Open a part that has a solid body and run the following code.
Public Sub SliceClientGraphics()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
' Set a reference to component definition of the active part.
Dim oCompDef As PartComponentDefinition
Set oCompDef = oDoc.ComponentDefinition
On Error Resume Next
Dim oClientGraphics As ClientGraphics
Set oClientGraphics = oCompDef.ClientGraphicsCollection("SliceGraphicsID")
If Err Then
Set oClientGraphics = oCompDef.ClientGraphicsCollection.Add("SliceGraphicsID")
Else
oClientGraphics.Delete
ThisApplication.ActiveView.Update
End
End If
Dim bApplyCap As Boolean
If MsgBox("Do you want an end cap?", vbQuestion + vbYesNo, "SliceGraphics") = vbYes Then
bApplyCap = True
Else
bApplyCap = False
End If
' Create a new graphics node within the client graphics objects.
Dim oSurfacesNode As GraphicsNode
Set oSurfacesNode = oClientGraphics.AddNode(1)
Dim oTransientBRep As TransientBRep
Set oTransientBRep = ThisApplication.TransientBRep
' Create a copy of the solid body in the part
Dim oBody As SurfaceBody
Set oBody = oTransientBRep.Copy(oCompDef.SurfaceBodies.Item(1))
' Create client graphics based on the transient body
Dim oSurfaceGraphics As SurfaceGraphics
Set oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oBody)
' Color it red
oSurfacesNode.Appearance = oDoc.AppearanceAssets(1)
' Make the body in the part invisible
oCompDef.SurfaceBodies.Item(1).Visible = False
Dim oLineSegment As LineSegment
Set oLineSegment = ThisApplication.TransientGeometry.CreateLineSegment(oSurfacesNode.RangeBox.MaxPoint, oSurfacesNode.RangeBox.MinPoint)
Dim oRootPoint As Point
Set oRootPoint = oLineSegment.MidPoint
' Get the negative Z-axis vector
Dim oNormal As Vector
Set oNormal = ThisApplication.TransientGeometry.CreateVector(0, 0, -1)
' Create a plane normal to Z axis with the root point at the center of the part
Dim oPlane As Plane
Set oPlane = ThisApplication.TransientGeometry.CreatePlane(oRootPoint, oNormal)
Dim oSlicingPlanes As ObjectCollection
Set oSlicingPlanes = ThisApplication.TransientObjects.CreateObjectCollection
Call oSlicingPlanes.Add(oPlane)
' Slice the client graphics
Call oSurfacesNode.SliceGraphics(bApplyCap, oSlicingPlanes)
' Update the view to see the result
ThisApplication.ActiveView.Update
End Sub