<?xml encoding=”UTF-8″>By Adam Nagy
Through the API it’s possible to get back edges (lines, arcs, etc) and also the faces (plane, cylinder) as NURBS. You can use the AlternateBody property of the SurfaceBody object for this. Based on the parameters you provide either only the faces will be converted to NURBS or both the faces and edges.
Remarks in API Help file:
Valid values for the AlternateForm parameter are in the SurfaceGeometryFormEnum and are:
– SurfaceGeometryForm_NURBS: Convert analytic surfaces to NURBS. This may result in splitting faces and edges as necessary. When used alone, only the faces are converted to NURBS. Edges will be represented by analytic curves.
– SurfaceGeometryForm_ProceduralToNURBS: Convert procedural surfaces to more accurate NURB approximations. This may result in splitting faces and edges as necessary
– These are bitwise values and combining SurfaceGeometryForm_NURBS and SurfaceGeometryForm_ProceduralToNURBS will create a result where the entire body or face is converted to NURBS, procedural surfaces are accurately approximated, and all edges will also be converted to NURBS.
The following code shows how to get the various types of geometry from the model. In this case we are testing it with this cylinder body shown in the picture:
Sub PrintBodyInfo(sb As SurfaceBody)
Dim fs As FaceShell
For Each fs In sb.FaceShells
Debug.Print Space(1); "FaceShell"
Dim f As Face
For Each f In fs.Faces
Debug.Print Space(2); "Face: " + TypeName(f.Geometry)
Dim el As EdgeLoop
For Each el In f.EdgeLoops
Debug.Print Space(3); "EdgeLoop"
Dim e As Edge
For Each e In el.Edges
Debug.Print Space(4); "Edge: " + TypeName(e.Geometry)
Next
Next
Next
Next
End Sub
Sub GetBodies()
Dim pd As PartDocument
Set pd = ThisApplication.ActiveDocument
Dim cd As PartComponentDefinition
Set cd = pd.ComponentDefinition
Debug.Print ">> Original geometry"
Dim sb1 As SurfaceBody
Set sb1 = cd.SurfaceBodies(1)
Call PrintBodyInfo(sb1)
Debug.Print ">> AlternateBody(SurfaceGeometryForm_NURBS)"
Dim sb2 As SurfaceBody
Set sb2 = sb1.AlternateBody(SurfaceGeometryForm_NURBS)
Call PrintBodyInfo(sb2)
Debug.Print ">> AlternateBody(SurfaceGeometryForm_NURBS " + _
"Or SurfaceGeometryForm_ProceduralToNURBS)"
Dim sb3 As SurfaceBody
Set sb3 = sb1.AlternateBody(SurfaceGeometryForm_NURBS Or _
SurfaceGeometryForm_ProceduralToNURBS)
Call PrintBodyInfo(sb3)
End Sub
The result:
>> Original geometry
FaceShell
Face: Cylinder
EdgeLoop
Edge: Circle
EdgeLoop
Edge: Circle
Face: Plane
EdgeLoop
Edge: Circle
Face: Plane
EdgeLoop
Edge: Circle
>> AlternateBody(SurfaceGeometryForm_NURBS)
FaceShell
Face: BSplineSurface
EdgeLoop
Edge: LineSegment
Edge: Arc3d
Edge: LineSegment
Edge: Arc3d
Face: BSplineSurface
EdgeLoop
Edge: LineSegment
Edge: Arc3d
Edge: LineSegment
Edge: Arc3d
Face: BSplineSurface
EdgeLoop
Edge: Arc3d
Edge: Arc3d
Face: BSplineSurface
EdgeLoop
Edge: Arc3d
Edge: Arc3d
>> AlternateBody(SurfaceGeometryForm_NURBS Or
SurfaceGeometryForm_ProceduralToNURBS)
FaceShell
Face: BSplineSurface
EdgeLoop
Edge: BSplineCurve
Edge: BSplineCurve
Edge: BSplineCurve
Face: BSplineSurface
EdgeLoop
Edge: BSplineCurve
Face: BSplineSurface
EdgeLoop
Edge: BSplineCurve


Leave a Reply