Geom2d.toShape() -> no 3D curve

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by wmayer »

One minor issue I have noticed with the change: if the support surface is not a plane then it now always creates a B-spline but before it e.g. created a circle for the snippet below. However, the check() method still raises the "No 3D curve" error.

Code: Select all

from FreeCAD import Base
import Part

obj = App.ActiveDocument.addObject("Part::Cylinder","Cylinder")
App.ActiveDocument.recompute()
shp = obj.Shape
elt = shp.Face1

import math
l2d = Part.Geom2d.Line2dSegment(Base.Vector2d(0,0),Base.Vector2d(2*math.pi,0.0))
edge = l2d.toShape(elt.Surface)
Part.show(edge)

edge.Curve
edge.check()
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by wmayer »

OK, I found a trick how to keep the canonical curve. See git commit 1073d06

The trick is to use BRepAdaptor_Curve and then for each canonical curve recreate the edge the using this curve and the boundaries. This way a 3d curve is created. If the curve type is unknown BRepLib::BuildCurves3d is used to create a B-spline.

Code: Select all

from FreeCAD import Base
import Part

obj = App.ActiveDocument.addObject("Part::Cylinder","Cylinder")
App.ActiveDocument.recompute()
shp = obj.Shape
elt = shp.Face1

# helix
l2d = Part.Geom2d.Line2dSegment(Base.Vector2d(0,0),Base.Vector2d(6.283185307179586,10.0))

edge = l2d.toShape(elt.Surface)
Part.show(edge)

edge.Curve
edge.check()




# line
l2d = Part.Geom2d.Line2dSegment(Base.Vector2d(0,0),Base.Vector2d(6.283185307179586,10.0))
edge = l2d.toShape(Part.Plane())
Part.show(edge)

edge.Curve
edge.check()



# circle
import math
l2d = Part.Geom2d.Line2dSegment(Base.Vector2d(0,0),Base.Vector2d(2*math.pi,0.0))
edge = l2d.toShape(elt.Surface)
Part.show(edge)

edge.Curve
edge.check()


# arc of circle
import math
l2d = Part.Geom2d.Line2dSegment(Base.Vector2d(0,0),Base.Vector2d(math.pi,0.0))
edge = l2d.toShape(elt.Surface)
Part.show(edge)

edge.Curve
edge.check()
User avatar
Chris_G
Veteran
Posts: 2598
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Geom2d.toShape() -> no 3D curve

Post by Chris_G »

Thanks Werner,
That is really cool.
I'll test this with the next PPA update.
Post Reply