I'm trying to lern python scripting inside freecad. I've been doing all examples from the wiki page Topological Data Scripting http://freecadweb.org/wiki/index.php?ti ... _scripting Amazing Stuff, it really makes fun because this is something my CAD at work ist not able to do at all.
Two things I was not able to do.
I would like to highligt one or more parts using python, just as I would klick these parts using the mouse. The whole part gets green.
I would like to access parts I've been created using the GUI and the mouse. I know the name (label) of them. I've found a script to find all names of the part objects of a freecad document but I'm not able te access them. I can not even calculate a volume of a simple box if the box was created using the gui and mouse.
thanks for any help, bernd
access gui created part objects using python
Forum rules
and Helpful information
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help
Also, be nice to others! Read the FreeCAD code of conduct!
Also, be nice to others! Read the FreeCAD code of conduct!
Re: access gui created part objects using python
Hello,
If you have a Object called "Box" in your document (no matter how it's created, in console or by scripting) you can access it by its name. Try it in the python console, the class browser will show your objects as part of the active document. That technique can be used to select the object too.
To get the Volume of a part the document object is not enough, you need to retrieve the geometrical shape. This shape has a property to access its volume (again, use the class browser to search what else is in that shape, pretty cool stuff)
If you have a Object called "Box" in your document (no matter how it's created, in console or by scripting) you can access it by its name. Try it in the python console, the class browser will show your objects as part of the active document. That technique can be used to select the object too.
Code: Select all
App.ActiveDocument.Box #Access document object named "Box"
Gui.Selection.addSelection(App.ActiveDocument.Box) #select document object named "Box"
Code: Select all
App.ActiveDocument.Box.Shape.Volume
Re: access gui created part objects using python
But if the name was changed using the GUI the python browser still shows the old names which where given from freecad. Same with following code. It shows the old names. I only can access the objects using the names given from freecad.ickby wrote:...If you have a Object called "Box" in your document (no matter how it's created, in console or by scripting) you can access it by its name. Try it in the python console, the class browser will show your objects as part of the active document. That technique can be used to select the object too. ...
Code: Select all
objs = FreeCAD.ActiveDocument.Objects
for obj in objs:
name = obj.Name # list the names of the objects
print name # Displays the name of the object
Code: Select all
AttributeError: 'App.Document' object has no attribute 'Rebar001a'
EDIT: I found about the difference of the name (internal name) and label.
Code: Select all
App.ActiveDocument.Box.Name
App.ActiveDocument.Box.Label