Hi,
until now, BOLTS needed a python function for every entry in the library, that set up the geometry. But as this is annoying in many cases, and python scripting is not for everybody, I work on loading parts from a fcstd file. To load a part from a fcstd file, I use code like this
Code: Select all
· · import FreeCAD
· · newdoc = FreeCAD.openDocument(self.filename)
· · obj = newdoc.getObjectsByLabel(self.objectlabel)
· · if len(obj) != 1:
· · · raise MalformedBaseError("No file %s found" % self.filename)
· · doc.copyObject(obj[0])
· · FreeCAD.setActiveDocument(doc.Name)
· · FreeCAD.closeDocument(newdoc.Name)
With this I have run into a couple of difficulties:
1) It is more a cosmetic issue, and I do not care too much about it: everything flickers when I load a file from fcstd, because when a new document is opened, the Gui automatically switches to it. Is there a way to circumvent the Gui and load the file in a document, that is not visible?
I also want to have the possibility to change parameters in the loaded part. For development I use aluminium extrusions as a test case and try to change its length:
2) I can load a Pad of the crosssection from the fcstd file with the code above, but when I want to change the Length property, I get the error "No sketch linked", and indeed, the Sketch that is present when I load the file manually is absent when using the code above.
3)When I load the File manually, the sketch is there, and I can change the length of the Pad manually in the ComboView, and the 3D View updates, just like expected. When doing that, the Python console says something like
Code: Select all
FreeCAD.getDocument("tube_rectangular_v000").getObject("Pad").Length = 200.00
But typing this in the Python Console only updates the value in the Combo View, not the 3D view.
4) I do not want to be restricted to Pads and its Lengths, so the property that is to be changed should be passed to the load function as a parameter. If Length were a simple member of the <Part::PartFeature>, I would expect something like this to work:
Code: Select all
FreeCAD.getDocument("tube_rectangular_v000").getObject("Pad").__dict__["Length"] = 200.0
but it doesn't. Then I thought I might use
Code: Select all
FreeCAD.getDocument("tube_rectangular_v000").getObject("Pad").__setattr__("Length",200.0)
but then I get a "TypeError: can't apply this __setattr__ to Part.Feature object"
Is there a nice possibility to access the properties of a Part.Feature with the name of the property as a string, or do I have to resort to something like
Code: Select all
if property == "Length":
part.Length = value
elif property == "Length2":
part.Length2 = value
elif ...
I would be very happy, if someone help me with or point me to useful literature about one or several of these. This was done on
OS: Ubuntu 13.04
Platform: 64-bit
Version: 0.13.1830 (Git)
Branch: releases/FreeCAD-0-13
Hash: ec7636d7aaf2612e9b43cff5d6a424037d53e505
Python version: 2.7.4
Qt version: 4.8.4
Coin version: 3.1.3
SoQt version: 1.5.0
OCC version: 6.5.0
Greetings
Johannes