use freecad python module of Windows dev version
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
use freecad python module of Windows dev version
At work I have a CAD software which has a Pythoninterpreter (Nemetschek Allplan). I would like to import freecad moules in this Python environment. But I use the FreeCAD windwos dev version which is just an extracted 7zip archive. How can I use all the Pythonmodules from this FreeCAD?
bernd
bernd
Re: use freecad python module of Windows dev version
Hey bernd.
I think making sure the path to the modules are in your interpreters sys.path should work for .py files.
For the compiled extensions .pyd we need to determine what python version your interpreter is using.
"fight the good fight"
Re: use freecad python module of Windows dev version
which one do I need to import Part?
Re: use freecad python module of Windows dev version
You only have to make sure that Nemetschek Allplan finds the FreeCAD.pyd file. Then you must first import FreeCAD in order to initialize the internals of FreeCAD. If your directory structure is OK FreeCAD sets up everything so that it finds its extension modules later. Afterwards you can import Part.
Trying to import Part without loading FreeCAD first is not supposed to work and leads to a crash.
Trying to import Part without loading FreeCAD first is not supposed to work and leads to a crash.
Re: use freecad python module of Windows dev version
Thanks guys for the informations. Werner this is what I need. I will gibe it a try but it may take some time.
Since Allplan uses Python 3.x I'm lucky we gone provide Pyton 3 builds for windows. Sgrogan great
bernd
Since Allplan uses Python 3.x I'm lucky we gone provide Pyton 3 builds for windows. Sgrogan great
bernd
Re: use freecad python module of Windows dev version
Code: Select all
pathToFreeCAD = "C:\\0_BHA_privat\\progr\\FreeCAD_0.18.xxxxx_x64_dev_Py3_Qt5_win\\bin"
import sys
sys.path.append(pathToFreeCAD)
for p in sys.path:
print(p)
Code: Select all
import FreeCAD
Mhh since it crashes it does recognize something, means I seam on the right track ...
something to test the import if it works ...
Code: Select all
ver = FreeCAD.Version()
print("FreeCAD {0}.{1}.{2}".format(ver[0],ver[1],ver[2]))
Re: use freecad python module of Windows dev version
Next step is to compare the 3rd party libraries used by both applications. It might be possible that two different versions of a library is used by the applications which in most cases won't work.
An alternative is to not import FreeCAD directly but spawn a Python process and load the FreeCAD module this way (you can also spawn FreeCADCmd.exe). In this case it doesn't matter which 3rd party libraries both applications use, especially Python2 vs. Python3.
The problem then will be how to interchange data between the processes: https://stackoverflow.com/questions/392 ... plications
An alternative is to not import FreeCAD directly but spawn a Python process and load the FreeCAD module this way (you can also spawn FreeCADCmd.exe). In this case it doesn't matter which 3rd party libraries both applications use, especially Python2 vs. Python3.
The problem then will be how to interchange data between the processes: https://stackoverflow.com/questions/392 ... plications
Re: use freecad python module of Windows dev version
I would like to try tackling this down. Werner do you have an idea how to get more errormessages from what is happening after import FreeCAD in Allplan, by the use of Python. Or how would you processeed ?
bernd
Re: use freecad python module of Windows dev version
When exactly does it crash? Does the terminal window return when entering "import FreeCAD"?
If you have installed Visual Studio on this computer (it doesn't matter which version) you can attach the debugger to the Allplan executable after it has crashed (don't click on "Programm schließen"). The debugger may give some further information about where the crash happens.
If you don't have VS here you can also use WinDbg which is part of the Debugging Tools for Windows. If none of them is available you can use the tool ProcessExplorer (www.sysinternals.com), select the crashing executable and create a dump file. You can choose between mini dump (small file size) and full dump (can become huge). Then you can analyse the dump file on another computer where a debugger is available.
Btw, with ProcessExplorer you see all dlls an executable has loaded and you may find conflicting versions used by Allplan and FreeCAD.
If you have installed Visual Studio on this computer (it doesn't matter which version) you can attach the debugger to the Allplan executable after it has crashed (don't click on "Programm schließen"). The debugger may give some further information about where the crash happens.
If you don't have VS here you can also use WinDbg which is part of the Debugging Tools for Windows. If none of them is available you can use the tool ProcessExplorer (www.sysinternals.com), select the crashing executable and create a dump file. You can choose between mini dump (small file size) and full dump (can become huge). Then you can analyse the dump file on another computer where a debugger is available.
Btw, with ProcessExplorer you see all dlls an executable has loaded and you may find conflicting versions used by Allplan and FreeCAD.
Re: use freecad python module of Windows dev version
Wow cool a lot of informations. I will go and give them a try.
bernd
The problem with Allplan Python is, you do not have your own terminal to interact with the Python interpreter like in FreeCAD. One creates a Python file with all the code inside. In Allplan GUI you can drop your PythonPart in the Allplan drawing window. You can not interact. The only thing which is available is the Allplan trace window which prints all kind of informations including Python outputs. See earlier post wha is printed ... nothing. If import FreeCAD is omited everything runs smooth.
bernd