Spring.py
Go to the documentation of this file.00001
00002
00003
00004
00005 from __future__ import division
00006 import FreeCAD, Part
00007 from FreeCAD import Base
00008
00009 class MySpring:
00010 def __init__(self, obj):
00011 ''' Add the properties: Pitch, Diameter, Height, BarDiameter '''
00012 obj.addProperty("App::PropertyLength","Pitch","MySpring","Pitch of the helix").Pitch=5.0
00013 obj.addProperty("App::PropertyLength","Diameter","MySpring","Diameter of the helix").Diameter=6.0
00014 obj.addProperty("App::PropertyLength","Height","MySpring","Height of the helix").Height=30.0
00015 obj.addProperty("App::PropertyLength","BarDiameter","MySpring","Diameter of the bar").BarDiameter=3.0
00016 obj.Proxy = self
00017
00018 def onChanged(self, fp, prop):
00019 if prop == "Pitch" or prop == "Diameter" or prop == "Height" or prop == "BarDiameter":
00020 self.execute(fp)
00021
00022 def execute(self, fp):
00023 pitch = fp.Pitch
00024 radius = fp.Diameter/2
00025 height = fp.Height
00026 barradius = fp.BarDiameter/2
00027 myhelix=Part.makeHelix(pitch,height,radius)
00028 g=myhelix.Edges[0].Curve
00029 c=Part.Circle()
00030 c.Center=g.value(0)
00031 c.Axis=(0,1,0)
00032 c.Radius=barradius
00033 p=c.toShape()
00034 section = Part.Wire([p])
00035 makeSolid=1
00036 isFrenet=1
00037 myspring=Part.Wire(myhelix).makePipeShell([section],makeSolid,isFrenet)
00038 fp.Shape = myspring
00039
00040 def makeMySpring():
00041 doc = FreeCAD.activeDocument()
00042 if doc == None:
00043 doc = FreeCAD.newDocument()
00044 spring=doc.addObject("Part::FeaturePython","My_Spring")
00045 spring.Label = "My Spring"
00046 MySpring(spring)
00047 spring.ViewObject.Proxy=0
00048 doc.recompute()
00049
00050 if __name__ == "__main__":
00051 makeMySpring()