By Barbara Han
Issue
I am exporting the extrude features’ data in xml. Consider two extrude features, where one lies on another,I need to identify on which plane the extrude feature lies, then extract the information of the plane. Can you please let us know how to do that through API?
Solution
To get the intersected plane of two features, there is no direct API for that, but it can be done using MeasureTools.GetMinimumDistance method. If the distance of two faces is zero, the two faces must overlap/intersect. Please refer to below sample code.
VBA sample code:
Sub intersectionOf2Extrudes()
Dim extr1 As ExtrudeFeature
Dim extr2 As ExtrudeFeature
‘get two extrude features, here assuming the user selected them from UI
Set extr1 = ThisApplication.ActiveDocument.SelectSet.Item(1)
Set extr2 = ThisApplication.ActiveDocument.SelectSet.Item(2)
ThisApplication.ActiveDocument.SelectSet.Clear
Dim faces1 As FaceCollection
Set faces1 = ThisApplication.TransientObjects.CreateFaceCollection
Dim faces2 As FaceCollection
Set faces2 = ThisApplication.TransientObjects.CreateFaceCollection
Dim f1 As Face
Dim f2 As Face
For Each f1 In extr1.Faces
Dim d As Double
For Each f2 In extr2.Faces
d = ThisApplication.MeasureTools.GetMinimumDistance(f1, f2)
Debug.Print d
If d = 0 Then
ThisApplication.ActiveDocument.SelectSet.Select f2
Dim obj As Object
Set obj = f2.Geometry
Select Case f2.SurfaceType
Case SurfaceTypeEnum.kPlaneSurface
Dim objPlane As Plane
Set objPlane = obj
Dim rp() As Double
Dim normal() As Double
obj.GetPlaneData rp, normal
‘TODO: export the plane information
Case SurfaceTypeEnum.kBSplineSurface
Dim objBSpline As BSplineSurface
Set objBSpline = obj
Dim poles() As Double
Dim knotsU() As Double
Dim knotsV() As Double
Dim weight() As Double
objBSpline.GetBSplineData poles, knotsU, knotsV, weight
‘TODO: export the plane information
Case Else ‘ToDo: judge other type and get data accordingly
”do something here
End Select
End If
Next
Next
End Sub
VB.NET sample code:
‘ ThisApplication is a global variant that delegate Application object
Sub intersectionOf2Extrudes()
Dim extr1 As ExtrudeFeature
Dim extr2 As ExtrudeFeature
‘get two extrude features, here assuming the user selected them from UI
extr1 = ThisApplication.ActiveDocument.SelectSet.Item(1)
extr2 = ThisApplication.ActiveDocument.SelectSet.Item(2)
ThisApplication.ActiveDocument.SelectSet.Clear()
Dim faces1 As FaceCollection
faces1 = ThisApplication.TransientObjects.CreateFaceCollection
Dim faces2 As FaceCollection
faces2 = ThisApplication.TransientObjects.CreateFaceCollection
Dim f1 As Face
Dim f2 As Face
For Each f1 In extr1.Faces
Dim d As Double
For Each f2 In extr2.Faces
d = ThisApplication.MeasureTools.GetMinimumDistance(f1, f2)
Debug.Print(d)
If d = 0 Then
ThisApplication.ActiveDocument.SelectSet.Select(f2)
Dim obj As Object
obj = f2.Geometry
Select Case f2.SurfaceType
Case SurfaceTypeEnum.kPlaneSurface
Dim objPlane As Plane
objPlane = obj
Dim rp(0) As Double
Dim normal(0) As Double
obj.GetPlaneData(rp, normal)
‘TODO: export the plane information
Case SurfaceTypeEnum.kBSplineSurface
Dim objBSpline As BSplineSurface
objBSpline = obj
Dim poles(0) As Double
Dim knotsU(0) As Double
Dim knotsV(0) As Double
Dim weight(0) As Double
objBSpline.GetBSplineData(poles, knotsU, knotsV, weight)
‘TODO: export the plane information
Case Else ‘ToDo: judge other type and get data accordingly
”do something here
End Select
End If
Next
Next
End Sub

Leave a Reply