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: 5513
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 3:15 am Minor nitpick - if c is the eccentricity of the ellipse, you have the wrong formula for its minor radius.
Thanks. I've fixed it for the next update. How might we also provide a rotation angle (about the z axis)?
edwilliams16
Veteran
Posts: 3179
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Post by edwilliams16 »

Screen Shot 2022-03-09 at 11.51.49 PM.png
Screen Shot 2022-03-09 at 11.51.49 PM.png (12.01 KiB) Viewed 4674 times
Screen Shot 2022-03-09 at 11.53.16 PM.png
Screen Shot 2022-03-09 at 11.53.16 PM.png (27.32 KiB) Viewed 4674 times
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?
User avatar
hammax
Veteran
Posts: 1991
Joined: Thu Jan 19, 2017 5:03 pm
Location: Ammersee DE

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

Post by hammax »

... testing the abilities of ParaCurve at known examples, like great circle for a winding pattern,
I have problems to make up a second curve (here a helix), getting it not to execute => some file or fxx problem???
I tried to reproduce a winding pattern for CFR-composite for a high pressure vessel =>
https://www.ke-next.de/files/upload/pos ... ooster.jpg
Edit: Helix solved with an earlier version of ParaCurve.

ParaCurve_3.PNG
ParaCurve_3.PNG (96.07 KiB) Viewed 4640 times
Attachments
ParCurve_GreatCircle_3.FCStd
FC.19.4
(246.62 KiB) Downloaded 60 times
ParCurve_GreatCircle_2.FCStd
FC.19.4
(74.55 KiB) Downloaded 65 times
Last edited by hammax on Fri Mar 11, 2022 7:47 am, edited 2 times in total.
edwilliams16
Veteran
Posts: 3179
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Post by edwilliams16 »

I'm having problems with the 03.22.10 version. If I start a new file, run the macro, double-click to edit, then click apply, I get the following error:

Code: Select all

08:50:56  Traceback (most recent call last):
  File "/Users/ed/Library/Preferences/FreeCAD/Macro/Parametric_Curve_FP.py", line 1381, in clicked
    if hasattr(fp,"Sorted"):
<class 'NameError'>: name 'fp' is not defined
If I change formula or edit one, I get the same error. I can open files with existing curves.

OS: macOS High Sierra (10.13)
Word size of FreeCAD: 64-bit
Version: 0.20.27809 (Git)
Build type: Release
Python 3.9.10, Qt 5.12.9, Coin 4.0.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods:
* Curves 0.3.0
* DynamicData 2.32.0
* fcgear
* lattice2
* MeshRemodel 1.8918.0
* toSketch
TheMarkster
Veteran
Posts: 5513
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 6:59 pm I'm having problems with the 03.22.10 version. If I start a new file, run the macro, double-click to edit, then click apply, I get the following error:

Code: Select all

08:50:56  Traceback (most recent call last):
  File "/Users/ed/Library/Preferences/FreeCAD/Macro/Parametric_Curve_FP.py", line 1381, in clicked
    if hasattr(fp,"Sorted"):
<class 'NameError'>: name 'fp' is not defined
If I change formula or edit one, I get the same error. I can open files with existing curves.

OS: macOS High Sierra (10.13)
Word size of FreeCAD: 64-bit
Version: 0.20.27809 (Git)
Build type: Release
Python 3.9.10, Qt 5.12.9, Coin 4.0.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods:
* Curves 0.3.0
* DynamicData 2.32.0
* fcgear
* lattice2
* MeshRemodel 1.8918.0
* toSketch
Easy to fix. Instead of fp it should have been self.fp in lines 1382 and 1383. I have added it to the next update, but you can apply the changes yourself in the meantime if you like. You will need to delete Parametric_FP.py so it gets rebuilt after applying the changes, and then restart.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

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

Post by TheMarkster »

hammax wrote: Thu Mar 10, 2022 11:37 am ... testing the abilities of ParaCurve at known examples, like great circle for a winding pattern,
I have problems to make up a second curve (here a helix), getting it not to execute => some file or fxx problem???
I tried to reproduce a winding pattern for CFR-composite for a high pressure vessel => https://www.bing.com/images/search?
Thanks for testing. I think I have found the problem. Be sure to open the report view and watch for error messages if things are not working. These can aid in troubleshooting. I have added some additional warning messages. These I might convert to log messages in the future if they prove to be too annoying.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

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

Post by TheMarkster »

Latest version 2022.03.10.rev2

Bug fixes
Check for compatibility with editor in case object was created with older version
Add some warning messages when unable to create shape, might be later changed to log messages if these prove to be too annoying.
Rename editor window title from Edit formulas to Formula editor, with version information.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board

Post by TheMarkster »

Latest version 0.2022.03.10.rev3

Adds new function fc(expr)

Usage:

fc(expr) is evaluated using FreeCAD's expression engine.

Pseudo code for its implementation:

fc(expr): FreeCAD.DocumentObject.evalExpression(expr)

Some examples:

a = fc(Cylinder.Height)

Presuming there is an object in the document named Cylinder, this would set a to the Cylinder's Height property. Caveat: this is not parametric. That is, when Cylinder's Height property changes, the ParametricCurve object is not automatically recomputed, like you might expect it to be. You would need to manually recompute the ParametricCurve object to use the new Cylinder.Height property value.

To mitigate this I have added a new property called "Dependencies" in the Curve section. You can add the Cylinder to the Dependencies property (App::PropertyLinkList) to create this dependency manually. Then from now on when Cylinder recomputes, the ParametricCurve object will also recompute. In a way this little quirk can be good because it can help to avoid cyclic redundancies in some situations.

It should be possible to use any valid expression with fc(expr). Let me know if there is an expression that fails, but works when entering into the python console:

Code: Select all

FreeCAD.DocumentObject.evalExpression(expr)
Note: You can use this for any of the string variables in a formula: a, b, c, d1, d2, dN, X, Y, and Z and it will recompute when you manually recompute, but for the float properties: t_min, interval, and t_max you should use the expression engine directly instead since these are floating point properties, with good support for this. You can use fc(expr) in the JSON formulas for these float properties, too, but they will be converted to float constants and will not be re-evaluated on recompute.

From a performance standpoint it appears fc(expr) works just as fast as using the normal evaulate() function, at least it does in my initial test. It could be recompute times will be slower in some cases, or possibly faster, but in my rudimentary testing they were roughly the same. In my test I compared recompute times when using a = 20 and a = fc(20). Of course, adding dependencies might cause some unnecessary recomputes of the ParametricCurve object, slowing down recompute times for the document as a whole.
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Parametric Curve FP discussion board

Post by TheMarkster »

New version: 0.2022.03.10.rev4

bug fix (reset button in dialog)
edwilliams16
Veteran
Posts: 3179
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric Curve FP discussion board

Post by edwilliams16 »

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
>>> 
Post Reply