Parametric Curve FP discussion board

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board

Post by TheMarkster »

edwilliams16 wrote: Fri Mar 11, 2022 1:25 am I must be missing something because I can't make this work at all. If I have a file with nothing but a Part.Cylinder, in the Python Console I get

Code: Select all

>>> App.DocumentObject.evalExpression(Cylinder.Height)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'Cylinder' is not defined
>>> App.DocumentObject.evalExpression(<<Cylinder>>.Height)
  File "<input>", line 1
    App.DocumentObject.evalExpression(<<Cylinder>>.Height)
                                      ^
SyntaxError: invalid syntax
>>> 
I had tested only with a dd object and its float property. It looks like fc(expr) struggles with units, such 10 mm. I'll see if I can fix it.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board

Post by TheMarkster »

Add .Value to the end of line 292.

Code: Select all

#        evaluated = FreeCAD.ActiveDocument.ActiveObject.evalExpression(fc_Eval).Value
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board

Post by TheMarkster »

New version: 2022.03.10.rev5

fix bug in fc(expr) so it handles unit quantities

Note: fc(expr) will always return a unitless value. For example, if fc(Cylinder.Height) is used and the height is 10 mm, the return value is 10.0.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board

Post by TheMarkster »

New version:

2022.03.10.rev6

After deleting formula from list, select the next item in the list instead of the first item. This way it is easier to delete multiple items.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board

Post by TheMarkster »

New version 0.2022.03.11

Fixed a bug in fc(expr) where now it wasn't handling well unitless expressions.
Nested fc(fc(expr)) is not supported, so check for that and report the error.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board (latest: 0.2022.03.09)

Post by TheMarkster »

edwilliams16 wrote: Thu Mar 10, 2022 9:56 am Screen Shot 2022-03-09 at 11.51.49 PM.pngScreen Shot 2022-03-09 at 11.53.16 PM.png

Easy enough to rotate - but I think would be better done by playing with the attachment, which is likely going to be used anyway. Could also change the input angle to dgrees?
math.degrees and math.radians are both supported.

For example, sin(radians(30)) = sin(pi/6). Speaking just for me, I find angles in degrees are more intuitive than radians.

>>>
>>> from Parametric_Curve_FP import evaluate
>>> evaluate("sin(pi/6)")
0.49999999999999994
>>> evaluate("sin(radians(30))")
0.49999999999999994
>>> evaluate("degrees(pi/6)")
29.999999999999996
>>>

I have noticed also there is some trouble occasionally with the Part::Helix primitive due to its segmented structure, particularly when it comes to rendering sweeps along such helices. It could be useful to have a helix formula that also allows for angles.
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric Curve FP discussion board

Post by edwilliams16 »

Screen Shot 2022-03-12 at 2.38.53 PM.png
Screen Shot 2022-03-12 at 2.38.53 PM.png (15.46 KiB) Viewed 3212 times

Code: Select all

{"helix": {"a": "1  #pitch", "b": "5 #height", "c": "1 #base radius", "d": ["20 #angle deg", "1  # 1= RH  0 = LH", "t*b/a", "a + b*t*sin(rad(d1))/(2*pi)", "ternary(d2, 1, -1)"], "X": "d4*cos(d3*d5)", "Y": "d4*sin(d3*d5)", "Z": "b*t/(2*pi)", "t_min": "0", "t_max": "2*pi", "interval": "0.01"}}
I didn't do any Placement - it would make the interface a lot more complicated - but I could..
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric Curve FP discussion board

Post by edwilliams16 »

I got Part|Sweep to work nicely with the above helix - but I couldn't get Part Design|Additive Pipe to sweep a circle properly. It could be I'm not doing it right...
Screen Shot 2022-03-12 at 3.43.37 PM.png
Screen Shot 2022-03-12 at 3.43.37 PM.png (42.64 KiB) Viewed 3178 times
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric Curve FP discussion board

Post by edwilliams16 »

The problem was my helix parametric curve had much too fine a resolution. Reducing interval to 0.1 Part design works fine.
Screen Shot 2022-03-12 at 4.06.45 PM.png
Screen Shot 2022-03-12 at 4.06.45 PM.png (41.87 KiB) Viewed 3152 times
Use this:

Code: Select all

{"helix": {"a": "1  #pitch", "b": "5 #height", "c": "1 #base radius", "d": ["20 #angle deg", "1  # 1= RH  0 = LH", "t*b/a", "a + b*t*sin(rad(d1))/(2*pi)", "ternary(d2, 1, -1)"], "X": "d4*cos(d3*d5)", "Y": "d4*sin(d3*d5)", "Z": "b*t/(2*pi)", "t_min": "0", "t_max": "2*pi", "interval": "0.1"}}
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board

Post by TheMarkster »

That looks great. I'll add it and the other modification of the angled ellipse to the default set of formulas for the next update.

Edit: Can you post the full formula for the angled ellipse?
Post Reply