Curves 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!
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Curves workbench

Post by keithsloan52 »

Thanks @Chris_G I changed the macro to use the values minus 1 and it now appears to be working
C575B359-0144-46D3-9EB3-FDDE3497E592.jpeg
C575B359-0144-46D3-9EB3-FDDE3497E592.jpeg (93.02 KiB) Viewed 1433 times
I assume the need for the value minus 1 is because the surface is closed or double edges as Ed calls it.
What is the best way to determine if this is the case as opposed to an open surface?
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

You could answer this yourself in seconds
  • Select the ellipsoid face
  • ctl-shift -p to send to the Python console
  • sub.Surface. in the console
  • scroll for likely methods
Yep:

sub.Surface.isUClosed() => True
sub.Surface.isVClosed() => False

Got it. I don't know how you develop, but I spend a lot of time looking completions in the Python console. I need to know if methods or properties that I could use already exist.

Code: Select all

doc = App.ActiveDocument
obj = doc.getObject("IsoCurve")
ob, fa = obj.Face
face = getattr(ob.Shape, fa[0])
surf = face.Surface
umin, umax, vmin, vmax = face.ParameterRange
nu = obj.NumberU - 1
ulist = [i*(umax - umin)/nu + umin for i in range(nu + 1)]
if surf.isUClosed():
    ulist = ulist[:-1]

nv = obj.NumberV - 1
vlist = [i*(vmax - vmin)/nv + vmin for i in range(nv + 1)]
boxLength = 2
cmpd = doc.addObject("Part::Compound","CompoundBoxes")
links = []
for u in ulist:
    for v in vlist[1:]:
        base = surf.value(u, v)
        normal = surf.normal(u,v)
        #rot = App.Rotation(App.Vector(0,0,1), normal)
        tangents = surf.tangent(u, v)
        print(f'{tangents[0]} {normal}')
        rot = App.Rotation(tangents[0], App.Vector(), normal, 'ZXY')
        box = Part.makeBox(boxLength, boxLength, boxLength)
        centerpl = App.Placement(-(boxLength/2) * App.Vector(1,1,1), App.Rotation())
        box.Placement = App.Placement(base, rot) * centerpl
        boxdoc = Part.show(box, 'Box')
        links.append(boxdoc)

cmpd.Links = links
doc.recompute()

gets rid of the duplicates. If you have arbitrary surfaces in mind - not just ellipsoids, then it will get much more difficult.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Curves workbench

Post by keithsloan52 »

OKay now I want to code another macro that places n objects along the IsoCurve lines. I need a function that I can use to return the position of a point a distance along or fraction of the line length.

I have tried without success

Code: Select all

 edges[i].Curve.value(r)
 and
 edges[i].valueAt(r)
Where edges are taken from the IsoCurves Shape i.e. edges = iso.Shape.Edges
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

Code: Select all

edges[i].Curve.discretize(npts)
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Curves workbench

Post by keithsloan52 »

edwilliams16 wrote: Tue Dec 06, 2022 8:46 am

Code: Select all

edges[i].Curve.discretize(npts)
Thanks, okay now I also need the normals at the corresponding places on the surface.
I see that the surface has a function normal but it seems to take two values ( u and v maybe?)
Anyway to get the normal of the surface at the discretized points?
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Curves workbench

Post by edwilliams16 »

Look at the tooltips of the methods of your surface, to find one that returns u, v given the vector location...
How about surf.parameter(vector)?
The opposite direction - get location given u, v?
How about surf.value(u, v)?

The normal at (u,v) - surf.normal(u, v)
The tangent vectors in the u, v directions? - look at the tooltips and figure it out for yourself.

It's all there in the python console.
mangojellysolutions
Posts: 4
Joined: Sat Dec 17, 2022 10:52 am

Re: Curves workbench

Post by mangojellysolutions »

Just like to thank Chris (and others) for continued work and dedication with the magnificent curves workbench and answering these questions. Even when the comments start getting a bit heated, Chris it must be hard to take certain levels of criticism when this is something you have worked on for love.

I have only just made an account on here . I have so many information streams it's hard to keep on top of. But I thought I take the time out to wish everyone that's contributed to this superb workbench a happy festive season and show my gratitude to what you have achieved.

I'm returning to the curves wb after taking time to focus on teaching the basics. I have a project that require curves so have stepped back in and am finding things that I didn't know existed or I was blind to.

I do have one question if I may, just to get me on the right path. I am making a version of rhino3D tween curve and need to create a new freehand bspline in a macro without using 'runcommand(gordenprofile,0)' so I can assign it to a variable. I know how to do this with a box in part wb but not sure about curves wb, I think I need to import from curves. That's all I need the rest I can figure out 🤔😁

Thank you once again and hope you all have a nice festive break... Sorry for the long post

MJ
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Curves workbench

Post by mario52 »

Hi

welcome mangojellysolutions

many thanks for your instructive video

bonnes fêtes

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Curves workbench

Post by drmacro »

I encountered an issue when using a user created sketch with Sketch on surface.

If the user sketch has no construction line/s, FreeCAD goes unresponsive and process kill is the only option I've found.

Is it possible to check for the lack of construction lines and prevent lockup?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Curves workbench

Post by Chris_G »

drmacro wrote: Sat Dec 17, 2022 12:03 pm Is it possible to check for the lack of construction lines and prevent lockup?
It should be fixed now.
mangojellysolutions wrote: Sat Dec 17, 2022 11:27 am Just like to thank Chris (and others) for continued work and dedication with the magnificent curves workbench and answering these questions.
Thanks a lot for your great Youtube tutorials. I think they have become the main source of documentation for people who want to give a try at Curves workbench.
mangojellysolutions wrote: Sat Dec 17, 2022 11:27 am I do have one question if I may, just to get me on the right path. I am making a version of rhino3D tween curve and need to create a new freehand bspline in a macro without using 'runcommand(gordenprofile,0)' so I can assign it to a variable. I know how to do this with a box in part wb but not sure about curves wb, I think I need to import from curves. That's all I need the rest I can figure out 🤔😁
This should put you on the right track :

Code: Select all

from freecad.Curves import gordon_profile_FP as GP

sub = []
# If the Spline is snapped to other shapes
# add a link to these shapes. For example :
# sub = [(obj1, ("Edge1",)), (obj2, ("Face1",))]

# the interpolation points
pts = [FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(5, 0, 0), FreeCAD.Vector(10, 0, 0)]

# the type of each point.
# 0 = free point
# 1 = point snapped to a shape of the sub list
# For example, typ = [1, 0, 1]
# means that the first point will snap to the fist shape of the sub list
# and the third point will snap to the second shape
typ = [0, 0, 0]

fp = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Freehand BSpline")
GP.GordonProfileFP(fp, sub, pts, typ)
GP.GordonProfileVP(fp.ViewObject)
fp.recompute()

Post Reply