Hier ist auch noch eine Beispiel-Subroutine.
'****************************************************************************
' Sub IntersectPlaneSurface
'
' Creates the intersection between a plane (given by its reference) and a
' surface. If both elements intersect, the intersection is added to iOpenBody
' and renamed to iName.
' Because this subroutine is always called from a loop, where a single plane
' intersects multiple surface, we create the reference to the plane only once
' outside the loop and outside this subroutine. We pass plane by its reference
' instead of creating the reference over and over again in this subroutine
'
' Variables:
' iPart: The part
' iHybridShapeFactory: The parts HybridShapeFactory
' iOpenBody: The open body to which the intersection will be added
' iSurface: The surface to be intersected
' iRefToPlane: The reference to the section plane
' iName: The name of iIntersection
' iIntersection: The created intersection object
'
'****************************************************************************
Sub IntersectPlaneSurface (iPart As Part, iHybridShapeFactory As HybridShapeFactory, _
iOpenBody As HybridBody, iSurface As HybridShape, iRefToPlane As Reference, _
iName As CATBSTR, iIntersection As HybridShapeIntersection)
Dim refToiSurface As Reference
'Create a reference to iSurface
Set refToiSurface = iPart.CreateReferenceFromObject(iSurface)
'Disable automatic error handling as we don't know
'whether there will be an intersection or not
On Error Resume Next
'Create the intersection object
'This works in any case, even if both elements don't intersect at all
'At this moment the element is only temporary. It will be discarded,
'if it is not appended to an open body
Set iIntersection = iHybridShapeFactory.AddNewIntersection(iRefToPlane, refToiSurface)
'Test if both elements intersect
'If not, update will cause an error
iPart.UpdateObject(iIntersection)
'In case of no error, both elements intersect and the intersection has to be
'added to the desired open body
If Err.Number = 0 Then
'Add intersection to current open body
iOpenBody.AppendHybridShape iIntersection
'Rename the intersection
RenameHybridShape iPart, iHybridShapeFactory, iIntersection, iName
End If
On Error Goto 0
End Sub
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP