[Solved] App::FeaturePython Selectable property

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
thyssentishman
Posts: 82
Joined: Mon May 16, 2022 10:35 am

Re: App::FeaturePython Selectable property

Post by thyssentishman »

onekk wrote: Tue Jun 28, 2022 9:13 am Not optimal, as it is not visible, in tree.

But if you assign it to a toggle button, it could work?
I have already done this in my modified version as a temporary solution, however the whole point of having it in the tree is to be able to customize the grid with the custom added properties (e.g. color, size etc.). Unhiding the object to change these doesn't seem optimal to me.

Do you understand why the grid doesn't show up in the 3D View anymore as soon as the object is added as Part::FeaturePython
instead of App::FeaturePython?
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: App::FeaturePython Selectable property

Post by onekk »

rvq wrote: Tue Jun 28, 2022 9:21 am Do you understand why the grid doesn't show up in the 3D View anymore as soon as the object is added as Part::FeaturePython
instead of App::FeaturePython?
No, let me see something.

Edit

No luck in modifying you code I think that probably something is not taken in account, with Part::FeaturePython, I usually supply a Shape to be shown and control it with the ViewProvider, but here there is no Shape, and adding one like a simple Part.Vertex (a Point at (0,0,0), to simply supply some shape is not working).

Probably asking @wmayer will be of some help.


Regards

Carlo D.

Edited to correct some mistyping
Last edited by onekk on Tue Jun 28, 2022 10:34 am, edited 2 times in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
thyssentishman
Posts: 82
Joined: Mon May 16, 2022 10:35 am

Re: App::FeaturePython Selectable property

Post by thyssentishman »

onekk wrote: Tue Jun 28, 2022 9:23 am Probably asking @wmayer will be of some help.
wmayer wrote:
Could you maybe help us here @wmayer?
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: App::FeaturePython Selectable property

Post by wmayer »

I think Selectable is a standard property only for Part::Feature but not for App::FeaturePython.
The Selectable property is added by ViewProviderGeometryObject. So, it's not only available for shapes but also for mesh, FEM meshes or point clouds.
obj = FreeCAD.ActiveDocument.addObject("App::FeaturePython","myObj")
obj.ViewObject.Selectable = False
You can use the next type in the class hierarchy:

Code: Select all

obj = FreeCAD.ActiveDocument.addObject("App::GeometryPython","myObj")
obj.ViewObject.Selectable = False
I believe it's because you are using Part:FeaturePython and I am using App:FeaturePython. What is the difference?
A Part:FeaturePython and its view provider has implemented a few more things compared to an App:FeaturePython.
Also when I change App for Part, the Selectable property shows up and the tree item as well, but the object won't show in the 3D view anymore.
At this point you still have to set a (proxy) view provider. If you don't want to assign a user-defined proxy view provider you have to set the Proxy property of the view provider to anything other than None. This is to trigger the internal initialization.

Code: Select all

obj.ViewObject.Proxy = 1
thyssentishman
Posts: 82
Joined: Mon May 16, 2022 10:35 am

Re: App::FeaturePython Selectable property

Post by thyssentishman »

wmayer wrote: Wed Jun 29, 2022 11:09 am You can use the next type in the class hierarchy
This worked perfectly thanks!
wmayer wrote: Wed Jun 29, 2022 11:09 am At this point you still have to set a (proxy) view provider. If you don't want to assign a user-defined proxy view provider you have to set the Proxy property of the view provider to anything other than None. This is to trigger the internal initialization.
Out of curiosity I tried this too using Part:FeaturePython but the object didn't show in the 3D view either. Even after a recompute. No errors on the Report View though.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: App::FeaturePython Selectable property

Post by wmayer »

Out of curiosity I tried this too using Part:FeaturePython
Have you assigned a shape to its Shape property?

Example:

Code: Select all

doc = App.newDocument()
obj = doc.addObject("Part::FeaturePython", "Part")
obj.ViewObject.Proxy=1
obj.Shape = Part.makeBox(1,1,1)
doc.recompute()
thyssentishman
Posts: 82
Joined: Mon May 16, 2022 10:35 am

Re: App::FeaturePython Selectable property

Post by thyssentishman »

wmayer wrote: Wed Jun 29, 2022 2:03 pm Have you assigned a shape to its Shape property?
Do Pivy objects count as Shapes?
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: App::FeaturePython Selectable property

Post by wmayer »

Do Pivy objects count as Shapes?
Not in this context. With pivy you would directly modify the scene graph of an object and bypass the mechanism that is implemented in FreeCAD to create the visual representation of a CAD shape.
thyssentishman
Posts: 82
Joined: Mon May 16, 2022 10:35 am

Re: App::FeaturePython Selectable property

Post by thyssentishman »

wmayer wrote: Wed Jun 29, 2022 2:11 pm Not in this context.
I see, thank you @wmayer. I guess I will stick to App::GeometryPython for this then, since I am only using Pivy right now.
Post Reply