Create a image file from a freecad file using just python

Need help, or want to share a macro? Post here!
Post Reply
Posts: 5
Joined: Wed Sep 15, 2021 6:07 pm

Create a image file from a freecad file using just python

Post by vito »

Hi good day.

First thanks a lot for the software. It is greatly appreciated.

Second I know there exists other posts with the same topics but the truth is, those haven’t work for me.
Anyway I’m using FreeCAD version 0.19 in an ubuntu 20.04 with python 3.8.
I imagine that perhaps some solutions could change in the newer versions.

What I’m doing now is trying to get a picture from a freeCAD file using just a python script which is run from the ubuntu terminal (NOT the python console inside FreeCAD)

If I run this code I do get a image file with what I want.

Code: Select all

FREECADPATH= '/usr/lib/freecad-python3/lib'

import sys

import FreeCAD,FreeCADGui
import Part,PartGui

#doc = FreeCAD.newDocument()
doc =FreeCAD.openDocument('/path_to_file/name_file')
Gui.Selection.addSelection('name_file','Fusion') #FUsion in this case is the name of the feature which I select

box = doc.getObject("Fusion")

The problem is that when I put the code within the script where I also create the file, the program does not work (don’t have a clue why, it doesn’t give me any error)

Besides I have another problem, I was thinking in trying to do a web app, and I will upload the code to an ubuntu server (that’s why I just want to use python code). What it seems to me is that the script actually opens FreeCAD and runs the code lines next to

Code: Select all

within the python console INSIDE FreeCAD.
But I don’t know whether that is going to work in a server.

I’ve trying to use the code from this ... e=1&t=1824 , (which is a windows solution) but didn’t work for me.

Right now I’m trying to read the documentation to use coin or PySide but the docs are not that straightforward.

If someone has managed to do this I would deeply appreciated
Post Reply