Parametric tubes

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Perplexity
Posts: 2
Joined: Tue Sep 22, 2020 9:56 pm

Parametric tubes

Post by Perplexity »

Hi all, very new to FreeCAD; I'd like to 3D print some shapes based on parametric paths. Heres the code I'm running that's supposed to make a torus:

Code: Select all

import math
import Part

paths = []
ticks = 360.0
t = 0.0
radius = 1.0
radians = 0.0
x0 = radius
y0 = 0.0
z0 = 1.0
while radians <= 2*math.pi:
	radians = 2.0*math.pi*t/ticks
	x1 = radius * math.cos(radians)
	y1 = radius * math.sin(radians)
	z1 = 0.0
	paths.append(App.Vector(x1, y1, z1))
	x0 = x1
	y0 = y1
	z0 = z1
	t += 1.0

path = Part.BSplineCurve()
path.interpolate(paths)
torus = Part.makeTube(path, 0.1)
>> Traceback (most recent call last):
>>  File "<input>", line 1, in <module>
>> TypeError: argument 1 must be Part.Shape, not Part.BSplineCurve
Now, I know I can do this perfectly well using makeCircle, but I want to be able to change the parameters to do various kinds of 3D rosettes and such. I've also tried doing it using a series of line segments and it kind of worked, although then I didn't know how to join them resulting tubes together into one object...any thoughts on how to best approach this? I clearly don't understand how all the basic components get pieced together and converted from one type to another.
Last edited by Perplexity on Wed Sep 23, 2020 4:10 pm, edited 1 time in total.
chrisb
Veteran
Posts: 54288
Joined: Tue Mar 17, 2015 9:14 am

Re: Parametric tubes

Post by chrisb »

Please edit your post and put the code in code tags, not mono. It keeps the indentation and makes further processing easier.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Perplexity
Posts: 2
Joined: Tue Sep 22, 2020 9:56 pm

Re: Parametric tubes

Post by Perplexity »

Done.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric tubes

Post by TheMarkster »

Code: Select all

Part.makeTube(path.toShape(),0.1)
User avatar
matyk
Posts: 111
Joined: Thu Feb 15, 2018 2:37 pm

Re: Parametric tubes

Post by matyk »

I use 3D_Parametric_Curve.FCMacro

Closed loop for the parameter range: 0 < t < 4*2π
Attachments
1.jpg
1.jpg (99.13 KiB) Viewed 762 times
Post Reply