How to find good documentation on the FreeCAD and Part python packages

Need help, or want to share a macro? Post here!
danielHjordan
Posts: 1
Joined: Wed Nov 13, 2019 12:29 pm

How to find good documentation on the FreeCAD and Part python packages

Postby danielHjordan » Wed Nov 13, 2019 12:55 pm

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 :)
Last edited by Kunda1 on Fri Nov 15, 2019 12:58 pm, edited 1 time in total.
Reason: fixed typo in thread title
User avatar
DeepSOIC
Posts: 7162
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: How to find good doccumentation on the FreeCAD and Part python packages

Postby DeepSOIC » Wed Nov 13, 2019 2:15 pm

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.
vocx
Posts: 1886
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to find good doccumentation on the FreeCAD and Part python packages

Postby vocx » Wed Nov 13, 2019 11:44 pm

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....
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.

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
Bayesian
Posts: 57
Joined: Thu Aug 08, 2019 1:49 pm

Re: How to find good doccumentation on the FreeCAD and Part python packages

Postby Bayesian » Thu Nov 14, 2019 9:11 am

The wiki has several examples on how to use the Part module to get you started.