Hello,
I am trying to create an online application that uses python and freecad to change a model of some hardware my team is working on. I accomplishing this through a CGI script that imports FreeCAD. However, I am having trouble. First and main question, is there any way to use FreeCAD imported into a Python script to change and output a .fcstd file? I can not use the command line, it must all be in a script, so FreeCADcmd is out.
Thank you, and pardon my ignorance
Accessing Freecad through Python CGI Script
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 5
- Joined: Mon Apr 24, 2017 4:30 pm
- kkremitzki
- Veteran
- Posts: 2518
- Joined: Thu Mar 03, 2016 9:52 pm
- Location: Illinois
Re: Accessing Freecad through Python CGI Script
You can start with something like this:
Code: Select all
import sys
FCLIBPATH = '/usr/lib/freecad-daily/lib'
sys.path.append(FCLIBPATH)
import FreeCAD
-
- Posts: 5
- Joined: Mon Apr 24, 2017 4:30 pm
Re: Accessing Freecad through Python CGI Script
No luck with that so far. Here is what I have right now, and it is causing an error on my machine saying that it cannot import FreeCAD:
Also, I am using CentOS and Apache2, I believe.
Code: Select all
#!/usr/bin/python
FREECADPATH= '/usr/lib/freecad/bin/FreeCAD' #put path of freecad application path here
import sys, cgi, cgitb
sys.path.append(FREECADPATH)
import FreeCAD
from FreeCAD import App, Part, Mesh
form = cgi.FieldStorage()
...
- kkremitzki
- Veteran
- Posts: 2518
- Joined: Thu Mar 03, 2016 9:52 pm
- Location: Illinois
Re: Accessing Freecad through Python CGI Script
You need to use the lib path, not the path to the FreeCAD binary. The correct folder will have FreeCAD.so in it.
-
- Posts: 5
- Joined: Mon Apr 24, 2017 4:30 pm
Re: Accessing Freecad through Python CGI Script
Ah, okay good. It can now import Freecad, but is stuck at importing App. Just as a side note, I am purely a software dev with only minimal engineering/cad experience, so assume that I am ignorant (haha). Is "App" necessary to make changes to a file while I am using the embedded Freecad library?
Re: Accessing Freecad through Python CGI Script
Maybe this helps? viewtopic.php?t=5055valpocoder wrote:Is "App" necessary to make changes to a file while I am using the embedded Freecad library?
"fight the good fight"
-
- Posts: 5
- Joined: Mon Apr 24, 2017 4:30 pm
Re: Accessing Freecad through Python CGI Script
Ah, yes, that seemed to have solved my problem, thank you very much!