Hello,
I can reference a body created in the PartDesign workbench using this (just an example):
b = Gui.getDocument('Unnamed').ActiveView.getActiveObject('pdbody')
If I wanted to reference the YZ plane of the Origin of this body is there any preferred way other than the following:
yz = b.Origin.OriginFeatures[5]
Thanks very much.
Scripted references to body origin planes
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Scripted references to body origin planes
Apparently, in python - no. In C++, there is a plenty of methods for obtaining specific pieces:
https://github.com/FreeCAD/FreeCAD/blob ... igin.h#L75
So it's just a matter of adding py interface. I invite you to write a feature request in tracker, please
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: Scripted references to body origin planes
Accessing directly by index is probably a bad idea because if the implementation changes it could break your code. This might be a more robust approach:
Code: Select all
b = Gui.getDocument('Unnamed').ActiveView.getActiveObject('pdbody')
for feat in b.Origin.OriginFeatures:
if "XZ_Plane" in feat.Label:
xz = feat
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Scripted references to body origin planes
and this one is not language-proof. Although these particular labels are not translatable yet, by the looks of it.
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: Scripted references to body origin planes
- wandererfan
- Veteran
- Posts: 6324
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Scripted references to body origin planes
Yes, absolutely. Names are guaranteed unique and constant. Labels are neither.
Re: Scripted references to body origin planes
Just following up on this I have raised a request:DeepSOIC wrote: ↑Sat Oct 13, 2018 11:24 pm Apparently, in python - no. In C++, there is a plenty of methods for obtaining specific pieces:
https://github.com/FreeCAD/FreeCAD/blob ... igin.h#L75
So it's just a matter of adding py interface. I invite you to write a feature request in tracker, please
https://www.freecadweb.org/tracker/view.php?id=3770
Thanks very much.