Draw curve based on a function in Sketch(Part Design) Workbench

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!
dfosorio11
Posts: 36
Joined: Thu Sep 09, 2021 10:58 pm

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by dfosorio11 »

TheMarkster wrote: Sun Sep 12, 2021 11:49 pm To use Parametric_Curve_FP you must put the Parametric_Curve_FP.py file in your macros folder and also Make_Parametric_Curve.py into the same folder. Execute Make_Parametric_Curve to create the parametric curve fp object.

I entered the parameters you said, but I get a very flat curve. Perhaps I entered them wrong?

Snip macro screenshot-aa7471.png

Snip macro screenshot-3b8ae3.png

Snip macro screenshot-7bcf16.png

Attach a screenshot of your parameters as you have put them so I can see if they are the same that I used. Attach your file, too, if you can.

You can bring the bspline into your sketch as follows:

Use the link to external geometry tool (keyboard shortcut: X) in the sketch to create the external (purple) link.
Select the purple edge.
Sketch menu -> Sketcher bspline tools -> convert geometry to bspline

Now you have the curve into your sketch. You should be able to add coincidence constraints to the end points of the curve.

If the curve object is not inside the body (if using Part Design) you can create a shapebinder of it and use that with the external geometry.



Heey Markster man,

Thanks for helping me out! I tryed the External Geomerty (blue) tool but it did not recognized the godamn exponential curve. I tryed using this external geometry tool with other sketchs and solids and it actually worked, but not with my function curve. I attached the images of my FC environment and the file, I would really appreciate if you can check it out.
I've got metting tomorrow with my boss, I hope I can show it to him for he kicks my ass hahahahaha

You are actually saving my life. When I am not such a FC noob, I'll help you in return!!
Big hugs!!

Diego
Attachments
metal_slot_vivaldi3.FCStd
(237.02 KiB) Downloaded 27 times
im4.png
im4.png (178.39 KiB) Viewed 1537 times
im3.png
im3.png (169.98 KiB) Viewed 1537 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by TheMarkster »

Now that is a proper curve. I am able to replicate by entering the values you give in the screen shot with both macros. You are almost there.

Make sure the Body is active. You can double click to toggle from active to not active.
Select the BSpline and in Part Design menu -> Create a shape binder.
Select the BSpline, press space bar to make it invisible.
Now you see the gold colored ShapeBinder.
Open the Sketch. Press X, select ShapeBinder.
Now you have a purple bspline in the sketch as external link. Next, you should convert it to normal geometry.
Select the purple binder, so it is now green, Sketch menu -> bspline tools -> convert geometry to bspline.
Deselect, now it is white normal geometry.
Select the white bspline and in sketch menu -> constraints -> constrain block. Now it's not going anywhere when you add other constraints.
I recommend only use block constraint on bsplines or temporarily on other object types, like lines and circles.

This is convenient way to get bspline into the sketcher, but now it's not parametric. Any change to the original does not affect this one in the sketcher. You can delete the link to external geometry if you want to. In the left panel in the sketcher in the Elements panel you will see 2 bsplines. One has red points the other has purple points. You can delete the purple one. If you're not sure which one you can change the mode from All to External, then you only see the purple one in the panel.
dfosorio11
Posts: 36
Joined: Thu Sep 09, 2021 10:58 pm

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by dfosorio11 »

Heey dear THEMarkster, you are the man!

I really appreciate your help. At least I nailed it at last, because of you!!!! I subscribed to your channel, 'cause I feel I'll be needing all your advices.
I'd love to share with you my work. I am an electronics telecommunications student. I am currently working in Atennas Designs, the sketch plane we worked out is a part of an antenna. I am also working in a Python scripted library to import STEP/IGES parameter based files to a Ground Penetrating Simulator for Electromagnetism phenomena called gprMax.

Quick comments on the Bspline he did:

1. I was working with the initial unmodified 3D Parametric Curve macro by Gomez Lucio (attached)
2. Using (1) it did NOT worked for polyline, only B-spline
3. I attached the results from the Body (out of sketch) and inside it.


I'll be sending you the final antenna model once it's done and I would happily share my work with you as well as sharing your videos and work, or reference you to other community members via your YouTube Channel.

Long things short, I'm working at a research group at the Uni. I have to develop, write, deliever, other FreecCAD simulation tools like Macros, Python-scripts, etc, and tools to build from sketchs and build several antennas, adding them on the FreeCAD interface for parametric macro (python scripted) modeling.

I can't thank you enought!
Stay save
Diego
Attachments
3D Parametric Curve.py
(5.9 KiB) Downloaded 23 times
im6_inside the sketch (block contricted).png
im6_inside the sketch (block contricted).png (194.28 KiB) Viewed 1391 times
im5_out of sketch.png
im5_out of sketch.png (162.1 KiB) Viewed 1391 times
tag
Posts: 7
Joined: Thu Oct 14, 2021 7:57 pm

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by tag »

TheMarkster wrote: Mon Sep 13, 2021 4:19 pm Now that is a proper curve. I am able to replicate by entering the values you give in the screen shot with both macros. You are almost there.

Make sure the Body is active. You can double click to toggle from active to not active.
Select the BSpline and in Part Design menu -> Create a shape binder.
Select the BSpline, press space bar to make it invisible.
Now you see the gold colored ShapeBinder.
Open the Sketch. Press X, select ShapeBinder.
Now you have a purple bspline in the sketch as external link. Next, you should convert it to normal geometry.
Select the purple binder, so it is now green, Sketch menu -> bspline tools -> convert geometry to bspline.
Deselect, now it is white normal geometry.
Select the white bspline and in sketch menu -> constraints -> constrain block. Now it's not going anywhere when you add other constraints.
I recommend only use block constraint on bsplines or temporarily on other object types, like lines and circles.

This is convenient way to get bspline into the sketcher, but now it's not parametric. Any change to the original does not affect this one in the sketcher. You can delete the link to external geometry if you want to. In the left panel in the sketcher in the Elements panel you will see 2 bsplines. One has red points the other has purple points. You can delete the purple one. If you're not sure which one you can change the mode from All to External, then you only see the purple one in the panel.
Hello @TheMarkster. I'm also trying to generate a solid of revolution using a computed curve, so I generated a parametric curve (a simple line), but I'm having trouble following the above steps. Let me annotate them so you can perhaps clarify them for me:
  • Make sure the Body is active.
I'm assuming this is the body for into whose sketch the parameteric curve is to be incorporated. Done
  • Select the BSpline and in Part Design menu -> Create a shape binder.
This is where I'm having trouble. Which B-spline? I have a sketch (in Sketcher) and if I move the Parameteric curve to it, I can see the curve there as a separate black line but can't do anything to it.

Image
Image

Thanks for your help!

TAG
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by TheMarkster »

Close the sketch.
Make the body active (double click in the tree)
Select the ParametricCurve object and create the blue ShapeBinder
Hide the ParametricCurve object.
You should now see the Binder as a yellow translucent color.
Open the sketcher.
Create the link to external geometry to the binder
This should put a pink bspline in the sketch
Now turn the pink bspline into a bspline
tag
Posts: 7
Joined: Thu Oct 14, 2021 7:57 pm

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by tag »

TheMarkster wrote: Sat Oct 16, 2021 1:30 am Close the sketch.
Make the body active (double click in the tree)
Select the ParametricCurve object and create the blue ShapeBinder
Hide the ParametricCurve object.
You should now see the Binder as a yellow translucent color.
Open the sketcher.
Create the link to external geometry to the binder
This should put a pink bspline in the sketch
Now turn the pink bspline into a bspline
Thanks! This worked, though it was a struggle to discover that this works only for new sketches and not already existing ones, i.e., you have to create the sketch after the parametric curve is created. At least, this is how I found it but I'm not a FreeCAD expert so I could have been doing something wrong.

Also, for reference of other people who might come searching here: the way to convert the "pink" (magenta, really) B-spline that results from using the external geometry tool on the shape binder, is to select it and then use Sketch > Sketcher B-spline tools > Convert geometry to B-spline

TAG

PS. Here's the solid of revolution, the top surface of which is generated by z=A*exp(-k*x**2), where A and k were chosen such that the curve passed through the points (10, 2) and (0, 15).

Image
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Draw curve based on a function in Sketch(Part Design) Workbench

Post by TheMarkster »

Yes, magenta, not pink. I meant to say purple, which I guess at least would be a little bit closer.

One problem with this method is now the parametric curve is no longer parametric to the ParametricCurve object. If you change the equation the object is not updated automatically.

An alternative approach that is parametric:

backup the current file because at least it is working in case this fails
Instead of the shapebinder edit the Body's Group property to bring the ParametricCurve object into the Body directly
Instead of bringing the bspline into the sketch as a link to external geometry bring only its points as links to external geometry
Constrain your line segments coincidentally to those endpoints.
Snip macro screenshot-757b3e.png
Snip macro screenshot-757b3e.png (32.69 KiB) Viewed 1137 times
In Curves workbench (installed in the addon manager) select all edges and create a JoinCurve. Set the JoinCurve properties as in this screenshot:
Snip macro screenshot-5be892.png
Snip macro screenshot-5be892.png (122.03 KiB) Viewed 1137 times
Hide the JoinCurve and the ParametricCurve and show the sketch. Make the revolution using the edge of the sketch as the axis reference.
Snip macro screenshot-0ebc12.png
Snip macro screenshot-0ebc12.png (64.22 KiB) Viewed 1137 times
Now when tweaking the ParametricCurve equation the revolution changes with it.
Attachments
parametric_curve_example.FCStd
(13.3 KiB) Downloaded 32 times
Post Reply