When learning how to write a python script for FreeCAD I am struggling to find out what attributes a class or method will accept.
Some times its easy for example when I type Part.circle() into the Python console FreeCAD gives me a handy little text pop up that says all of the possible attributes I can put into the brackets to make a circle.
Then there are others with no handy pop up text recently I found
myRev = FreeCAD.activeDocument().addObject("PartDesign::Revolution", "MyRev")
myRev.ReferenceAxis
Which gives me no indication of how I should define the axis. I tries as a FreeCad.Vector but no dice. I did get the friendly error:
TypeError: Property 'ReferenceAxis': type must be 'DocumentObject', 'NoneType' or ('DocumentObject',['String',]) not Base.Vector
Which helps a bit.
What I am looking for is some comprehensive straight forward documentation on these modules their methods and what attributes / attribute types I need to enter. Instead of mustering my way through errors, hoping some helpful text will pop up in the consol or hoping I can find some possibly questionable code on a forum somewhere where these modules are used.
Help much appreciated
How to find good documentation on the FreeCAD and Part python packages
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 1
- Joined: Wed Nov 13, 2019 12:29 pm
How to find good documentation on the FreeCAD and Part python packages
Last edited by Kunda1 on Fri Nov 15, 2019 12:58 pm, edited 1 time in total.
Reason: fixed typo in thread title
Reason: fixed typo in thread title
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: How to find good doccumentation on the FreeCAD and Part python packages
Hi!
All the attributes you are confused about are actually properties. They can be played with in GUI, in property editor. There, you will see "docstrings" as tooltips. You can also access them in console if you want, use .getDocumentationOfProperty("ReferenceAxis"). It can also be very useful to look up the type of property with getTypeIdOfProperty.
All the attributes you are confused about are actually properties. They can be played with in GUI, in property editor. There, you will see "docstrings" as tooltips. You can also access them in console if you want, use .getDocumentationOfProperty("ReferenceAxis"). It can also be very useful to look up the type of property with getTypeIdOfProperty.
Re: How to find good doccumentation on the FreeCAD and Part python packages
This doesn't exist. FreeCAD has a ton of modules made both in C++ and Python. Documentation is lacking because developers prefer to develop new features but don't like documenting them very well. Documenting is boring, developing is fun.danielHjordan wrote: ↑Wed Nov 13, 2019 12:55 pm ...
What I am looking for is some comprehensive straight forward documentation on these modules their methods and what attributes / attribute types I need to enter....
So, while the situation improves, you may have to refer to different pages on the wiki, particularly the Scripted objects page, and the rest of the pages in the Power users hub and Developer hub, and looking at the C++ code itself.
The documentation of the code is generated using Doxygen; this is hosted in https://www.freecadweb.org/api/. However, this documentation is a reduced version. In order to get the full documentation (5 GB), you need to get the source code and compile it yourself; see Source documentation. Then you will be able to look at the properties of different classes, such as PartDesign::Revolution, Part::Circle, and others.
In many cases, these objects implement functions of the OpenCASCADE Technology (OCCT) kernel, so you may have to search in this documentation as well; see https://www.opencascade.com/doc/occt-7. ... index.html
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: How to find good doccumentation on the FreeCAD and Part python packages
The wiki has several examples on how to use the Part module to get you started.