I've made a very simple part in FreeCAD, the part label is "simple_block". My ultimate goal is to update the dimensions and export as a .stl which all works under Windows, now I need to go back to basics in Linux.
My problem is that in my embedded python script under Linux, when I try to find the part using
Code: Select all
FreeCAD.ActiveDocument.getObjectsByLabel("simple_block")
I've thought that maybe I'm not loading the FreeCAD file correctly, although
Code: Select all
print(FreeCAD.ActiveDocument.FileName)
Any clues would really help!
On Linux I install from the ubuntu repositories through apt install freecad and this installs version 0.19 along with python 3.10.
Other detaisl of my Ubuntu install:
OS: Ubuntu 22.04.1 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Python version: 3.10.2
Qt version: 5.15.2
Coin version: 4.0.0
OCC version: 7.5.1
Locale: English/Canada (en_CA)
Here is the simple code that I have in Linux which I thought should run fine since it runs on Windows!
Code: Select all
import pathlib
import sys
FREECAD_LIB_PATH = pathlib.Path("/usr/lib/freecad/lib")
# this path is updated on my Windows machine
sys.path.append(FREECAD_LIB_PATH.as_posix())
import FreeCAD
import Mesh
freecad_file = pathlib.Path().cwd() / "test_part.FCStd"
FreeCAD.open(freecad_file.as_posix())
doc = FreeCAD.ActiveDocument
# check to see if correct FreeCAD file name is returned...it is
print(doc.FileName)
# List all objects in the FreeCAD tree...none of my parts are listed in Linux but they are in Windows
for obj in doc.Objects:
print(obj.Label)
# Try to grab the part by label...this doesn't work in Linux but it does work in Windows
obj = doc.getObjectsByLabel("simple_block")
print(obj[0].Label)
I expected to see the object "simple_block" in the printout...which does work in Windows, not under Linux.Origin
X_Axis
Y_Axis
Z_Axis
XY_Plane
XZ_Plane
YZ_Plane
Sketch
Traceback (most recent call last):
File "/home/ubuntu/test.py", line 27, in <module>
print(obj[0].Label)
IndexError: list index out of range
Any guidance would be much appreciated!
obj = doc.getObjectsByLabel("simple_block")
print(obj[0].Label)