coil spring

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

Post by kwahooo »

Time to refresh topic! :)

Today I generated customizable spring model.
Image

Diameter, height, pitch and bar (rod? Im unsure which is correct in English) diameter can be changed in Property view. Script (fuse of many code snippets from forum:) is here:

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=30.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

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

if __name__ == "__main__":
	makeMySpring()
Two things:
1. List of one element looks funny section = Part.Wire([p]) but I don't know how make this without list. makePipeShell accept only lists...
2. I should use 4 spaces instead tabs. Sorry.
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 »

Great work! :)
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Show your FreeCAD projects here!

Post by jmaustpc »

Hi Kwahoo

it great! :)

You have also just shown up a bug in FreeCAD! :shock:

The start and finish points of the helix should end up directly above each other for a helix with a height of an integer multiple of its pitch. In other words, if you start at a point and go around one full circle, back to where you started, following a helix, you should end up higher by exactly one pitch.

There is a calculation error, not in your Python script, but in the source code which your python script references. This is a bug that was in the C++ code and showed up when accessed via Part workbench, I am surprised it is there again.

I will sort it out and post it to the forum under a different subject once I have done so.


Hi norm,

did it produce the spring for you? I had to adjust a parameter to get it to display something. However I had problems with extra indents being inserted from copying and pasting the code of sourceforge, so that might be why it did not initially auto generate for me.

Jim
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 »

Hi,

I haven't tried kwahoo's script yet. Apart from skimming the forum, I'm kind of taking a FreeCAD break tonight. I spent a good part of my weekend working on the French translation on Crowdin, and well I need a break! ;)

Which only makes me wonder again at the relentless dedication of Jürgen, Werner, Yorik and the others.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Show your FreeCAD projects here!

Post by jmaustpc »

normandc wrote:Hi,

I haven't tried kwahoo's script yet. Apart from skimming the forum, I'm kind of taking a FreeCAD break tonight. I spent a good part of my weekend working on the French translation on Crowdin, and well I need a break! ;)

Which only makes me wonder again at the relentless dedication of Jürgen, Werner, Yorik and the others.
Although what you say of the others is definitely correct and without in anyway belittling their contribution, I have to say in defence of you, that in some ways all that translating stuff is the hardest, certainly in terms of getting motivated to do it. Think of this, how hard are you to replace? You understand both languages really well, you're an advanced experienced user of CAD, so you know what you're writing about and on top of all that you are prepared to get in and do the work.

Even if you were all of the above but not an experience CAD user, you would be so much less valuable. We would then end up with the typical translations you used to get in cheap Chinese instruction sheets. For example without someone like you we would probably get the French equivalent of "manufacture of a usually circular cross sectional device for the subterranean containment and directional flow control of flowing liquids and gasses" Rather than "makePipe"!


sleep well.

Jim
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 »

LOL, believe me, sometimes a correct French translation for a two or three-word technical expression in English will be almost as long :D

I'm happy to do this work, as it's still not much compared to the tireless hours the guys have given. I'm doing this for me too, I like to have a fully translated CAD app. Even if I read English fine, I still prefer my tools in my native language. I just wish there were more French-speaking people here on the forum (there is maybe half a dozen who visit). Maybe if I start updating my blog again, and build a readership, I'll be able to bring more people into the fold. :)
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Show your FreeCAD projects here!

Post by jmaustpc »

Hi all
Helix problem from Python command line.

OK I have found the problem in the code, but there are two ways to fix it, so I will start another topic on the bug, and see what the developers want to do.

Jim

see new topic here: -

viewtopic.php?f=10&t=1908
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:Time to refresh topic! :)

Today I generated customizable spring model.
Image

Diameter, height, pitch and bar (rod? Im unsure which is correct in English) diameter can be changed in Property view. Script (fuse of many code snippets from forum:) is here:

Two things:
1. List of one element looks funny section = Part.Wire([p]) but I don't know how make this without list. makePipeShell accept only lists...
2. I should use 4 spaces instead tabs. Sorry.

Hi again Kwahooo
Werner has fixed the problem with helix creation, a few minutes ago . If you are compiling from source then it is up now, in SVN5144.

I've just compiled 5144, and tested a script with a helix posted by someone else and, (of course since Werner did it), it works. :)

On the rod bar thing, off the top of my head I would say a rod is round, a bar can be round but also "Flat bar, square bar, hex bar," ...... and then of course their is the other type of "bar" at which one buys alcoholic drinks! :shock:

Oh yeah and the other type of Rod, .... a singer from the 1980s (or was it the 70's?) "Rod Stewart", I should add he is still alive!

Jim
Post Reply