Extra python modules/sv: Difference between revisions

From FreeCAD Documentation
(Created page with "Försök igen. Om du åter får ett fel som")
(Updating to match new version of source page)
 
(39 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<languages/>
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.

{{Docnav
|[[Workbench_creation|Workbench creation]]
|[[Source_documentation|Source documentation]]
}}

{{TOCright}}

==Overview==

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 PyQt) ==


== PySide (previously PyQt4) ==
* 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


Line 13: Line 25:


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

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 ====
==== MacOS ====

PyQt on Mac can be installed via homebrew or port. See [[CompileOnMac#Install_Dependencies]] for more information.
PySide on Mac can be installed via homebrew or port. See [[Compile on MacOS#Install_Dependencies|Install dependencies]] for more information.


=== Usage ===
=== Usage ===

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

{{Code|code=
import PySide
import PySide
}}
</pre>

To access the FreeCAD interface, type :
To access the FreeCAD interface, type:
<pre>

{{Code|code=
from PySide import QtCore,QtGui
from PySide import QtCore,QtGui
FreeCADWindow = FreeCADGui.getMainWindow()
FreeCADWindow = FreeCADGui.getMainWindow()
}}
</pre>

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

{{Code|code=
FreeCADWindow.addDockWidget(QtCore.Qt.RghtDockWidgetArea,my_custom_widget)
FreeCADWindow.addDockWidget(QtCore.Qt.RghtDockWidgetArea,my_custom_widget)
}}
</pre>

Working with Unicode :
Working with Unicode:
<pre>

{{Code|code=
text = text.encode('utf-8')
text = text.encode('utf-8')
}}
</pre>

Working with QFileDialog and OpenFileName :
Working with QFileDialog and OpenFileName:
<pre>

{{Code|code=
path = FreeCAD.ConfigGet("AppHomePath")
path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
#path = FreeCAD.ConfigGet("UserAppData")
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Read a txt file", path, "*.txt")
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Read a txt file", path, "*.txt")
}}
</pre>

Working with QFileDialog and SaveFileName :
Working with QFileDialog and SaveFileName:
<pre>

{{Code|code=
path = FreeCAD.ConfigGet("AppHomePath")
path = FreeCAD.ConfigGet("AppHomePath")
#path = FreeCAD.ConfigGet("UserAppData")
#path = FreeCAD.ConfigGet("UserAppData")
SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Save a file txt", path, "*.txt")
SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Save a file txt", path, "*.txt")
}}
</pre>

===Example of transition from PyQt4 and PySide===
===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
PS: these examples of errors were found in the transition from PyQt4 to PySide and these corrections were made, other solutions are certainly available with the examples above

<pre>
{{Code|code=
try:
try:
import PyQt4 # PyQt4
import PyQt4 # PyQt4
Line 71: Line 100:
from PySide.QtGui import * # PySide
from PySide.QtGui import * # PySide
from PySide.QtCore import * # PySide
from PySide.QtCore import * # PySide
}}
</pre>

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

{{Code|code=
myNewFreeCADWidget = QtGui.QDockWidget() # create a new dockwidget
myNewFreeCADWidget = QtGui.QDockWidget() # create a new dockwidget
myNewFreeCADWidget.ui = Ui_MainWindow() # myWidget_Ui() # load the Ui script
myNewFreeCADWidget.ui = Ui_MainWindow() # myWidget_Ui() # load the Ui script
Line 83: Line 114:
FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
except Exception:
except Exception:
FCmw = FreeCADGui.getMainWindow() # PySide # the active qt window, = the freecad window since we are inside it
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
FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
}}
</pre>

Working with Unicode :
Working with Unicode:
<pre>

{{Code|code=
try:
try:
text = unicode(text, 'ISO-8859-1').encode('UTF-8') # PyQt4
text = unicode(text, 'ISO-8859-1').encode('UTF-8') # PyQt4
except Exception:
except Exception:
text = text.encode('utf-8') # PySide
text = text.encode('utf-8') # PySide
}}
</pre>

Working with QFileDialog and OpenFileName :
Working with QFileDialog and OpenFileName:
<pre>

{{Code|code=
OpenName = ""
OpenName = ""
try:
try:
Line 100: Line 135:
except Exception:
except Exception:
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Lire un fichier FCInfo ou txt", path, "*.FCInfo *.txt")#PySide
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Lire un fichier FCInfo ou txt", path, "*.FCInfo *.txt")#PySide
}}
</pre>

Working with QFileDialog and SaveFileName :
Working with QFileDialog and SaveFileName:
<pre>

{{Code|code=
SaveName = ""
SaveName = ""
try:
try:
Line 108: Line 145:
except Exception:
except Exception:
SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Sauver un fichier FCInfo", path, "*.FCInfo")# PySide
SaveName, Filter = PySide.QtGui.QFileDialog.getSaveFileName(None, "Sauver un fichier FCInfo", path, "*.FCInfo")# PySide
}}
</pre>

The MessageBox:
The MessageBox:

<pre>
{{Code|code=
def errorDialog(msg):
def errorDialog(msg):
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
diag = QtGui.QMessageBox(QtGui.QMessageBox.Critical,u"Error Message",msg )
try:
try:
diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # this function sets the window before
diag.setWindowFlags(PyQt4.QtCore.Qt.WindowStaysOnTopHint) # PyQt4 # this function sets the window before
except Exception:
except Exception:
diag.setWindowFlags(PySide.QtCore.Qt.WindowStaysOnTopHint)# PySide # this function sets the window before
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.setWindowModality(QtCore.Qt.ApplicationModal) # function has been disabled to promote "WindowStaysOnTopHint"
diag.exec_()
diag.exec_()
}}
</pre>

Working with setProperty (PyQt4) and setValue (PySide)
Working with setProperty (PyQt4) and setValue (PySide)

<pre>
{{Code|code=
self.doubleSpinBox.setProperty("value", 10.0) # PyQt4
self.doubleSpinBox.setProperty("value", 10.0) # PyQt4
</pre>
}}
replace to :

<pre>
replace with:
self.doubleSpinBox.setValue(10.0) # PySide

</pre>
{{Code|code=
self.doubleSpinBox.setValue(10.0) # PySide
}}

Working with setToolTip
Working with setToolTip

<pre>
{{Code|code=
self.doubleSpinBox.setToolTip(_translate("MainWindow", "Coordinate placement Axis Y", None)) # PyQt4
self.doubleSpinBox.setToolTip(_translate("MainWindow", "Coordinate placement Axis Y", None)) # PyQt4
</pre>
}}
replace to :

<pre>
replace with:
self.doubleSpinBox.setToolTip(_fromUtf8("Coordinate placement Axis Y")) # PySide

</pre>
{{Code|code=
or :
self.doubleSpinBox.setToolTip(_fromUtf8("Coordinate placement Axis Y")) # PySide
<pre>
}}

or:

{{Code|code=
self.doubleSpinBox.setToolTip(u"Coordinate placement Axis Y.")# PySide
self.doubleSpinBox.setToolTip(u"Coordinate placement Axis Y.")# PySide
}}
</pre>

=== Additional documentation ===
=== Additional documentation ===

Some pyQt4 tutorials (including how to build interfaces with Qt Designer to use with python):
* [https://doc.qt.io/qt.html#qtforpython Qt official documentation site]
* 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 ==
== Pivy ==

* 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


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 macOS, unfortunately, you will need to compile pivy yourself.


=== Installation ===
=== Installation ===


==== Prerequisites ====
==== Prerequisites ====

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.


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.


For Fedora I found an RPM with Coin3.
For Fedora I found an RPM with Coin3.
Line 164: Line 214:
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 ====

<div class="mw-translate-fuzzy">
====Debian & Ubuntu====
====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å [[Download/sv|Nedladdnings]]sidorna, eller så kan du kompilera det själv.
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å [[Download/sv|Nedladdnings]]sidorna, eller så kan du kompilera det själv.
</div>

<div class="mw-translate-fuzzy">
Det bästa sättet att kompilera pivy smidigt är att hämta debians källkodspaket för pivy och göra ett paket med debuild. Det är samma källkod som på den officiella pivysajten, men debianfolket har gjort flera bugg-fixningstillägg. Det kompilerar också bra på ubuntu karmic: http://packages.debian.org/squeeze/python-pivy (ladda ned .orig.gz och .diff.gz file, packa upp båda, tillämpa sedan .diff på källkoden: gå till den uppackade pivy källkodsmappen, och tillämpa .diff patchen:
</div>


{{Code|code=
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:
<pre>
patch -p1 < ../pivy_0.5.0~svn765-2.diff
patch -p1 < ../pivy_0.5.0~svn765-2.diff
}}
</pre>

sedan
sedan

<pre>
{{Code|code=
debuild
debuild
}}
</pre>

för att få pivy korrekt byggt till ett officiellt installerbart paket. Sedan så är det bara att installera paketet med gdebi.
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 ====
==== Other linux distributions ====

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

<pre>
{{Code|code=
hg clone http://hg.sim.no/Pivy/default Pivy
hg clone http://hg.sim.no/Pivy/default Pivy
</pre>
}}

As of March 2012, the latest version is Pivy-0.5.
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 http://www.swig.org]. Packa sedan upp den, och gör som root följande i en konsol:
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 http://www.swig.org]. Packa sedan upp den, och gör som root följande i en konsol:

<pre>
{{Code|code=
./configure
./configure
make
make
make install (or checkinstall if you use it)
make install (or checkinstall if you use it)
}}
</pre>
Det tar bara några sekunder att bygga.


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.

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 macOS (see below) but seems to build fine on Fedora Core 15.

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

{{Code|code=
python setup.py build
}}


Efter det, gå till pivy källkoden och anropa
<pre>
python setup.py build
</pre>
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.


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.
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):
Det finns sex rader att fixa. Efter det, installera genom att skriva (som root):

<pre>
{{Code|code=
python setup.py install (or checkinstall python setup.py install)
python setup.py install (or checkinstall python setup.py install)
}}
</pre>

Klart! Pivy är installerat.
Klart! Pivy är installerat.


==== Mac OS ====
==== MacOS ====

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.


As for linux, get the latest source:
As for linux, get the latest source:

<pre>
{{Code|code=
hg clone http://hg.sim.no/Pivy/default Pivy
hg clone http://hg.sim.no/Pivy/default Pivy
</pre>
}}

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

<pre>
{{Code|code=
port install mercurial
port install mercurial
}}
</pre>

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

{{Code|code=
port install swig
port install swig
}}
</pre>

I found I needed also:
I found I needed also:

<pre>
{{Code|code=
port install swig-python
port install swig-python
}}
</pre>
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 [https://sourceforge.net/mailarchive/message.php?msg_id=28114815 digest]
This can be corrected by editing the 2 source locations to add dereferences: *arg4, *arg5 in place of arg4, arg5. Now Pivy should build:

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

{{Code|code=
python setup.py build
python setup.py build
sudo python setup.py install
sudo python setup.py install
}}
</pre>

==== Windows ====

<div class="mw-translate-fuzzy">
====Windows====
====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.
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
Om du ännu inte har Pythontolken i systemsökvägen, gör
<pre>
</div>

{{Code|code=
set PATH=path_to_python_2.5;%PATH%
set PATH=path_to_python_2.5;%PATH%
}}
</pre>

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

<pre>
{{Code|code=
svn co https://svn.coin3d.org/repos/Pivy/trunk Pivy
svn co https://svn.coin3d.org/repos/Pivy/trunk Pivy
</pre>
}}

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 http://www.swig.org]. Packa sedan upp den och lägg till den i systemsökvägen från kommandoraden
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 http://www.swig.org]. Packa sedan upp den och lägg till den i systemsökvägen från kommandoraden

<pre>
{{Code|code=
set PATH=path_to_swig_1.3.25;%PATH%
set PATH=path_to_swig_1.3.25;%PATH%
}}
</pre>

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

<pre>
{{Code|code=
set COINDIR=path_to_coin
set COINDIR=path_to_coin
}}
</pre>

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.
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).
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
Efter det, gå till pivy källkoden och anropa

<pre>
{{Code|code=
python setup.py build
python setup.py build
</pre>
}}

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

<pre>
{{Code|code=
set INCLUDE=%INCLUDE%;path_to_coin_include_dir
set INCLUDE=%INCLUDE%;path_to_coin_include_dir
}}
</pre>

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

<pre>
{{Code|code=
set INCLUDE=%INCLUDE%;path_to_soqt_include_dir
set INCLUDE=%INCLUDE%;path_to_soqt_include_dir
}}
</pre>

och slutligen Qt headers
och slutligen Qt headers

<pre>
{{Code|code=
set INCLUDE=%INCLUDE%;path_to_qt4\include\Qt
set INCLUDE=%INCLUDE%;path_to_qt4\include\Qt
}}
</pre>

<div class="mw-translate-fuzzy">
Om du använder Expressutgåvan av Visual Studio så kan du få ett python keyerror undantag.
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.
I detta fall så måste du ändra en del saker i msvccompiler.py som finns i din python installation.
</div>


Gå till rad 122 och byt ut raden
Gå till rad 122 och byt ut raden

<pre>
{{Code|code=
vsbase = r"Software\Microsoft\VisualStudio\%0.1f" % version
vsbase = r"Software\Microsoft\VisualStudio\%0.1f" % version
}}
</pre>

mot
mot

<pre>
{{Code|code=
vsbase = r"Software\Microsoft\VCExpress\%0.1f" % version
vsbase = r"Software\Microsoft\VCExpress\%0.1f" % version
}}
</pre>

<div class="mw-translate-fuzzy">
Försök sedan igen.
Försök sedan igen.


Om du får ett andra fel som
Om du får ett andra fel som
<pre>
</div>

{{Code|code=
error: Python was built with Visual Studio 2003;...
error: Python was built with Visual Studio 2003;...
}}
</pre>

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

<pre>
{{Code|code=
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")
}}
</pre>

mot
mot

<pre>
{{Code|code=
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv2.0")
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv2.0")
}}
</pre>

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

<pre>
{{Code|code=
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.
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.
}}
</pre>

then you should check the environment variables DISTUTILS_USE_SDK and MSSDK with
så ska du kontrollera miljövariablerna DISTUTILS_USE_SDK och MSSDK med
<pre>

{{Code|code=
echo %DISTUTILS_USE_SDK%
echo %DISTUTILS_USE_SDK%
echo %MSSDK%
echo %MSSDK%
}}
</pre>

If not yet set then just set it e.g. to 1
Om de inte är inställda än, ställ in dem till 1
<pre>

{{Code|code=
set DISTUTILS_USE_SDK=1
set DISTUTILS_USE_SDK=1
set MSSDK=1
set MSSDK=1
}}
</pre>

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.
<div class="mw-translate-fuzzy">
After that copy the generated pivy directory to a place where the python interpreter in FreeCAD can find it.
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.
</div>


=== Usage ===
=== Usage ===

To check if Pivy is correctly installed:
To check if Pivy is correctly installed:

<pre>
{{Code|code=
import pivy
import pivy
}}
</pre>

To have Pivy access the FreeCAD scenegraph do the following:
För att Pivy ska komma åt FreeCAD scengrafen, gör följande:
<pre>

{{Code|code=
from pivy import coin
from pivy import coin
App.newDocument() # Open a document and a view
App.newDocument() # Open a document and a view
view = Gui.ActiveDocument.ActiveView
view = Gui.ActiveDocument.ActiveView
FCSceneGraph = view.getSceneGraph() # returns a pivy Python object that holds a SoSeparator, the main "container" of the Coin scenegraph
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
FCSceneGraph.addChild(coin.SoCube()) # add a box to scene
}}
</pre>

You can now explore the FCSceneGraph with the dir() command.
Nu kan du utforska FCSceneGraph med dir() kommandot.


=== Additonal Documentation ===
=== 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:
<div class="mw-translate-fuzzy">
===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:
</div>


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


You can also look at the Draft.py file in the FreeCAD Mod/Draft folder, since it makes big use of pivy.
Du kan också titta Draft.py filen i FreeCAD Mod/Draft mappen, eftersom den använder pivy mycket.


== pyCollada ==
== pyCollada ==

* 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


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

In either case, you'll need the following packages already installed on your system:
{{Code|code=
<pre>
sudo apt-get install python3-collada
python-lxml
}}
python-numpy

python-dateutil
You can check if pycollada was correctly installed by issuing in a Python console:
</pre>

===== From the git repository =====
{{Code|code=
<pre>
git clone git://github.com/pycollada/pycollada.git pycollada
cd pycollada
sudo python setup.py install
</pre>
===== With easy_install =====
Assuming you have a complete python installation already, the easy_install utility should be present already:
<pre>
easy_install pycollada
</pre>
You can check if pycollada was correctly installed by issuing in a python console:
<pre>
import collada
import collada
}}
</pre>

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


==== Windows ====
==== Windows ====


On Windows since 0.15 pycollada is included in both the FreeCAD release and developer builds so no additional steps are necessary.
# 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 setuptools here: https://pypi.python.org/pypi/setuptools (We need to install the setuptools in order to install pycollada in the next step)
# Unzip the downloaded setuptools file somewhere
# Start a cmd with admin permission
# Navigate to the unpacked setuptools folder
# 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
# Fetch pycollada here: https://pypi.python.org/pypi/pycollada/ (has already been posted above) and once again:
# Unzip the downloaded pycollada file somewhere
# Start a cmd with admin permission, or use the one you opened not long ago
# Navigate to the unpacked pycollada folder
# Install the setuptools by tipping "Python setup.py install" into the cmd


==== MacOS ====
* 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 are using the Homebrew build of FreeCAD you can install pycollada into your system Python using pip.


If you need to install pip:
If you need to install pip:

<pre>
{{Code|code=
$ sudo easy_install pip
$ sudo easy_install pip
}}
</pre>

Install pycollada:
Install pycollada:

<pre>
{{Code|code=
$ sudo pip install pycollada
$ sudo pip install pycollada
}}
</pre>

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:

<pre>
{{Code|code=
$ pip install --target="/Applications/FreeCAD.app/Contents/lib/python2.7/site-packages" pycollada
$ pip install --target="/Applications/FreeCAD.app/Contents/lib/python2.7/site-packages" pycollada
}}
</pre>

or after downloading the pycollada code

{{Code|code=
$ export PYTHONPATH=/Applications/FreeCAD\ 0.16.6706.app/Contents/lib/python2.7/site-packages:$PYTHONPATH
$ python setup.py install --prefix=/Applications/FreeCAD\ 0.16.6706.app/Contents
}}

== IfcOpenShell ==
== IfcOpenShell ==


Line 412: Line 533:
* optional, needed to extend import abilities of IFC files
* optional, needed to extend import abilities of IFC files


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 Workbench]] 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 ===

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

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:

<pre>
{{Code|code=
liboce-*-dev
liboce-*-dev
python-dev
python-dev
swig
swig
}}
</pre>

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.


Grab the latest source code from here:
Grab the latest source code from here:

<pre>
{{Code|code=
svn co https://ifcopenshell.svn.sourceforge.net/svnroot/ifcopenshell ifcopenshell
git clone https://github.com/IfcOpenShell/IfcOpenShell.git
</pre>
}}

The build process is very easy:
The build process is very easy:

<pre>
{{Code|code=
mkdir ifcopenshell-build
mkdir ifcopenshell-build
cd ifcopenshell-build
cd ifcopenshell-build
cmake ../ifcopenshell/cmake
cmake ../IfcOpenShell/cmake
}}
</pre>

or, if you are using oce instead of opencascade:
or, if you are using oce instead of opencascade:

<pre>
{{Code|code=
cmake -DOCC_INCLUDE_DIR=/usr/include/oce ../ifcopenshell/cmake
cmake -DOCC_INCLUDE_DIR=/usr/include/oce ../ifcopenshell/cmake
</pre>
}}
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):

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

{{Code|code=
cmake -DOCC_INCLUDE_DIR=/usr/include/oce -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DPYTHON_LIBRARY=/usr/lib/python2.7.so ../ifcopenshell/cmake
cmake -DOCC_INCLUDE_DIR=/usr/include/oce -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DPYTHON_LIBRARY=/usr/lib/python2.7.so ../ifcopenshell/cmake
}}
</pre>

Then:
Then:

<pre>
{{Code|code=
make
make
sudo make install
sudo make install
}}
</pre>

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

import IfcImport
{{Code|code=
</pre>
import ifcopenshell
}}

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


==== Windows ====
==== Windows ====

'''Note''': Official FreeCAD installers obtained from the FreeCAD website/github page now contain ifcopenshell already.


''Copied from the IfcOpenShell README file''
''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++.
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 opencascade 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.
For building the IfcPython wrapper, SWIG needs to be installed. Please download the latest swigwin version from [https://www.swig.org/download.html swig website]. 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.


===Links===
== Teigha Converter ==


Tutorial [[Import/Export_IFC_-_compiling_IfcOpenShell|Import/Export IFC - compiling IfcOpenShell]]
* homepage: http://www.opendesign.com/guestfiles/TeighaFileConverter
* license: freeware
* optional, used to enable import and export of DWG files


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

LazyLoader is a Python module that allows deferred loading, while still importing at the top of the script. This is useful if you are importing another module that is slow, and it is used several times throughout the script. Using LazyLoader can improve workbench startup times, but the module will still need to be loaded on first use.


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


LazyLoader is included with FreeCAD v0.19
{{docnav|Localisation|Source documentation}}


=== Usage ===
[[Category:Developer Documentation]]


You will need to import LazyLoader, then change the import of whatever module you want to be deferred.
{{clear}}

<languages/>
{{Code|code=
from lazy_loader.lazy_loader import LazyLoader
Part = LazyLoader('Part', globals(), 'Part')
}}
The variable Part is how the module is named in your script. You can replicate "import Part as P" by changing the variable.

{{Code|code=
P = LazyLoader('Part', globals(), 'Part')
}}
You can also import a module from a package.
{{Code|code=
utils = LazyLoader('PathScripts', globals(), 'PathScripts.PathUtils')
}}
You can't import individual functions, just entire modules.

=== Links ===

* Original source: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/util/lazy_loader.py
* Further explanation: https://wil.yegelwel.com/lazily-importing-python-modules/
* Code within the FreeCAD source code: https://github.com/FreeCAD/FreeCAD/tree/master/src/3rdParty/lazy_loader
* Forum discussion: https://forum.freecadweb.org/viewtopic.php?f=10&t=45298


<div class="mw-translate-fuzzy">
{{docnav/sv|Localisation/sv|Source documentation/sv}}
</div>

{{Userdocnavi{{#translation:}}}}
[[Category:Python Code{{#translation:}}]]
[[Category:Developer Documentation{{#translation:}}]]

Latest revision as of 18:15, 14 November 2023

Overview

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

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.

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

MacOS

PySide on Mac can be installed via homebrew or port. See 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 from 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 with:

self.doubleSpinBox.setValue(10.0) # PySide

Working with setToolTip

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

replace with:

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

or:

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

Additional documentation

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 macOS, 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

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.

Det bästa sättet att kompilera pivy smidigt är att hämta debians källkodspaket för pivy och göra ett paket med debuild. Det är samma källkod som på den officiella pivysajten, men debianfolket har gjort flera bugg-fixningstillägg. Det kompilerar också bra på ubuntu karmic: http://packages.debian.org/squeeze/python-pivy (ladda ned .orig.gz och .diff.gz file, packa upp båda, tillämpa sedan .diff på källkoden: gå till den uppackade pivy källkodsmappen, och tillämpa .diff patchen:

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

sedan

debuild

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:

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

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:

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

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 macOS (see below) but seems to build fine on Fedora Core 15.

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

python setup.py build

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

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

Klart! Pivy är installerat.

MacOS

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

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

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

set PATH=path_to_python_2.5;%PATH%

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

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

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

set PATH=path_to_swig_1.3.25;%PATH%

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

set COINDIR=path_to_coin

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

python setup.py build

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

set INCLUDE=%INCLUDE%;path_to_coin_include_dir

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

set INCLUDE=%INCLUDE%;path_to_soqt_include_dir

och slutligen Qt headers

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

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

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

mot

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

Försök sedan igen.

Om du får ett andra fel som

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

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

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

mot

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

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

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.

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

echo %DISTUTILS_USE_SDK%
echo %MSSDK%

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

set DISTUTILS_USE_SDK=1
set MSSDK=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:

import pivy

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

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

Nu kan du utforska FCSceneGraph med dir() kommandot.

Additonal Documentation

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:

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

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

Linux

sudo apt-get install python3-collada

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

On Windows since 0.15 pycollada is included in both the FreeCAD release and developer builds so no additional steps are necessary.

MacOS

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

or after downloading the pycollada code

$ export PYTHONPATH=/Applications/FreeCAD\ 0.16.6706.app/Contents/lib/python2.7/site-packages:$PYTHONPATH
$ python setup.py install --prefix=/Applications/FreeCAD\ 0.16.6706.app/Contents

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

git clone https://github.com/IfcOpenShell/IfcOpenShell.git

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 ifcopenshell

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

Windows

Note: Official FreeCAD installers obtained from the FreeCAD website/github page now contain ifcopenshell already.

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 opencascade 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 swig website. 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.

Links

Tutorial Import/Export IFC - compiling IfcOpenShell

LazyLoader

LazyLoader is a Python module that allows deferred loading, while still importing at the top of the script. This is useful if you are importing another module that is slow, and it is used several times throughout the script. Using LazyLoader can improve workbench startup times, but the module will still need to be loaded on first use.

Installation

LazyLoader is included with FreeCAD v0.19

Usage

You will need to import LazyLoader, then change the import of whatever module you want to be deferred.

from lazy_loader.lazy_loader import LazyLoader
Part = LazyLoader('Part', globals(), 'Part')

The variable Part is how the module is named in your script. You can replicate "import Part as P" by changing the variable.

P = LazyLoader('Part', globals(), 'Part')

You can also import a module from a package.

utils = LazyLoader('PathScripts', globals(), 'PathScripts.PathUtils')

You can't import individual functions, just entire modules.

Links


Localisation/sv
Source documentation/sv