Parameters not working in object loaded from file

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Son
Posts: 8
Joined: Mon May 26, 2014 4:06 am
Location: Florida, USA

Parameters not working in object loaded from file

Post by Son »

I created a parametric rectangle with the script below. It worked fine: the graphics changed as the parameters changed. I saved the rectangle to a file FCStd then opened it in a new session of FreeCAD. This time the graphics would not change as the parameters changed.

Code: Select all

import FreeCAD,Part

class ParametricRectangle:

 def __init__(self,obj):
   obj.Proxy = self
   obj.addProperty("App::PropertyFloat","Length").Length = 10.0
   obj.addProperty("App::PropertyFloat","Width").Width = 5.0

 def execute(self,obj):
   # first we need to make sure the values of Length and Width are not 0
   # otherwise the Part.Line will complain that both points are equal
   if (obj.Length == 0) or (obj.Width == 0):
     # if yes, exit this method without doing anything
     return
     
   # we create 4 points for the 4 corners
   v1 = FreeCAD.Vector(0,0,0)
   v2 = FreeCAD.Vector(obj.Length,0,0)
   v3 = FreeCAD.Vector(obj.Length,obj.Width,0)
   v4 = FreeCAD.Vector(0,obj.Width,0)
   
   # we create 4 edges
   e1 = Part.Line(v1,v2).toShape()
   e2 = Part.Line(v2,v3).toShape()
   e3 = Part.Line(v3,v4).toShape()
   e4 = Part.Line(v4,v1).toShape()
   
   # we create a wire
   w = Part.Wire([e1,e2,e3,e4])
   
   # we create a face
   f = Part.Face(w)
   
   # All shapes have a Placement too. We give our shape the value of the placement
   # set by the user. This will move/rotate the face automatically.
   f.Placement = obj.Placement
   
   # all done, we can attribute our shape to the object!
   obj.Shape = f

# MAIN SCRIPT: Create a parametric object
myObj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Rectangle")
ParametricRectangle(myObj)
myObj.ViewObject.Proxy = 0 # this is mandatory unless we code the ViewProvider too
App.ActiveDocument.recompute()
FreeCAD version:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.10460 (Git)
Build type: Release
Branch: master
Hash: 91c59c7910436c44ede608e29d9a90a287121a11
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0
Post Reply