Extra python modules: Difference between revisions

From FreeCAD Documentation
(translate)
(Marked this version for translation)
Line 1: Line 1:
<translate>
<translate>
<!--T:1-->
This page lists several additional python modules or other pieces of software that can be downloaded freely from the internet, and add functionality to your FreeCAD installation.
This page lists several additional python modules or other pieces of software that can be downloaded freely from the internet, and add functionality to your FreeCAD installation.


== PySide (previously PyQt4) ==
== PySide (previously PyQt4) == <!--T:2-->
* homepage (PySide): [http://qt-project.org/wiki/PySide http://qt-project.org/wiki/PySide]
* homepage (PySide): [http://qt-project.org/wiki/PySide http://qt-project.org/wiki/PySide]
* license: LGPL
* license: LGPL
* optional, but needed by several modules: Draft, Arch, Ship, Plot, OpenSCAD, Spreadsheet
* optional, but needed by several modules: Draft, Arch, Ship, Plot, OpenSCAD, Spreadsheet


<!--T:3-->
PySide (previously PyQt) is required by several modules of FreeCAD to access FreeCAD's Qt interface. It is already bundled in the windows verison of FreeCAD, and is usually installed automatically by FreeCAD on Linux, when installing from official repositories. If those modules (Draft, Arch, etc) are enabled after FreeCAD is installed, it means PySide (previously PyQt) is already there, and you don't need to do anything more.
PySide (previously PyQt) is required by several modules of FreeCAD to access FreeCAD's Qt interface. It is already bundled in the windows verison of FreeCAD, and is usually installed automatically by FreeCAD on Linux, when installing from official repositories. If those modules (Draft, Arch, etc) are enabled after FreeCAD is installed, it means PySide (previously PyQt) is already there, and you don't need to do anything more.


<!--T:4-->
'''Note:''' FreeCAD progressively moved away from PyQt after version 0.13, in favour of [http://qt-project.org/wiki/PySide PySide], which does exactly the same job but has a license (LGPL) more compatible with FreeCAD.
'''Note:''' FreeCAD progressively moved away from PyQt after version 0.13, in favour of [http://qt-project.org/wiki/PySide PySide], which does exactly the same job but has a license (LGPL) more compatible with FreeCAD.


=== Installation ===
=== Installation === <!--T:5-->


==== Linux ====
==== Linux ==== <!--T:6-->
The simplest way to install PySide is through your distribution's package manager. On Debian/Ubuntu systems, the package name is generally ''python-PySide'', while on RPM-based systems it is named ''pyside''. The necessary dependencies (Qt and SIP) will be taken care of automatically.
The simplest way to install PySide is through your distribution's package manager. On Debian/Ubuntu systems, the package name is generally ''python-PySide'', while on RPM-based systems it is named ''pyside''. The necessary dependencies (Qt and SIP) will be taken care of automatically.


==== Windows ====
==== Windows ==== <!--T:7-->
The program can be downloaded from http://qt-project.org/wiki/Category:LanguageBindings::PySide::Downloads . You'll need to install the Qt and SIP libraries before installing PySide (to be documented).
The program can be downloaded from http://qt-project.org/wiki/Category:LanguageBindings::PySide::Downloads . You'll need to install the Qt and SIP libraries before installing PySide (to be documented).


==== MacOSX ====
==== MacOSX ==== <!--T:8-->
PyQt on Mac can be installed via homebrew or port. See [[CompileOnMac#Install_Dependencies]] for more information.
PyQt on Mac can be installed via homebrew or port. See [[CompileOnMac#Install_Dependencies]] for more information.


=== Usage ===
=== Usage === <!--T:9-->
Once it is installed, you can check that everything is working by typing in FreeCAD python console:
Once it is installed, you can check that everything is working by typing in FreeCAD python console:
</translate>
</translate>
Line 29: Line 32:
</pre>
</pre>
<translate>
<translate>
<!--T:10-->
To access the FreeCAD interface, type :
To access the FreeCAD interface, type :
</translate>
</translate>
Line 36: Line 40:
</pre>
</pre>
<translate>
<translate>
<!--T:11-->
Now you can start to explore the interface with the dir() command. You can add new elements, like a custom widget, with commands like :
Now you can start to explore the interface with the dir() command. You can add new elements, like a custom widget, with commands like :
</translate>
</translate>
Line 42: Line 47:
</pre>
</pre>
<translate>
<translate>
<!--T:12-->
Working with Unicode :
Working with Unicode :
</translate>
</translate>
Line 48: Line 54:
</pre>
</pre>
<translate>
<translate>
<!--T:13-->
Working with QFileDialog and OpenFileName :
Working with QFileDialog and OpenFileName :
</translate>
</translate>
Line 56: Line 63:
</pre>
</pre>
<translate>
<translate>
<!--T:14-->
Working with QFileDialog and SaveFileName :
Working with QFileDialog and SaveFileName :
</translate>
</translate>
Line 64: Line 72:
</pre>
</pre>
<translate>
<translate>
===Example of transition from PyQt4 and PySide===
===Example of transition from PyQt4 and PySide=== <!--T:15-->


<!--T:16-->
PS: these examples of errors were found in the transition PyQt4 to PySide and these corrections were made, other solutions are certainly available with the examples above
PS: these examples of errors were found in the transition PyQt4 to PySide and these corrections were made, other solutions are certainly available with the examples above
</translate>
</translate>
Line 87: Line 96:
</pre>
</pre>
<translate>
<translate>
<!--T:17-->
To access the FreeCAD interface, type :
To access the FreeCAD interface, type :
You can add new elements, like a custom widget, with commands like :
You can add new elements, like a custom widget, with commands like :
Line 103: Line 113:
</pre>
</pre>
<translate>
<translate>
<!--T:18-->
Working with Unicode :
Working with Unicode :
</translate>
</translate>
Line 112: Line 123:
</pre>
</pre>
<translate>
<translate>
<!--T:19-->
Working with QFileDialog and OpenFileName :
Working with QFileDialog and OpenFileName :
</translate>
</translate>
Line 122: Line 134:
</pre>
</pre>
<translate>
<translate>
<!--T:20-->
Working with QFileDialog and SaveFileName :
Working with QFileDialog and SaveFileName :
</translate>
</translate>
Line 132: Line 145:
</pre>
</pre>
<translate>
<translate>
<!--T:21-->
The MessageBox:
The MessageBox:
</translate>
</translate>
Line 145: Line 159:
</pre>
</pre>
<translate>
<translate>
<!--T:22-->
Working with setProperty (PyQt4) and setValue (PySide)
Working with setProperty (PyQt4) and setValue (PySide)
</translate>
</translate>
Line 151: Line 166:
</pre>
</pre>
<translate>
<translate>
<!--T:23-->
replace to :
replace to :
</translate>
</translate>
Line 157: Line 173:
</pre>
</pre>
<translate>
<translate>
<!--T:24-->
Working with setToolTip
Working with setToolTip
</translate>
</translate>
Line 163: Line 180:
</pre>
</pre>
<translate>
<translate>
<!--T:25-->
replace to :
replace to :
</translate>
</translate>
Line 169: Line 187:
</pre>
</pre>
<translate>
<translate>
<!--T:26-->
or :
or :
</translate>
</translate>
Line 175: Line 194:
</pre>
</pre>
<translate>
<translate>
=== Additional documentation ===
=== Additional documentation === <!--T:27-->
Some pyQt4 tutorials (including how to build interfaces with Qt Designer to use with python):
Some pyQt4 tutorials (including how to build interfaces with Qt Designer to use with python):
* http://pyqt.sourceforge.net/Docs/PyQt4/classes.html - the PyQt4 API Reference on sourceforge
* http://pyqt.sourceforge.net/Docs/PyQt4/classes.html - the PyQt4 API Reference on sourceforge
Line 181: Line 200:
* http://www.zetcode.com/tutorials/pyqt4/ - very complete in-depth tutorial
* http://www.zetcode.com/tutorials/pyqt4/ - very complete in-depth tutorial


== Pivy ==
== Pivy == <!--T:28-->
* homepage: [https://bitbucket.org/Coin3D/coin/wiki/Home https://bitbucket.org/Coin3D/coin/wiki/Home]
* homepage: [https://bitbucket.org/Coin3D/coin/wiki/Home https://bitbucket.org/Coin3D/coin/wiki/Home]
* license: BSD
* license: BSD
* optional, but needed by several modules of FreeCAD: Draft, Arch
* optional, but needed by several modules of FreeCAD: Draft, Arch


<!--T:29-->
Pivy is a needed by several modules to access the 3D view of FreeCAD. On windows, Pivy is already bundled inside the FreeCAD installer, and on Linux it is usually automatically installed when you install FreeCAD from an official repository. On MacOSX, unfortunately, you will need to compile pivy yourself.
Pivy is a needed by several modules to access the 3D view of FreeCAD. On windows, Pivy is already bundled inside the FreeCAD installer, and on Linux it is usually automatically installed when you install FreeCAD from an official repository. On MacOSX, unfortunately, you will need to compile pivy yourself.


=== Installation ===
=== Installation === <!--T:30-->


==== Prerequisites ====
==== Prerequisites ==== <!--T:31-->
I believe before compiling Pivy you will want to have Coin and SoQt installed.
I believe before compiling Pivy you will want to have Coin and SoQt installed.


<!--T:32-->
I found for building on Mac it was sufficient to install the [http://www.coin3d.org/lib/plonesoftwarecenter_view Coin3 binary package]. Attempting to install coin from MacPorts was problematic: tried to add a lot of X Windows packages and ultimately crashed with a script error.
I found for building on Mac it was sufficient to install the [http://www.coin3d.org/lib/plonesoftwarecenter_view Coin3 binary package]. Attempting to install coin from MacPorts was problematic: tried to add a lot of X Windows packages and ultimately crashed with a script error.


<!--T:33-->
For Fedora I found an RPM with Coin3.
For Fedora I found an RPM with Coin3.


<!--T:34-->
SoQt compiled from [http://www.coin3d.org/lib/soqt/releases/1.5.0 source] fine on Mac and Linux.
SoQt compiled from [http://www.coin3d.org/lib/soqt/releases/1.5.0 source] fine on Mac and Linux.


==== Debian & Ubuntu ====
==== Debian & Ubuntu ==== <!--T:35-->
Starting with Debian Squeeze and Ubuntu Lucid, pivy will be available directly from the official repositories, saving us a lot of hassle. In the meantime, you can either download one of the packages we made (for debian and ubuntu karmic) availables on the [[Download]] pages, or compile it yourself.
Starting with Debian Squeeze and Ubuntu Lucid, pivy will be available directly from the official repositories, saving us a lot of hassle. In the meantime, you can either download one of the packages we made (for debian and ubuntu karmic) availables on the [[Download]] pages, or compile it yourself.


<!--T:36-->
The best way to compile pivy easily is to grab the debian source package for pivy and make a package with debuild. It is the same source code from the official pivy site, but the debian people made several bug-fixing additions. It also compiles fine on ubuntu karmic: http://packages.debian.org/squeeze/python-pivy (download the .orig.gz and the .diff.gz file, then unzip both, then apply the .diff to the source: go to the unzipped pivy source folder, and apply the .diff patch:
The best way to compile pivy easily is to grab the debian source package for pivy and make a package with debuild. It is the same source code from the official pivy site, but the debian people made several bug-fixing additions. It also compiles fine on ubuntu karmic: http://packages.debian.org/squeeze/python-pivy (download the .orig.gz and the .diff.gz file, then unzip both, then apply the .diff to the source: go to the unzipped pivy source folder, and apply the .diff patch:
</translate>
</translate>
Line 208: Line 232:
</pre>
</pre>
<translate>
<translate>
<!--T:37-->
then
then
</translate>
</translate>
Line 214: Line 239:
</pre>
</pre>
<translate>
<translate>
<!--T:38-->
to have pivy properly built into an official installable package. Then, just install the package with gdebi.
to have pivy properly built into an official installable package. Then, just install the package with gdebi.


==== Other linux distributions ====
==== Other linux distributions ==== <!--T:39-->
First get the latest sources from the [http://pivy.coin3d.org/mercurial/ project's repository]:
First get the latest sources from the [http://pivy.coin3d.org/mercurial/ project's repository]:
</translate>
</translate>
Line 223: Line 249:
</pre>
</pre>
<translate>
<translate>
<!--T:40-->
As of March 2012, the latest version is Pivy-0.5.
As of March 2012, the latest version is Pivy-0.5.


<!--T:41-->
Then you need a tool called SWIG to generate the C++ code for the Python bindings. Pivy-0.5 reports that it has only been tested with SWIG 1.3.31, 1.3.33, 1.3.35, and 1.3.40. So you can download a source tarball for one of these old versions from [http://www.swig.org http://www.swig.org]. Then unpack it and from a command line do (as root):
Then you need a tool called SWIG to generate the C++ code for the Python bindings. Pivy-0.5 reports that it has only been tested with SWIG 1.3.31, 1.3.33, 1.3.35, and 1.3.40. So you can download a source tarball for one of these old versions from [http://www.swig.org http://www.swig.org]. Then unpack it and from a command line do (as root):
</translate>
</translate>
Line 233: Line 261:
</pre>
</pre>
<translate>
<translate>
<!--T:42-->
It takes just a few seconds to build.
It takes just a few seconds to build.


<!--T:43-->
Alternatively, you can try building with a more recent SWIG. As of March 2012, a typical repository version is 2.0.4. Pivy has a minor compile problem with SWIG 2.0.4 on Mac OS (see below) but seems to build fine on Fedora Core 15.
Alternatively, you can try building with a more recent SWIG. As of March 2012, a typical repository version is 2.0.4. Pivy has a minor compile problem with SWIG 2.0.4 on Mac OS (see below) but seems to build fine on Fedora Core 15.


<!--T:44-->
After that go to the pivy sources and call
After that go to the pivy sources and call
</translate>
</translate>
Line 243: Line 274:
</pre>
</pre>
<translate>
<translate>
<!--T:45-->
which creates the source files. Note that build can produce thousands of warnings, but hopefully there will be no errors.
which creates the source files. Note that build can produce thousands of warnings, but hopefully there will be no errors.


<!--T:46-->
This is probably obsolete, but you may run into a compiler error where a 'const char*' cannot be converted in a 'char*'. To fix that you just need to write a 'const' before in the appropriate lines. There are six lines to fix.
This is probably obsolete, but you may run into a compiler error where a 'const char*' cannot be converted in a 'char*'. To fix that you just need to write a 'const' before in the appropriate lines. There are six lines to fix.


<!--T:47-->
After that, install by issuing (as root):
After that, install by issuing (as root):
</translate>
</translate>
Line 253: Line 287:
</pre>
</pre>
<translate>
<translate>
<!--T:48-->
That's it, pivy is installed.
That's it, pivy is installed.


==== Mac OS ====
==== Mac OS ==== <!--T:49-->
These instructions may not be complete. Something close to this worked for OS 10.7 as of March 2012. I use MacPorts for repositories, but other options should also work.
These instructions may not be complete. Something close to this worked for OS 10.7 as of March 2012. I use MacPorts for repositories, but other options should also work.


<!--T:50-->
As for linux, get the latest source:
As for linux, get the latest source:
</translate>
</translate>
Line 264: Line 300:
</pre>
</pre>
<translate>
<translate>
<!--T:51-->
If you don't have hg, you can get it from MacPorts:
If you don't have hg, you can get it from MacPorts:
</translate>
</translate>
Line 270: Line 307:
</pre>
</pre>
<translate>
<translate>
<!--T:52-->
Then, as above you need SWIG. It should be a matter of:
Then, as above you need SWIG. It should be a matter of:
</translate>
</translate>
Line 276: Line 314:
</pre>
</pre>
<translate>
<translate>
<!--T:53-->
I found I needed also:
I found I needed also:
</translate>
</translate>
Line 282: Line 321:
</pre>
</pre>
<translate>
<translate>
<!--T:54-->
As of March 2012, MacPorts SWIG is version 2.0.4. As noted above for linux, you might be better off downloading an older version. SWIG 2.0.4 seems to have a bug that stops Pivy building. See first message in this digest: https://sourceforge.net/mailarchive/message.php?msg_id=28114815
As of March 2012, MacPorts SWIG is version 2.0.4. As noted above for linux, you might be better off downloading an older version. SWIG 2.0.4 seems to have a bug that stops Pivy building. See first message in this digest: https://sourceforge.net/mailarchive/message.php?msg_id=28114815


<!--T:55-->
This can be corrected by editing the 2 source locations to add dereferences: *arg4, *arg5 in place of arg4, arg5. Now Pivy should build:
This can be corrected by editing the 2 source locations to add dereferences: *arg4, *arg5 in place of arg4, arg5. Now Pivy should build:
</translate>
</translate>
Line 291: Line 332:
</pre>
</pre>
<translate>
<translate>
==== Windows ====
==== Windows ==== <!--T:56-->
Assuming you are using Visual Studio 2005 or later you should open a command prompt with 'Visual Studio 2005 Command prompt' from the Tools menu.
Assuming you are using Visual Studio 2005 or later you should open a command prompt with 'Visual Studio 2005 Command prompt' from the Tools menu.
If the Python interpreter is not yet in the system path do
If the Python interpreter is not yet in the system path do
Line 299: Line 340:
</pre>
</pre>
<translate>
<translate>
<!--T:57-->
To get pivy working you should get the latest sources from the project's repository:
To get pivy working you should get the latest sources from the project's repository:
</translate>
</translate>
Line 305: Line 347:
</pre>
</pre>
<translate>
<translate>
<!--T:58-->
Then you need a tool called SWIG to generate the C++ code for the Python bindings. It is recommended to use version 1.3.25 of SWIG, not the latest version, because at the moment pivy will only function correctly with 1.3.25. Download the binaries for 1.3.25 from [http://www.swig.org http://www.swig.org]. Then unpack it and from the command line add it to the system path
Then you need a tool called SWIG to generate the C++ code for the Python bindings. It is recommended to use version 1.3.25 of SWIG, not the latest version, because at the moment pivy will only function correctly with 1.3.25. Download the binaries for 1.3.25 from [http://www.swig.org http://www.swig.org]. Then unpack it and from the command line add it to the system path
</translate>
</translate>
Line 311: Line 354:
</pre>
</pre>
<translate>
<translate>
<!--T:59-->
and set COINDIR to the appropriate path
and set COINDIR to the appropriate path
</translate>
</translate>
Line 317: Line 361:
</pre>
</pre>
<translate>
<translate>
<!--T:60-->
On Windows the pivy config file expects SoWin instead of SoQt as default. I didn't find an obvious way to build with SoQt, so I modified the file setup.py directly.
On Windows the pivy config file expects SoWin instead of SoQt as default. I didn't find an obvious way to build with SoQt, so I modified the file setup.py directly.
In line 200 just remove the part 'sowin' : ('gui._sowin', 'sowin-config', 'pivy.gui.') (do not remove the closing parenthesis).
In line 200 just remove the part 'sowin' : ('gui._sowin', 'sowin-config', 'pivy.gui.') (do not remove the closing parenthesis).


<!--T:61-->
After that go to the pivy sources and call
After that go to the pivy sources and call
</translate>
</translate>
Line 326: Line 372:
</pre>
</pre>
<translate>
<translate>
<!--T:62-->
which creates the source files. You may run into a compiler error several header files couldn't be found. In this case adjust the INCLUDE variable
which creates the source files. You may run into a compiler error several header files couldn't be found. In this case adjust the INCLUDE variable
</translate>
</translate>
Line 332: Line 379:
</pre>
</pre>
<translate>
<translate>
<!--T:63-->
and if the SoQt headers are not in the same place as the Coin headers also
and if the SoQt headers are not in the same place as the Coin headers also
</translate>
</translate>
Line 338: Line 386:
</pre>
</pre>
<translate>
<translate>
<!--T:64-->
and finally the Qt headers
and finally the Qt headers
</translate>
</translate>
Line 344: Line 393:
</pre>
</pre>
<translate>
<translate>
<!--T:65-->
If you are using the Express Edition of Visual Studio you may get a python keyerror exception.
If you are using the Express Edition of Visual Studio you may get a python keyerror exception.
In this case you have to modify a few things in msvccompiler.py located in your python installation.
In this case you have to modify a few things in msvccompiler.py located in your python installation.


<!--T:66-->
Go to line 122 and replace the line
Go to line 122 and replace the line
</translate>
</translate>
Line 353: Line 404:
</pre>
</pre>
<translate>
<translate>
<!--T:67-->
with
with
</translate>
</translate>
Line 359: Line 411:
</pre>
</pre>
<translate>
<translate>
<!--T:68-->
Then retry again.
Then retry again.
If you get a second error like
If you get a second error like
Line 366: Line 419:
</pre>
</pre>
<translate>
<translate>
<!--T:69-->
you must also replace line 128
you must also replace line 128
</translate>
</translate>
Line 372: Line 426:
</pre>
</pre>
<translate>
<translate>
<!--T:70-->
with
with
</translate>
</translate>
Line 378: Line 433:
</pre>
</pre>
<translate>
<translate>
<!--T:71-->
Retry once again. If you get again an error like
Retry once again. If you get again an error like
</translate>
</translate>
Line 384: Line 440:
</pre>
</pre>
<translate>
<translate>
<!--T:72-->
then you should check the environment variables DISTUTILS_USE_SDK and MSSDK with
then you should check the environment variables DISTUTILS_USE_SDK and MSSDK with
</translate>
</translate>
Line 391: Line 448:
</pre>
</pre>
<translate>
<translate>
<!--T:73-->
If not yet set then just set it e.g. to 1
If not yet set then just set it e.g. to 1
</translate>
</translate>
Line 398: Line 456:
</pre>
</pre>
<translate>
<translate>
<!--T:74-->
Now, you may run into a compiler error where a 'const char*' cannot be converted in a 'char*'. To fix that you just need to write a 'const' before in the appropriate lines. There are six lines to fix.
Now, you may run into a compiler error where a 'const char*' cannot be converted in a 'char*'. To fix that you just need to write a 'const' before in the appropriate lines. There are six lines to fix.
After that copy the generated pivy directory to a place where the python interpreter in FreeCAD can find it.
After that copy the generated pivy directory to a place where the python interpreter in FreeCAD can find it.


=== Usage ===
=== Usage === <!--T:75-->
To check if Pivy is correctly installed:
To check if Pivy is correctly installed:
</translate>
</translate>
Line 408: Line 467:
</pre>
</pre>
<translate>
<translate>
<!--T:76-->
To have Pivy access the FreeCAD scenegraph do the following:
To have Pivy access the FreeCAD scenegraph do the following:
</translate>
</translate>
Line 418: Line 478:
</pre>
</pre>
<translate>
<translate>
<!--T:77-->
You can now explore the FCSceneGraph with the dir() command.
You can now explore the FCSceneGraph with the dir() command.


=== Additonal Documentation ===
=== Additonal Documentation === <!--T:78-->
Unfortunately documentation about pivy is still almost inexistant on the net. But you might find Coin documentation useful, since pivy simply translate Coin functions, nodes and methods in python, everything keeps the same name and properties, keeping in mind the difference of syntax between C and python:
Unfortunately documentation about pivy is still almost inexistant on the net. But you might find Coin documentation useful, since pivy simply translate Coin functions, nodes and methods in python, everything keeps the same name and properties, keeping in mind the difference of syntax between C and python:


<!--T:79-->
* https://bitbucket.org/Coin3D/coin/wiki/Documentation - Coin3D API Reference
* https://bitbucket.org/Coin3D/coin/wiki/Documentation - Coin3D API Reference
* http://www-evasion.imag.fr/~Francois.Faure/doc/inventorMentor/sgi_html/index.html - The Inventor Mentor - The "bible" of Inventor scene description language.
* http://www-evasion.imag.fr/~Francois.Faure/doc/inventorMentor/sgi_html/index.html - The Inventor Mentor - The "bible" of Inventor scene description language.


<!--T:80-->
You can also look at the Draft.py file in the FreeCAD Mod/Draft folder, since it makes big use of pivy.
You can also look at the Draft.py file in the FreeCAD Mod/Draft folder, since it makes big use of pivy.


== pyCollada ==
== pyCollada == <!--T:81-->
* homepage: http://pycollada.github.com
* homepage: http://pycollada.github.com
* license: BSD
* license: BSD
* optional, needed to enable import and export of Collada (.DAE) files
* optional, needed to enable import and export of Collada (.DAE) files


<!--T:82-->
pyCollada is a python library that allow programs to read and write [http://en.wikipedia.org/wiki/COLLADA Collada (*.DAE)] files. When pyCollada is installed on your system, FreeCAD will be able to handle importing and exporting in the Collada file format.
pyCollada is a python library that allow programs to read and write [http://en.wikipedia.org/wiki/COLLADA Collada (*.DAE)] files. When pyCollada is installed on your system, FreeCAD will be able to handle importing and exporting in the Collada file format.


=== Installation ===
=== Installation === <!--T:83-->
Pycollada is usually not yet available in linux distributions repositories, but since it is made only of python files, it doesn't require compilation, and is easy to install. You have 2 ways, or directly from the official pycollada git repository, or with the easy_install tool.
Pycollada is usually not yet available in linux distributions repositories, but since it is made only of python files, it doesn't require compilation, and is easy to install. You have 2 ways, or directly from the official pycollada git repository, or with the easy_install tool.


==== Linux ====
==== Linux ==== <!--T:84-->
In either case, you'll need the following packages already installed on your system:
In either case, you'll need the following packages already installed on your system:
</translate>
</translate>
Line 447: Line 511:
</pre>
</pre>
<translate>
<translate>
===== From the git repository =====
===== From the git repository ===== <!--T:85-->
</translate>
</translate>
<pre>
<pre>
Line 455: Line 519:
</pre>
</pre>
<translate>
<translate>
===== With easy_install =====
===== With easy_install ===== <!--T:86-->
Assuming you have a complete python installation already, the easy_install utility should be present already:
Assuming you have a complete python installation already, the easy_install utility should be present already:
</translate>
</translate>
Line 462: Line 526:
</pre>
</pre>
<translate>
<translate>
<!--T:87-->
You can check if pycollada was correctly installed by issuing in a python console:
You can check if pycollada was correctly installed by issuing in a python console:
</translate>
</translate>
Line 468: Line 533:
</pre>
</pre>
<translate>
<translate>
<!--T:88-->
If it returns nothing (no error message), then all is OK
If it returns nothing (no error message), then all is OK


==== Windows ====
==== Windows ==== <!--T:89-->


<!--T:90-->
# Install Python. While FreeCAD and some other programs come with a bundled version of Python, having a fixed install will help with the next steps. You can get Python here: https://www.python.org/downloads/ . Of course you should pick the right version, in this case that would be 2.6.X, as FreeCAD currently uses 2.6.2 (Personally I went with 2.6.2, and by the way, you can check the version yourself by starting the Python.exe in the bin folder of FreeCAD). You'll also have to add the path of the installation directory into the path variable so you can access Python from the cmd. Now we can install the missing things, in total there are 3 things we need to install: numpy, setuptools, pycollada
# Install Python. While FreeCAD and some other programs come with a bundled version of Python, having a fixed install will help with the next steps. You can get Python here: https://www.python.org/downloads/ . Of course you should pick the right version, in this case that would be 2.6.X, as FreeCAD currently uses 2.6.2 (Personally I went with 2.6.2, and by the way, you can check the version yourself by starting the Python.exe in the bin folder of FreeCAD). You'll also have to add the path of the installation directory into the path variable so you can access Python from the cmd. Now we can install the missing things, in total there are 3 things we need to install: numpy, setuptools, pycollada
# Fetch numpy here: http://sourceforge.net/projects/numpy/files/NumPy/ . Pick a version which fits to the version used by FreeCAD, there are multiple installers for different Python versions in every numpy version folder, the installer will put numpy into the folder of your Python installation, where FreeCAD can access it as well
# Fetch numpy here: http://sourceforge.net/projects/numpy/files/NumPy/ . Pick a version which fits to the version used by FreeCAD, there are multiple installers for different Python versions in every numpy version folder, the installer will put numpy into the folder of your Python installation, where FreeCAD can access it as well
Line 485: Line 552:
# Install the setuptools by tipping "Python setup.py install" into the cmd
# Install the setuptools by tipping "Python setup.py install" into the cmd


<!--T:91-->
* Another reference on how to use easy_install: http://jishus.org/?p=452
* Another reference on how to use easy_install: http://jishus.org/?p=452


==== Mac OS ====
==== Mac OS ==== <!--T:92-->


<!--T:93-->
If you are using the Homebrew build of FreeCAD you can install pycollada into your system Python using pip.
If you are using the Homebrew build of FreeCAD you can install pycollada into your system Python using pip.


<!--T:94-->
If you need to install pip:
If you need to install pip:
</translate>
</translate>
Line 497: Line 567:
</pre>
</pre>
<translate>
<translate>
<!--T:95-->
Install pycollada:
Install pycollada:
</translate>
</translate>
Line 503: Line 574:
</pre>
</pre>
<translate>
<translate>
<!--T:96-->
If you are using a binary version of FreeCAD, you can tell pip to install pycollada into the site-packages inside FreeCAD.app:
If you are using a binary version of FreeCAD, you can tell pip to install pycollada into the site-packages inside FreeCAD.app:
</translate>
</translate>
Line 509: Line 581:
</pre>
</pre>
<translate>
<translate>
== IfcOpenShell ==
== IfcOpenShell == <!--T:97-->


<!--T:98-->
* homepage: http://www.ifcopenshell.org
* homepage: http://www.ifcopenshell.org
* license: LGPL
* license: LGPL
* optional, needed to extend import abilities of IFC files
* optional, needed to extend import abilities of IFC files


<!--T:99-->
IFCOpenShell is a library currently in development, that allows to import (and soon export) [http://en.wikipedia.org/wiki/Industry_Foundation_Classes Industry foundation Classes (*.IFC)] files. IFC is an extension to the STEP format, and is becoming the standard in [http://en.wikipedia.org/wiki/Building_information_modeling BIM] workflows. When ifcopenshell is correctly installed on your system, the FreeCAD [[Arch Module]] will detect it and use it to import IFC files, instead of its built-in rudimentary importer. Since ifcopenshell is based on OpenCasCade, like FreeCAD, the quality of the import is very high, producing high-quality solid geometry.
IFCOpenShell is a library currently in development, that allows to import (and soon export) [http://en.wikipedia.org/wiki/Industry_Foundation_Classes Industry foundation Classes (*.IFC)] files. IFC is an extension to the STEP format, and is becoming the standard in [http://en.wikipedia.org/wiki/Building_information_modeling BIM] workflows. When ifcopenshell is correctly installed on your system, the FreeCAD [[Arch Module]] will detect it and use it to import IFC files, instead of its built-in rudimentary importer. Since ifcopenshell is based on OpenCasCade, like FreeCAD, the quality of the import is very high, producing high-quality solid geometry.


=== Installation ===
=== Installation === <!--T:100-->
Since ifcopenshell is pretty new, you'll likely need to compile it yourself.
Since ifcopenshell is pretty new, you'll likely need to compile it yourself.


==== Linux ====
==== Linux ==== <!--T:101-->
You will need a couple of development packages installed on your system in order to compile ifcopenshell:
You will need a couple of development packages installed on your system in order to compile ifcopenshell:
</translate>
</translate>
Line 529: Line 603:
</pre>
</pre>
<translate>
<translate>
<!--T:102-->
but since FreeCAD requires all of them too, if you can compile FreeCAD, you won't need any extra dependency to compile IfcOpenShell.
but since FreeCAD requires all of them too, if you can compile FreeCAD, you won't need any extra dependency to compile IfcOpenShell.


<!--T:103-->
Grab the latest source code from here:
Grab the latest source code from here:
</translate>
</translate>
Line 537: Line 613:
</pre>
</pre>
<translate>
<translate>
<!--T:104-->
The build process is very easy:
The build process is very easy:
</translate>
</translate>
Line 545: Line 622:
</pre>
</pre>
<translate>
<translate>
<!--T:105-->
or, if you are using oce instead of opencascade:
or, if you are using oce instead of opencascade:
</translate>
</translate>
Line 551: Line 629:
</pre>
</pre>
<translate>
<translate>
<!--T:106-->
Since ifcopenshell is made primarily for Blender, it uses python3 by default. To use it inside FreeCAD, you need to compile it against the same version of python that is used by FreeCAD. So you might need to force the python version with additional cmake parameters (adjust the python version to yours):
Since ifcopenshell is made primarily for Blender, it uses python3 by default. To use it inside FreeCAD, you need to compile it against the same version of python that is used by FreeCAD. So you might need to force the python version with additional cmake parameters (adjust the python version to yours):
</translate>
</translate>
Line 557: Line 636:
</pre>
</pre>
<translate>
<translate>
<!--T:107-->
Then:
Then:
</translate>
</translate>
Line 564: Line 644:
</pre>
</pre>
<translate>
<translate>
<!--T:108-->
You can check that ifcopenshell was correctly installed by issuing in a python console:
You can check that ifcopenshell was correctly installed by issuing in a python console:
</translate>
</translate>
Line 570: Line 651:
</pre>
</pre>
<translate>
<translate>
<!--T:109-->
If it returns nothing (no error message), then all is OK
If it returns nothing (no error message), then all is OK


==== Windows ====
==== Windows ==== <!--T:110-->


<!--T:111-->
''Copied from the IfcOpenShell README file''
''Copied from the IfcOpenShell README file''


<!--T:112-->
Users are advised to use the Visual Studio .sln file in the win/ folder. For Windows users a prebuilt Open CASCADE version is available from the http://opencascade.org website. Download and install this version and provide the paths to the Open CASCADE header and library files to MS Visual Studio C++.
Users are advised to use the Visual Studio .sln file in the win/ folder. For Windows users a prebuilt Open CASCADE version is available from the http://opencascade.org website. Download and install this version and provide the paths to the Open CASCADE header and library files to MS Visual Studio C++.


<!--T:113-->
For building the IfcPython wrapper, SWIG needs to be installed. Please download the latest swigwin version from http://www.swig.org/download.html . After extracting the .zip file, please add the extracted folder to the PATH environment variable. Python needs to be installed, please provide the include and library paths to Visual Studio.
For building the IfcPython wrapper, SWIG needs to be installed. Please download the latest swigwin version from http://www.swig.org/download.html . After extracting the .zip file, please add the extracted folder to the PATH environment variable. Python needs to be installed, please provide the include and library paths to Visual Studio.


== Teigha Converter ==
== Teigha Converter == <!--T:114-->


<!--T:115-->
* homepage: http://www.opendesign.com/guestfiles/TeighaFileConverter
* homepage: http://www.opendesign.com/guestfiles/TeighaFileConverter
* license: freeware
* license: freeware
* optional, used to enable import and export of DWG files
* optional, used to enable import and export of DWG files


<!--T:116-->
The Teigha Converter is a small freely available utility that allows to convert between several versions of DWG and DXF files. FreeCAD can use it to offer DWG import and export, by converting DWG files to the DXF format under the hood,then using its standard DXF importer to import the file contents. The restrictions of the [[Draft_DXF|DXF importer]] apply.
The Teigha Converter is a small freely available utility that allows to convert between several versions of DWG and DXF files. FreeCAD can use it to offer DWG import and export, by converting DWG files to the DXF format under the hood,then using its standard DXF importer to import the file contents. The restrictions of the [[Draft_DXF|DXF importer]] apply.


=== Installation ===
=== Installation === <!--T:117-->
On all platforms, only by installing the appropriate package from http://www.opendesign.com/guestfiles/TeighaFileConverter . After installation, if the utility is not found automatically by FreeCAD, you might need to set the path to the converter executable manually, in the menu Edit -> Preferences -> Draft -> Import/Export options.
On all platforms, only by installing the appropriate package from http://www.opendesign.com/guestfiles/TeighaFileConverter . After installation, if the utility is not found automatically by FreeCAD, you might need to set the path to the converter executable manually, in the menu Edit -> Preferences -> Draft -> Import/Export options.


<!--T:118-->
{{docnav|Localisation|Source documentation}}
{{docnav|Localisation|Source documentation}}


<!--T:119-->
[[Category:Developer Documentation]]
[[Category:Developer Documentation]]



Revision as of 22:00, 8 November 2014

This page lists several additional python modules or other pieces of software that can be downloaded freely from the internet, and add functionality to your FreeCAD installation.

PySide (previously PyQt4)

PySide (previously PyQt) is required by several modules of FreeCAD to access FreeCAD's Qt interface. It is already bundled in the windows verison of FreeCAD, and is usually installed automatically by FreeCAD on Linux, when installing from official repositories. If those modules (Draft, Arch, etc) are enabled after FreeCAD is installed, it means PySide (previously PyQt) is already there, and you don't need to do anything more.

Note: FreeCAD progressively moved away from PyQt after version 0.13, in favour of PySide, which does exactly the same job but has a license (LGPL) more compatible with FreeCAD.

Installation

Linux

The simplest way to install PySide is through your distribution's package manager. On Debian/Ubuntu systems, the package name is generally python-PySide, while on RPM-based systems it is named pyside. The necessary dependencies (Qt and SIP) will be taken care of automatically.

Windows

The program can be downloaded from http://qt-project.org/wiki/Category:LanguageBindings::PySide::Downloads . You'll need to install the Qt and SIP libraries before installing PySide (to be documented).

MacOSX

PyQt on Mac can be installed via homebrew or port. See CompileOnMac#Install_Dependencies for more information.

Usage

Once it is installed, you can check that everything is working by typing in FreeCAD python console:

import PySide

To access the FreeCAD interface, type :

from PySide import QtCore,QtGui
FreeCADWindow = FreeCADGui.getMainWindow()

Now you can start to explore the interface with the dir() command. You can add new elements, like a custom widget, with commands like :

FreeCADWindow.addDockWidget(QtCore.Qt.RghtDockWidgetArea,my_custom_widget)

Working with Unicode :

text = text.encode('utf-8')

Working with QFileDialog and OpenFileName :

path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Read a txt file", path, "*.txt")

Working with QFileDialog and SaveFileName :

path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Save a file txt", path, "*.txt")

Example of transition from PyQt4 and PySide

PS: these examples of errors were found in the transition PyQt4 to PySide and these corrections were made, other solutions are certainly available with the examples above

try:
    import PyQt4                                        # PyQt4
    from PyQt4 import QtGui ,QtCore                     # PyQt4
    from PyQt4.QtGui import QComboBox                   # PyQt4
    from PyQt4.QtGui import QMessageBox                 # PyQt4
    from PyQt4.QtGui import QTableWidget, QApplication  # PyQt4
    from PyQt4.QtGui import *                           # PyQt4
    from PyQt4.QtCore import *                          # PyQt4
except Exception:
    import PySide                                       # PySide
    from PySide import QtGui ,QtCore                    # PySide
    from PySide.QtGui import QComboBox                  # PySide
    from PySide.QtGui import QMessageBox                # PySide
    from PySide.QtGui import QTableWidget, QApplication # PySide
    from PySide.QtGui import *                          # PySide
    from PySide.QtCore import *                         # PySide

To access the FreeCAD interface, type : You can add new elements, like a custom widget, with commands like :

myNewFreeCADWidget = QtGui.QDockWidget()          # create a new dockwidget
myNewFreeCADWidget.ui = Ui_MainWindow()           # myWidget_Ui()             # load the Ui script
myNewFreeCADWidget.ui.setupUi(myNewFreeCADWidget) # setup the ui
try:
    app = QtGui.qApp                              # PyQt4 # the active qt window, = the freecad window since we are inside it
    FCmw = app.activeWindow()                     # PyQt4 # the active qt window, = the freecad window since we are inside it
    FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
except Exception:
    FCmw = FreeCADGui.getMainWindow()             # PySide # the active qt window, = the freecad window since we are inside it 
    FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window

Working with Unicode :

try:
    text = unicode(text, 'ISO-8859-1').encode('UTF-8')  # PyQt4
except Exception:
    text = text.encode('utf-8')                         # PySide

Working with QFileDialog and OpenFileName :

OpenName = ""
try:
    OpenName = QFileDialog.getOpenFileName(None,QString.fromLocal8Bit("Lire un fichier FCInfo ou txt"),path,"*.FCInfo *.txt") # PyQt4
except Exception:
    OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Lire un fichier FCInfo ou txt", path, "*.FCInfo *.txt")#PySide

Working with QFileDialog and SaveFileName :

SaveName = ""
try:
    SaveName = QFileDialog.getSaveFileName(None,QString.fromLocal8Bit("Sauver un fichier FCInfo"),path,"*.FCInfo") # PyQt4
except Exception:
    SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Sauver un fichier FCInfo", path, "*.FCInfo")# PySide

The MessageBox:

def errorDialog(msg):
    diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
    try:
        diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # this function sets the window before
    except Exception:    
        diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint)# PySide # this function sets the window before
#    diag.setWindowModality(QtCore.Qt.ApplicationModal)       # function has been disabled to promote "WindowStaysOnTopHint"
    diag.exec_()

Working with setProperty (PyQt4) and setValue (PySide)

self.doubleSpinBox.setProperty("value", 10.0)  # PyQt4

replace to :

self.doubleSpinBox.setValue(10.0)  # PySide

Working with setToolTip

self.doubleSpinBox.setToolTip(_translate("MainWindow", "Coordinate placement Axis Y", None))  # PyQt4

replace to :

self.doubleSpinBox.setToolTip(_fromUtf8("Coordinate placement Axis Y"))  # PySide 

or :

self.doubleSpinBox.setToolTip(u"Coordinate placement Axis Y.")# PySide

Additional documentation

Some pyQt4 tutorials (including how to build interfaces with Qt Designer to use with python):

Pivy

Pivy is a needed by several modules to access the 3D view of FreeCAD. On windows, Pivy is already bundled inside the FreeCAD installer, and on Linux it is usually automatically installed when you install FreeCAD from an official repository. On MacOSX, unfortunately, you will need to compile pivy yourself.

Installation

Prerequisites

I believe before compiling Pivy you will want to have Coin and SoQt installed.

I found for building on Mac it was sufficient to install the Coin3 binary package. Attempting to install coin from MacPorts was problematic: tried to add a lot of X Windows packages and ultimately crashed with a script error.

For Fedora I found an RPM with Coin3.

SoQt compiled from source fine on Mac and Linux.

Debian & Ubuntu

Starting with Debian Squeeze and Ubuntu Lucid, pivy will be available directly from the official repositories, saving us a lot of hassle. In the meantime, you can either download one of the packages we made (for debian and ubuntu karmic) availables on the Download pages, or compile it yourself.

The best way to compile pivy easily is to grab the debian source package for pivy and make a package with debuild. It is the same source code from the official pivy site, but the debian people made several bug-fixing additions. It also compiles fine on ubuntu karmic: http://packages.debian.org/squeeze/python-pivy (download the .orig.gz and the .diff.gz file, then unzip both, then apply the .diff to the source: go to the unzipped pivy source folder, and apply the .diff patch:

patch -p1 < ../pivy_0.5.0~svn765-2.diff

then

debuild

to have pivy properly built into an official installable package. Then, just install the package with gdebi.

Other linux distributions

First get the latest sources from the project's repository:

hg clone http://hg.sim.no/Pivy/default Pivy 

As of March 2012, the latest version is Pivy-0.5.

Then you need a tool called SWIG to generate the C++ code for the Python bindings. Pivy-0.5 reports that it has only been tested with SWIG 1.3.31, 1.3.33, 1.3.35, and 1.3.40. So you can download a source tarball for one of these old versions from http://www.swig.org. Then unpack it and from a command line do (as root):

./configure
make
make install (or checkinstall if you use it)

It takes just a few seconds to build.

Alternatively, you can try building with a more recent SWIG. As of March 2012, a typical repository version is 2.0.4. Pivy has a minor compile problem with SWIG 2.0.4 on Mac OS (see below) but seems to build fine on Fedora Core 15.

After that go to the pivy sources and call

python setup.py build 

which creates the source files. Note that build can produce thousands of warnings, but hopefully there will be no errors.

This is probably obsolete, but you may run into a compiler error where a 'const char*' cannot be converted in a 'char*'. To fix that you just need to write a 'const' before in the appropriate lines. There are six lines to fix.

After that, install by issuing (as root):

python setup.py install (or checkinstall python setup.py install)

That's it, pivy is installed.

Mac OS

These instructions may not be complete. Something close to this worked for OS 10.7 as of March 2012. I use MacPorts for repositories, but other options should also work.

As for linux, get the latest source:

hg clone http://hg.sim.no/Pivy/default Pivy 

If you don't have hg, you can get it from MacPorts:

port install mercurial

Then, as above you need SWIG. It should be a matter of:

port install swig

I found I needed also:

port install swig-python

As of March 2012, MacPorts SWIG is version 2.0.4. As noted above for linux, you might be better off downloading an older version. SWIG 2.0.4 seems to have a bug that stops Pivy building. See first message in this digest: https://sourceforge.net/mailarchive/message.php?msg_id=28114815

This can be corrected by editing the 2 source locations to add dereferences: *arg4, *arg5 in place of arg4, arg5. Now Pivy should build:

python setup.py build
sudo python setup.py install

Windows

Assuming you are using Visual Studio 2005 or later you should open a command prompt with 'Visual Studio 2005 Command prompt' from the Tools menu. If the Python interpreter is not yet in the system path do

set PATH=path_to_python_2.5;%PATH%

To get pivy working you should get the latest sources from the project's repository:

svn co https://svn.coin3d.org/repos/Pivy/trunk Pivy 

Then you need a tool called SWIG to generate the C++ code for the Python bindings. It is recommended to use version 1.3.25 of SWIG, not the latest version, because at the moment pivy will only function correctly with 1.3.25. Download the binaries for 1.3.25 from http://www.swig.org. Then unpack it and from the command line add it to the system path

set PATH=path_to_swig_1.3.25;%PATH%

and set COINDIR to the appropriate path

set COINDIR=path_to_coin

On Windows the pivy config file expects SoWin instead of SoQt as default. I didn't find an obvious way to build with SoQt, so I modified the file setup.py directly. In line 200 just remove the part 'sowin' : ('gui._sowin', 'sowin-config', 'pivy.gui.') (do not remove the closing parenthesis).

After that go to the pivy sources and call

python setup.py build 

which creates the source files. You may run into a compiler error several header files couldn't be found. In this case adjust the INCLUDE variable

set INCLUDE=%INCLUDE%;path_to_coin_include_dir

and if the SoQt headers are not in the same place as the Coin headers also

set INCLUDE=%INCLUDE%;path_to_soqt_include_dir

and finally the Qt headers

set INCLUDE=%INCLUDE%;path_to_qt4\include\Qt

If you are using the Express Edition of Visual Studio you may get a python keyerror exception. In this case you have to modify a few things in msvccompiler.py located in your python installation.

Go to line 122 and replace the line

vsbase = r"Software\Microsoft\VisualStudio\%0.1f" % version

with

vsbase = r"Software\Microsoft\VCExpress\%0.1f" % version

Then retry again. If you get a second error like

error: Python was built with Visual Studio 2003;...

you must also replace line 128

self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")

with

self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv2.0")

Retry once again. If you get again an error like

error: Python was built with Visual Studio version 8.0, and extensions need to be built with the same version of the compiler, but it isn't installed.

then you should check the environment variables DISTUTILS_USE_SDK and MSSDK with

echo %DISTUTILS_USE_SDK%
echo %MSSDK%

If not yet set then just set it e.g. to 1

set DISTUTILS_USE_SDK=1
set MSSDK=1

Now, you may run into a compiler error where a 'const char*' cannot be converted in a 'char*'. To fix that you just need to write a 'const' before in the appropriate lines. There are six lines to fix. After that copy the generated pivy directory to a place where the python interpreter in FreeCAD can find it.

Usage

To check if Pivy is correctly installed:

import pivy

To have Pivy access the FreeCAD scenegraph do the following:

from pivy import coin
App.newDocument() # Open a document and a view 
view = Gui.ActiveDocument.ActiveView 
FCSceneGraph = view.getSceneGraph() # returns a pivy Python object that holds a SoSeparator, the main "container" of the Coin scenegraph
FCSceneGraph.addChild(coin.SoCube()) # add a box to scene 

You can now explore the FCSceneGraph with the dir() command.

Additonal Documentation

Unfortunately documentation about pivy is still almost inexistant on the net. But you might find Coin documentation useful, since pivy simply translate Coin functions, nodes and methods in python, everything keeps the same name and properties, keeping in mind the difference of syntax between C and python:

You can also look at the Draft.py file in the FreeCAD Mod/Draft folder, since it makes big use of pivy.

pyCollada

pyCollada is a python library that allow programs to read and write Collada (*.DAE) files. When pyCollada is installed on your system, FreeCAD will be able to handle importing and exporting in the Collada file format.

Installation

Pycollada is usually not yet available in linux distributions repositories, but since it is made only of python files, it doesn't require compilation, and is easy to install. You have 2 ways, or directly from the official pycollada git repository, or with the easy_install tool.

Linux

In either case, you'll need the following packages already installed on your system:

python-lxml 
python-numpy
python-dateutil
From the git repository
git clone git://github.com/pycollada/pycollada.git pycollada
cd pycollada
sudo python setup.py install
With easy_install

Assuming you have a complete python installation already, the easy_install utility should be present already:

easy_install pycollada

You can check if pycollada was correctly installed by issuing in a python console:

import collada

If it returns nothing (no error message), then all is OK

Windows

  1. Install Python. While FreeCAD and some other programs come with a bundled version of Python, having a fixed install will help with the next steps. You can get Python here: https://www.python.org/downloads/ . Of course you should pick the right version, in this case that would be 2.6.X, as FreeCAD currently uses 2.6.2 (Personally I went with 2.6.2, and by the way, you can check the version yourself by starting the Python.exe in the bin folder of FreeCAD). You'll also have to add the path of the installation directory into the path variable so you can access Python from the cmd. Now we can install the missing things, in total there are 3 things we need to install: numpy, setuptools, pycollada
  2. Fetch numpy here: http://sourceforge.net/projects/numpy/files/NumPy/ . Pick a version which fits to the version used by FreeCAD, there are multiple installers for different Python versions in every numpy version folder, the installer will put numpy into the folder of your Python installation, where FreeCAD can access it as well
  3. Fetch setuptools here: https://pypi.python.org/pypi/setuptools (We need to install the setuptools in order to install pycollada in the next step)
  4. Unzip the downloaded setuptools file somewhere
  5. Start a cmd with admin permission
  6. Navigate to the unpacked setuptools folder
  7. Install the setuptools by tipping "Python setup.py install" into the cmd, this will not work when Python is not installed or when the path variable hasn't been configured
  8. Fetch pycollada here: https://pypi.python.org/pypi/pycollada/ (has already been posted above) and once again:
  9. Unzip the downloaded pycollada file somewhere
  10. Start a cmd with admin permission, or use the one you opened not long ago
  11. Navigate to the unpacked pycollada folder
  12. Install the setuptools by tipping "Python setup.py install" into the cmd

Mac OS

If you are using the Homebrew build of FreeCAD you can install pycollada into your system Python using pip.

If you need to install pip:

$ sudo easy_install pip

Install pycollada:

$ sudo pip install pycollada

If you are using a binary version of FreeCAD, you can tell pip to install pycollada into the site-packages inside FreeCAD.app:

$ pip install --target="/Applications/FreeCAD.app/Contents/lib/python2.7/site-packages" pycollada

IfcOpenShell

IFCOpenShell is a library currently in development, that allows to import (and soon export) Industry foundation Classes (*.IFC) files. IFC is an extension to the STEP format, and is becoming the standard in BIM workflows. When ifcopenshell is correctly installed on your system, the FreeCAD Arch Module will detect it and use it to import IFC files, instead of its built-in rudimentary importer. Since ifcopenshell is based on OpenCasCade, like FreeCAD, the quality of the import is very high, producing high-quality solid geometry.

Installation

Since ifcopenshell is pretty new, you'll likely need to compile it yourself.

Linux

You will need a couple of development packages installed on your system in order to compile ifcopenshell:

liboce-*-dev
python-dev
swig

but since FreeCAD requires all of them too, if you can compile FreeCAD, you won't need any extra dependency to compile IfcOpenShell.

Grab the latest source code from here:

svn co https://ifcopenshell.svn.sourceforge.net/svnroot/ifcopenshell ifcopenshell

The build process is very easy:

mkdir ifcopenshell-build
cd ifcopenshell-build
cmake ../ifcopenshell/cmake

or, if you are using oce instead of opencascade:

cmake -DOCC_INCLUDE_DIR=/usr/include/oce ../ifcopenshell/cmake 

Since ifcopenshell is made primarily for Blender, it uses python3 by default. To use it inside FreeCAD, you need to compile it against the same version of python that is used by FreeCAD. So you might need to force the python version with additional cmake parameters (adjust the python version to yours):

cmake -DOCC_INCLUDE_DIR=/usr/include/oce -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DPYTHON_LIBRARY=/usr/lib/python2.7.so ../ifcopenshell/cmake

Then:

make
sudo make install

You can check that ifcopenshell was correctly installed by issuing in a python console:

import IfcImport

If it returns nothing (no error message), then all is OK

Windows

Copied from the IfcOpenShell README file

Users are advised to use the Visual Studio .sln file in the win/ folder. For Windows users a prebuilt Open CASCADE version is available from the http://opencascade.org website. Download and install this version and provide the paths to the Open CASCADE header and library files to MS Visual Studio C++.

For building the IfcPython wrapper, SWIG needs to be installed. Please download the latest swigwin version from http://www.swig.org/download.html . After extracting the .zip file, please add the extracted folder to the PATH environment variable. Python needs to be installed, please provide the include and library paths to Visual Studio.

Teigha Converter

The Teigha Converter is a small freely available utility that allows to convert between several versions of DWG and DXF files. FreeCAD can use it to offer DWG import and export, by converting DWG files to the DXF format under the hood,then using its standard DXF importer to import the file contents. The restrictions of the DXF importer apply.

Installation

On all platforms, only by installing the appropriate package from http://www.opendesign.com/guestfiles/TeighaFileConverter . After installation, if the utility is not found automatically by FreeCAD, you might need to set the path to the converter executable manually, in the menu Edit -> Preferences -> Draft -> Import/Export options.

Localisation
Source documentation