This line:
print( isinstance(Gui.Selection.getSelection()[0],PartDesign.Body) )
I basically want to know if selected object is a body.
I will use it to select all visible bodies.
But this gives me:
Traceback (most recent call last):
File "<input>", line 1, in <module>
NameError: name 'PartDesign' is not defined
Is object instance of Body. 'PartDesign' is not defined.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Is object instance of Body. 'PartDesign' is not defined.
Something like:
Tested using:
OS: Linux Mint 19.3 (X-Cinnamon/cinnamon)
Word size of FreeCAD: 64-bit
Version: 0.20.26155 (Git)
Build type: Release
Branch: master
Hash: 0926a4148bcff11249fd4f56bc30256102ffe105
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
Code: Select all
# -*- coding: utf-8 -*-
import FreeCAD
import FreeCADGui
try:
s = FreeCADGui.Selection.getSelection()[0]
except:
print('Nothing selected')
for selection in FreeCADGui.Selection.getSelectionEx():
if str(type(selection.Object)) == "<class 'PartDesign.Body'>":
print(selection.Object.Label)
else:
print('You must only select PartDesign Bodies')
break
OS: Linux Mint 19.3 (X-Cinnamon/cinnamon)
Word size of FreeCAD: 64-bit
Version: 0.20.26155 (Git)
Build type: Release
Branch: master
Hash: 0926a4148bcff11249fd4f56bc30256102ffe105
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
Re: Is object instance of Body. 'PartDesign' is not defined.
Thank you for your guidelines.
I have used this in the end:
I have used this in the end:
Code: Select all
obj.isDerivedFrom("PartDesign::Body")