coil spring and helix

Show off your FreeCAD projects here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
kwahooo
Posts: 204
Joined: Wed May 19, 2010 11:11 pm
Contact:

coil spring and helix

Post by kwahooo »

Werner added into PartDesing/Scripts Spring and Epitrochoid examples I see...
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Show your FreeCAD projects here!

Post by jmaustpc »

kwahooo wrote:Werner added into PartDesing/Scripts Spring and Epitrochoid examples I see...
I just checked it out (as in both svn and literally :D ) and they are cool 8-)

Jim
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Show your FreeCAD projects here!

Post by jmaustpc »

Full credit to the Kwahooo spring, this is an example of how easy it is to extend/modify something after someone has done all the hard work of creating the first version.

I have made a loop of pipe by creating two springs and subtracting one from the other.

Jim

A jpeg, just delete ".notreallyzipped.zip"....
pipe helix bend.jpeg.notreallyzipped.zip
(23.7 KiB) Downloaded 484 times

Code: Select all

from __future__ import division # allows floating point division from integers
import FreeCAD, Part
from FreeCAD import Base

class MySpring:
   def __init__(self, obj):
      ''' Add the properties: Pitch, Diameter, Height, BarDiameter '''
      obj.addProperty("App::PropertyLength","Pitch","MySpring","Pitch of the helix").Pitch=5.0
      obj.addProperty("App::PropertyLength","Diameter","MySpring","Diameter of the helix").Diameter=6.0
      obj.addProperty("App::PropertyLength","Height","MySpring","Height of the helix").Height=5.0
      obj.addProperty("App::PropertyLength","BarDiameter","MySpring","Diameter of the bar").BarDiameter=3.0
      obj.Proxy = self

   def onChanged(self, fp, prop):
      if prop == "Pitch" or prop == "Diameter" or prop == "Height" or prop == "BarDiameter":
         self.execute(fp)

   def execute(self, fp):
      pitch = fp.Pitch
      radius = fp.Diameter/2
      height = fp.Height
      barradius = fp.BarDiameter/2
      myhelix=Part.makeHelix(pitch,height,radius)
      g=myhelix.Edges[0].Curve
      c=Part.Circle()
      c.Center=g.value(0) # start point of the helix
      c.Axis=(0,1,0)
      c.Radius=barradius
      p=c.toShape()
      section = Part.Wire([p])
      makeSolid=1 #change to 1 to make a solid
      isFrenet=1
      myspring=Part.Wire(myhelix).makePipeShell([section],makeSolid,isFrenet)
      fp.Shape = myspring

class MySpringid:
   def __init__(self, obj):
      ''' Add the properties: Pitch, Diameter, Height, BarDiameter '''
      obj.addProperty("App::PropertyLength","Pitch","MySpringid","Pitch of the helix").Pitch=5.0
      obj.addProperty("App::PropertyLength","Diameter","MySpringid","Diameter of the helix").Diameter=6.0
      obj.addProperty("App::PropertyLength","Height","MySpringid","Height of the helix").Height=5.0
      obj.addProperty("App::PropertyLength","BarBore","MySpringid","Bore of the bar").BarBore=2.0
      obj.Proxy = self

   def onChanged(self, fpid, prop):
      if prop == "Pitch" or prop == "Diameter" or prop == "Height" or prop == "BarBore":
         self.execute(fp)

   def execute(self, fpid):
      pitch = fpid.Pitch
      radius = fpid.Diameter/2
      height = fpid.Height
      barboreradius = fpid.BarBore/2
      myhelix=Part.makeHelix(pitch,height,radius)
      g=myhelix.Edges[0].Curve
      cid=Part.Circle()
      cid.Center=g.value(0) # start point of the helix
      cid.Axis=(0,1,0)
      cid.Radius=barboreradius
      pid=cid.toShape()
      sectionid = Part.Wire([pid])
      makeSolid=1 #change to 1 to make a solid
      isFrenet=1
      myspringid=Part.Wire(myhelix).makePipeShell([sectionid],makeSolid,isFrenet)
      fpid.Shape = myspringid

def makeMySpring():
    doc = FreeCAD.activeDocument()
    if doc == None:
     doc = FreeCAD.newDocument()
    spring=doc.addObject("Part::FeaturePython","My_Spring")
    spring.Label = "My Spring"
    MySpring(spring)
    spring.ViewObject.Proxy=0

def makeMySpringid():
    doc = FreeCAD.activeDocument()
    if doc == None:
     doc = FreeCAD.newDocument()
    springid=doc.addObject("Part::FeaturePython","My_Springid")
    springid.Label = "My Springid"
    MySpringid(springid)
    springid.ViewObject.Proxy=0

if __name__ == "__main__":
   makeMySpring()

if __name__ == "__main__":
   makeMySpringid()

#App.ActiveDocument.recompute()

App.activeDocument().addObject("Part::Cut","Cut")
App.activeDocument().Cut.Base = App.activeDocument().My_Spring
App.activeDocument().Cut.Tool = App.activeDocument().My_Springid
Gui.activeDocument().hide('My_Spring')
Gui.activeDocument().hide('My_Springid')
Gui.activeDocument().Cut.ShapeColor = Gui.activeDocument().My_Spring.ShapeColor
App.ActiveDocument.recompute()

User avatar
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Show your FreeCAD projects here!

Post by yorik »

the kwahoo spring will become famous in history, a bit like the pythagore theorem or the columbus egg... Generations of students will study it and try to reproduce :)
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Show your FreeCAD projects here!

Post by NormandC »

casper-nilsson wrote:Sure its ok to use them, but reupload it to sourceforge, since its a dropbox link, you never know how long it will be in my folder.
Thanks, I added the aeroponics screenshot to the wiki. I forgot to give you credits in the file's comments though, sorry for that. :oops:

On what distro are you and what theme/mod do you use? The wheel with bearing screenshot you posted on Wikimedia has me intrigued, with the tabs at the top of the screen!

I have to say your screenshots all look amazing. You have an eye for presentation/render. :)

Thanks for the color gradient, I'll try it out.
Hallu
Posts: 5
Joined: Tue Apr 08, 2014 9:40 am

Re: coil spring and helix

Post by Hallu »

Hi,
I'm trying to use this script to do some coil springs. However, it isn't perfect. When you decrease the pitch, some surfaces are missing (try 2 mm for example), and below 5 mm, it never starts with a vertical circular cross section, instead the half top part of the starting point is missing. Is there a newer more refined script for coil springs ? Thanks.
Hallu
Posts: 5
Joined: Tue Apr 08, 2014 9:40 am

Re: coil spring and helix

Post by Hallu »

Nevermind, I found my mistake, didn't realize it was a substraction of the 2.
Post Reply