Extra python modules/sv

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)

 * homepage (PySide): http://qt-project.org/wiki/PySide
 * license: LGPL
 * optional, but needed by several modules: Draft, Arch, Ship, Plot, OpenSCAD, Spreadsheet

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.

Notera: av följande moduler, så är Pivy nu helt integrerad i alla FreeCAD installationspaket, och PyQt4 är också integrerat i Windows installationspaket.

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 for more information.

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

To access the FreeCAD interface, type :

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

Working with Unicode :

Working with QFileDialog and OpenFileName :

Working with QFileDialog and SaveFileName :

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

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

Working with Unicode :

Working with QFileDialog and OpenFileName :

Working with QFileDialog and SaveFileName :

The MessageBox:

Working with setProperty (PyQt4) and setValue (PySide)

replace to :

Working with setToolTip

replace to :

or :

Additional documentation
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://www.rkblog.rk.edu.pl/w/p/introduction-pyqt4/ - a simple introduction
 * http://www.zetcode.com/tutorials/pyqt4/ - very complete in-depth tutorial

Pivy

 * homepage: https://bitbucket.org/Coin3D/coin/wiki/Home
 * license: BSD
 * optional, but needed by several modules of FreeCAD: Draft, Arch

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.

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
Med början i Debian Squeeze och Ubuntu Lucid, så kommer pivy att finnas tillgängligt direkt från de officiella förråden, vilket sparar mycket krångel. Innan dess, så kan du antingen ladda ned ett av de paket som vi har gjort (för debian och ubuntu karmic) tillgängliga på Nedladdningssidorna, eller så kan du kompilera det själv.

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:

sedan

för att få pivy korrekt byggt till ett officiellt installerbart paket. Sedan så är det bara att installera paketet med gdebi.

Other linux distributions
First get the latest sources from the project's repository:

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

Sedan behöver du ett verktyg som kallas för SWIG för att generera C++ koden för Pythonbindningarna. Det rekommenderas att version 1.3.25 av SWIG används, inte den senaste versionen, därför att pivy för tillfället endast fungerar korrekt med 1.3.25. Ladda ned 1.3.25 source tarball från http://www.swig.org. Packa sedan upp den, och gör som root följande i en konsol:

Det tar bara några sekunder att bygga.

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.

Efter det, gå till pivy källkoden och anropa

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

viltet skapar källkodsfilerna. Du kan få kompileringsfel där en 'const char*' inte kan konverteras till en 'char*'. För att fixa det så behöver du bara skriva en 'const' innan raderna som orsakade felet.

Det finns sex rader att fixa. Efter det, installera genom att skriva (som root):

Klart! Pivy är installerat.

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:

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

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

I found I needed also:

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:

Windows
När du använder Visual Studio 2005 eller senare så ska du öppna en kommandoprompt med 'Visual Studio 2005 Command prompt' från Tools menyn. Om du ännu inte har Pythontolken i systemsökvägen, gör

För att få pivy att fungera så ska du hämta den senaste källkoden från projektets förråd:

Sedan behöver du ett verktyg som kallas för SWIG för att generera C++ koden för Python bindningarna. Det rekommenderas att version 1.3.25 av SWIG används, inte den senaste versionen, därför att pivy för tillfället endast fungerar korrekt med 1.3.25. Ladda ned binärkoden för 1.3.25 från http://www.swig.org. Packa sedan upp den och lägg till den i systemsökvägen från kommandoraden

och ställ in COINDIR till den riktiga sökvägen

På Windows så förväntar sig pivys konfigurationsfil SoWin istället för SoQt som standard. Jag har inte hittat en självklart sätt att bygga med SoQt, så Jag modifierade filen setup.py direkt.

Ta på rad 200 bort delen 'sowin' : ('gui._sowin', 'sowin-config', 'pivy.gui.') (ta inte bort den stängande parentesen).

Efter det, gå till pivy källkoden och anropa

vilket skapar källkodsfilerna. Du kan få kompileringsfel för att flera headerfiler inte kunde hittas. I detta fall så får du justera INCLUDE variabeln

och om SoQt headers int är på samma plats som Coin headers så får du också justera

och slutligen Qt headers

Om du använder Expressutgåvan av Visual Studio så kan du få ett python keyerror undantag.

I detta fall så måste du ändra en del saker i msvccompiler.py som finns i din python installation.

Gå till rad 122 och byt ut raden

mot

Försök sedan igen.

Om du får ett andra fel som

Så måste du även byta ut rad 128

mot

Försök igen. Om du åter får ett fel som

så ska du kontrollera miljövariablerna DISTUTILS_USE_SDK och MSSDK med

Om de inte är inställda än, ställ in dem till 1

Nu kan du få kompileringsfel där en 'const char*' inte kan konverteras till en 'char*'. För att fixa det så behöver du bara skriva en 'const' innan raderna som orsakade felet. Det finns sex rader att fixa.

Kopiera sedan den genererade pivykatalogen till en plats där pythontolken i FreeCAD kan hitta den.

Usage
To check if Pivy is correctly installed:

För att Pivy ska komma åt FreeCAD scengrafen, gör följande:

Nu kan du utforska FCSceneGraph med dir kommandot.

Dokumentation
Olyckligtvis så existerar det knappast ännu någon dokumentation om pivy på nätet. Men Coin dokumentationen kan vara användbar, eftersom pivy helt enkelt översätter Coin funktioner, noder och metoder i python, allt behåller samma namn och egenskaper, bara man tänker på syntaxskillnaden mellan C och python:


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

Du kan också titta på Draft.py filen i FreeCAD Mod/Draft mappen, eftersom den använder pivy mycket.

pyCollada

 * homepage: http://pycollada.github.com
 * license: BSD
 * optional, needed to enable import and export of Collada (.DAE) files

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:

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

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

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


 * Another reference on how to use easy_install: http://jishus.org/?p=452

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:

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:

IfcOpenShell

 * homepage: http://www.ifcopenshell.org
 * license: LGPL
 * optional, needed to extend import abilities of IFC files

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:

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:

The build process is very easy:

or, if you are using oce instead of opencascade:

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):

Then:

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

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

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

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.