I've this simple code, exploring python-freecad capabilities:
freecad.py:
Code: Select all
# -*- coding:utf-8 -*-
FREECADPATH = '/usr/lib/freecad/lib' # path to your FreeCAD.so
import sys
sys.path.append(FREECADPATH)
import FreeCAD, FreeCADGui, Part, Draft, math, MeshPart, Mesh, Drawing
from PyQt4 import QtGui,QtCore
from FreeCAD import Base
from FreeCAD import Vector
App=FreeCAD
Gui=FreeCADGui
def main():
base_length = 800
base_width = 600
thickness = 15
name = "freecad_python_test"
App.newDocument(name)
App.setActiveDocument(name)
App.ActiveDocument.addObject("Part::Box","Test_Box")
App.ActiveDocument.Test_Box.Length=base_length
App.ActiveDocument.Test_Box.Width=base_width
App.ActiveDocument.Test_Box.Height=thickness
App.ActiveDocument.Test_Box.Placement=Base.Placement(Base.Vector(0.000,0.000,0.000),Base.Rotation(0.000,0.000,0.000,1.000))
App.ActiveDocument.Test_Box.Label='Python Generated BOX'
[b]App.ActiveDocument.Test_Box.ViewObject.Visibility=True[/b]
App.ActiveDocument.recompute()
App.ActiveDocument.saveAs("/mnt/reports/"+name+".FCStd")
print "Generating a box with lenght: " + str(base_length) + "mm and width: " + str(base_width) + "mm. Saved in /mnt/reports/"+name+".FCStd"
main()
Code: Select all
[b]App.ActiveDocument.Test_Box.ViewObject.Visibility=True[/b]
FreeCAD 0.16, Libs: 0.16R
Traceback (most recent call last):
File "freepy1.py", line 33, in <module>
main()
File "freepy1.py", line 27, in main
App.ActiveDocument.Test_Box.ViewObject.Visibility=True
AttributeError: 'NoneType' object has no attribute 'Visibility'
in FreeCAD python console the operation runs fine...
I'm using Vanilla Debian for linux and this is the log on the windows machine:
OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6712 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: da2d364457257a7a8c6fb2137cea12c45becd71a
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
PS: i'm using the old 0.16 version to match the stable FreeCAD version offered by Debian's repositories