Need help modeling a spring with makePipe and GUI shapes

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Need help modeling a spring with makePipe and GUI shapes

Post by NormandC »

Hello guys,

I've been trying python scripting again. I wanted to use the makePipe function to create a spring. In the console, using snippets of code found here and there, here's what I've come up with:

Code: Select all

import Part, FreeCAD, math
from FreeCAD import Base
helix=Part.makeHelix(1,10,3)
circle = Part.makeCircle(0.35,Base.Vector(3,0,0),Base.Vector(0,1,0))
circle = Part.Wire([circle])
pipe = Part.Wire(helix).makePipe(circle)
Part.show(pipe)
And it works (it generates a tubular surface, not a solid, but that's another matter).
fcspring.jpg
fcspring.jpg (22.2 KiB) Viewed 6386 times
But I find geometry creation through the console tedious. I'd much rather draw my 2D elements with the GUI tools, then run a script on them.

So I created an Helix object with the "Primitives > Create primitives" Part menu, then a Draft Circle for my section.

To register them in the console, I did this:

Code: Select all

myCircle=App.ActiveDocument.getObject("Circle")
myHelix=App.ActiveDocument.getObject("Helix")
But next I go with the pipe command, and I get this:
>>> pipe = Part.Wire(myHelix).makePipe(myCircle)
Traceback (most recent call last):
File "<input>", line 1, in <module>
Exception: edge or wire or list of edges and wires expected
So OK, I guess I need to extract the wire out of the circle. I do this:
>>> section=Part.Wire([myCircle])
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: item is not a shape
So now I'm stumped.

It would help if I could understand any of this. I'm not sure my brain is wired for it. :cry:
Last edited by NormandC on Tue Oct 04, 2011 11:15 pm, edited 1 time in total.
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to model a spring with makePipe and GUI shapes

Post by NormandC »

One thing though: the section of the resulting spring is not truely circular, because the circle was drawn on the XZ plane, and the start of the helix is not normal to that.

Is there a way to get the normal plane to a Wire end through the console?
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to model a spring with makePipe and GUI shapes

Post by NormandC »

I was thinking this could be used to generate a screw thread. The section would be a trapezoid instead of a circle. You make it solid, then boolean substract it from a 6mm dia cylinder, and voilà, you've got your screw thread. (as was suggested here)

Unfortunately this is the unexpected result:
fc_thread_rotatingsection.jpg
fc_thread_rotatingsection.jpg (37.32 KiB) Viewed 6385 times
You'll notice that the section seems to twist along the helix. Is this supposed to do that?!? Is it because the section plane is not normal to the starting point of the helix?

Here's the script to get this:

Code: Select all

import Part, FreeCAD, math
from FreeCAD import Base

helix = Part.makeHelix(1,10,3)
edge1 = Part.makeLine((2.5,0,-0.125), (2.5,0,0.125))
edge2 = Part.makeLine((2.5,0,0.125), (3.1,0,0.419))
edge3 = Part.makeLine((3.1,0,0.419), (3.1,0,-0.419))
edge4 = Part.makeLine((3.1,0,-0.419), (2.5,0,-0.125))
section = Part.Wire([edge1,edge2,edge3,edge4])
pipe = Part.Wire(helix).makePipe(section)
Part.show(pipe)
In the CAD packages I've worked with, when doing a sweep (which the makePipe function is), you can control how the section should be swept: normal to the trajectory (or wire, which here is the helix), parallel to the section plane (not what we want in this case), but I've never seen a section twist along the trajectory like that.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: How to model a spring with makePipe and GUI shapes

Post by jmaustpc »

Hi Norm

WOW. :)

I have been wanting to do the same thing, but I have give up for a bit while I do some more coding, if I can work out a few more things I will have some more features graphically for you.

By the way try this, create some shapes, then use the part create primitives, then click on the 3d view button, then click on a part of one of your items (not the empty desktop, if you do you then have to click d3 view again) and it will set the position to where you clicked on you pre-existing part. Then click create and it attaches to where you clicked.

I had the thought of calculating the angle of the helix, you need two 180 deg. rotation z-axis. I made a Libre Office Calc spread sheet to calculate this and made two planes. Was thinking it might work to make the thread it in two halves split down the z-axis. Anyway I'll post it here in case it give you any ideas. I'll be back on line in 3 days. I had to delete most of it as the file was too big, but you will see the planes, I was wondering if a half circle on each of these plains would make a helix???

Anyway I have to bolt, off for 3 days with kids, school holidays.

Jim
Attachments
threadexperiments4.fcstd.notreallyzipped.zip
(132.88 KiB) Downloaded 148 times
calculationsofhelixdiameterandplaneangles1.ods.notreallyzipped.zip
(10.54 KiB) Downloaded 149 times
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: How to model a spring with makePipe and GUI shapes

Post by NormandC »

Hi,

This is my lunch hour at work, I just replicated the thread in Solid Edge. Although in SE there is no need to create an helix wire first, since the Helical protrusion command does it automatically.

This is what I expected in FreeCAD.

P.S. Thanks Jim, I hope you have fun in your holiday!
Attachments
Helical protrusion in Solid Edge
Helical protrusion in Solid Edge
M6 thread helix.jpg (38.51 KiB) Viewed 6357 times
jmaustpcp1

Re: How to model a spring with makePipe and GUI shapes

Post by jmaustpcp1 »

normandc wrote:One thing though: the section of the resulting spring is not truely circular, because the circle was drawn on the XZ plane, and the start of the helix is not normal to that.
2
Is there a way to get the normal plane to a Wire end through the console?
Hi Norm, (from my Mum's PC) :D

What if you rotate the circle at the beginning to the appropriate angle for the pitch based on the result of the calculations in that spreadsheet I posted the other day?

Also did you try making the circle from Part Workbench then part menu create primitives? I added circle to the dialogue a few days ago, it is in svn. I am working on adding polygons to this dialogue as well, made some progress before I went away. When finished polygon can be used to create a polygon from 3 sides, triangle, upwards.

Anyway I must away, things to pack, and just short of 300km to drive, but I'll be home in a few hours. :)

Jim
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Need help modeling a spring with makePipe and GUI shapes

Post by NormandC »

Hi Jim,

I did try rotating the circle, although I did it approximately. The result is about the same. I concluded it is unrelated to the twisting (although still needed to get a correct thread). BTW I reported a bug about this: https://sourceforge.net/apps/mantisbt/f ... php?id=444

I saw your addition to the Primitives menu, and tried it. Nice work! Unfortunately, as I said in my first post, I have no idea how to use the makePipe function out of elements that I've created through the GUI.

So you're getting back from your holiday? They always go by too fast don't they? Have a safe trip back! :)
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Need help modeling a spring with makePipe and GUI shapes

Post by jmaustpc »

Hi Norm
I'm back. Very happy to be home. If you have to live in a city, Sydney is pretty good really, but if you are just a country boy at heart then getting out of the city and back to the bush is a great relief.

I started trying to work out how to put the two different pipe functions into the gui. I didn't want to commit to doing the stuff I am trying to do because I am so new to coding and I have a lot to learn, I may not be capable of achieving my goals yet, although I think I can now, I am very, ......, very, slow. I am learning heaps but I don't want to be a burden on the "proper FreeCAD coders". I mean that I don't think its appropriate for me to get them to help me learn to code in general sense, unless its a FreeCAD specific thing. Having said that the other day I had 90% of the work completed on something but I was stuck on something, (that in the end turned out to be really basic simple thing that was really quite obvious), I had been going around in circles and I started thinking it might be a bug in QT. I decided that whatever the case, it would be a net gain to FreeCAD for me to post what I had done, so just gave up and posted my work in a not quite complete state. I don't want to make a habit of doing so.

Anyway in general what I am currently doing is just working my way through Part source code, looking to put the things in there which are not in the gui already, into the gui. So hopefully I will have some nice surprises for you soon.

Jim
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Need help modeling a spring with makePipe and GUI shapes

Post by NormandC »

Hi Jim,

That's nice to hear! I was very happy when the guys started planning the 0.13 branch and talked about adding more tools to PartDesign. I've a lot of trouble with understanding how Python works. The appending of functions one before the other in reverse order (from what I understand) confuses the hell out of my sorry brain. The last time I was ever near programming was with BASIC 25 years ago when I was a teenager. I programmed a Space Invaders game with ASCII characters and what I called a "car generator" that drew a car profile based on some parameters. There were only lines though, no arcs because there was no such function in ATARI BASIC! After that I decided that I wanted to use apps on a computer, not program them, and that was that.

So anyway, about the bug I posted, well Werner already closed it! He made the change in svn4991. The PPA package is currently building so I'll give it a shot tomorrow night.

Oh and he changed the code to this:
wmayer wrote:The code must be changed to:

Code: Select all

import Part, FreeCAD, math
from FreeCAD import Base

helix = Part.makeHelix(1,10,3)
edge1 = Part.makeLine((2.5,0,-0.125), (2.5,0,0.125))
edge2 = Part.makeLine((2.5,0,0.125), (3.1,0,0.419))
edge3 = Part.makeLine((3.1,0,0.419), (3.1,0,-0.419))
edge4 = Part.makeLine((3.1,0,-0.419), (2.5,0,-0.125))
section = Part.Wire([edge1,edge2,edge3,edge4])
makeSolid=0
isFrenet=1
pipe = Part.Wire(helix).makePipeShell([section],makeSolid,isFrenet)
Part.show(pipe)
So he's using makePipeShell instead of makePipe, and look at that variable makeSolid, what happens when you set it to 1 you think? ;)

The isFrenet variable is new I guess, keeping it in the script with my current copy of FreeCAD produces nothing. Removing it and setting makeSolid=1, I get a solid. :) (it takes a few seconds to process the script and generate the shape)

The screw thread capability may finally be within our reach now! :D (although for now when I create a cylinder and cut it with the solid helical thread thingy, it results in a bunch of failed surfaces)
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Need help modeling a spring with makePipe and GUI shapes

Post by jmaustpc »

G'day Norm

this is a WWW!

(Wow!!Way-to-go, Werner!!!)

I had 4991 already compiled so I thought I would give it a go. (Really nice Werner.)

Norm I am getting stuck on some of the coding again, I might end up having to give up again and ask another silly question. We will see. :oops:

It was interesting to see your comments on BASIC. I to wrote space invader in basic. In my case in it was early 1980s on a Sinclare ZX80 upgraded to an 81(but this means it could only work in "fast mode" unlike a real zx81, I also had a MASSIVE memory upgrade wait for it ........ I had a 16K!!!! external memory module. I spent a whole day trying to write the space Invaders, got it to largely work, except my destroyed aliens kept coming back, and then I bumped the computer thus lost everything!!!! :twisted: the audio backup tape was useless. Fast mode means it can not think and display at the same time, so every second or third line or whatever, you had say "pause xx seconds" or whatever it was. After that experience I don't think I ever bothered with that computer again.

Jim
screw spirol with Werners fix.jpeg
screw spirol with Werners fix.jpeg (169.85 KiB) Viewed 6287 times
Post Reply