Try below,But it sometimes crashes and doesn't output. I don't know why this is so, it needs to be solved by a master.
If something goes wrong, Change view to another perspective.
The error is mainly that all sketch profile outlines cannot be selected when extrude at certain angles in the function of 'oSketchEnt', and the reason maybe some sketch lines intersect but do not have a clear intersection point; As a result, an effective closed profilepath cannot be formed.It is hoped that a master will solve it.
@WCrihfield
2025.5.26 edit


Examples of errors:


Option Explicit on
Public Sub Main()
oInvApp = ThisApplication
Dim oDoc As PartDocument = oInvApp.ActiveDocument
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oName As String = "Silhouette"
oCreateSilhouetteSketch(oDef, oName, oInvApp.ActiveView.Camera)
End Sub
Function oSketchEnt(oDef As PartComponentDefinition, oProfile As Profile, oName As String)
Dim oExtrudeDef As ExtrudeDefinition
oExtrudeDef = oDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kNewBodyOperation)
oExtrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection)
Dim oExtrude As ExtrudeFeature = oDef.Features.ExtrudeFeatures.Add(oExtrudeDef)
oExtrude.Name = "Extrude_" & oName
Dim obody As SurfaceBody = oExtrude.SurfaceBodies.Item(1)
oCreateClientFeature(oDef, oName, oProfile.Parent.PlanarEntity, obody)
oExtrude.Delete(False, False, False)
oDef.Document.selectset.select(oDef.Features.ClientFeatures.Item(1))
End Function
Function oCreateSilhouetteSketch(oCompDef As PartComponentDefinition, oInName As String, viewCam As Camera)
Dim oViewDir As UnitVector = viewCam.Eye.VectorTo(viewCam.Target).AsUnitVector
Dim xAxis As UnitVector = viewCam.UpVector.Copy
Dim UpPoint As Point = viewCam.Eye.Copy
UpPoint.TranslateBy(xAxis.AsVector)
Dim EyeTargetUpPlane As Plane = oInvApp.TransientGeometry.CreatePlaneByThreePoints(viewCam.Eye, viewCam.Target, UpPoint)
Dim yAxis As UnitVector = EyeTargetUpPlane.Normal
Dim oWap As WorkPlane = oCompDef.WorkPlanes.AddFixed(oCompDef.MassProperties.CenterOfMass, xAxis, yAxis, True)
Dim oWax As WorkAxis = oCompDef.WorkAxes.AddFixed(oCompDef.MassProperties.CenterOfMass, oViewDir, True)
Dim oSk As PlanarSketch = oCompDef.Sketches.Add(oWap)
oCreateTmpView(oCompDef, viewCam, oSk, oInName)
End Function
Function oCreateTmpView(oCompDef As PartComponentDefinition, oViewCamera As Camera, oSk As PlanarSketch, oName As String)
Dim oDoc As DrawingDocument = oInvApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , False)
Dim oViewOrientation As ViewOrientationTypeEnum = ViewOrientationTypeEnum.kArbitraryViewOrientation
Dim oSht As Sheet = oDoc.ActiveSheet
Dim oPntView As Point2d = oInvApp.TransientGeometry.CreatePoint2d(0, 0)
Dim oScale As Double = 1
Dim oViewStyle As DrawingViewStyleEnum = DrawingViewStyleEnum.kHiddenLineDrawingViewStyle
Dim oVBase As DrawingView = oSht.DrawingViews.AddBaseView(oCompDef.Document, oPntView,
oScale, oViewOrientation, oViewStyle, , oViewCamera, )
Dim oDrawSketch As DrawingSketch = oVBase.Sketches.Add
For Each oDrawingCurve As DrawingCurve In oVBase.DrawingCurves
oDrawSketch.AddByProjectingEntity(oDrawingCurve)
Next
oDrawSketch.CopyContentsTo(oSk)
Dim oSkCol As ObjectCollection = oInvApp.TransientObjects.CreateObjectCollection
For Each oSkent As SketchEntity In oSk.SketchEntities
oSkCol.Add(oSkent)
Next
Dim oPmt As Point2d = oVBase.ModelToDrawingViewSpace(oCompDef.MassProperties.CenterOfMass)
oSk.MoveSketchObjects(oSkCol, oPmt.VectorTo(oPntView))
oSk.RotateSketchObjects(oSkCol, oPntView, 3 * PI / 2, False, True)
Dim oProfile As Profile
oProfile = oSk.Profiles.AddForSolid(False, oSkCol, False)
oDoc.Close(True)
oSketchEnt(oCompDef, oProfile, oName)
End Function
Function oCreateClientFeature(oCompDef As PartComponentDefinition, oInName As String, oWp As WorkPlane, oBody As SurfaceBody)
Dim oName As String = "BRep-" & oInName
Dim oCf As ClientFeature
Try
oCf = oCompDef.Features.ClientFeatures.Item("[" & oName & "]")
oCf.Delete
Catch : End Try
Dim oCfDef As ClientFeatureDefinition = oCompDef.Features.ClientFeatures.CreateDefinition()
oCf = oCompDef.Features.ClientFeatures.Add(oCfDef, "[" & oName & "]")
oCf.Name = "[" & oName & "]"
oCfDef = oCf.Definition
Dim oClientGraphics As ClientGraphics = oCfDef.ClientGraphicsCollection.Add(oName)
Dim oSurfacesNode As GraphicsNode = oClientGraphics.AddNode(1)
Dim oUnionBody As SurfaceBody
Dim oColors As Color = oInvApp.TransientObjects.CreateColor(0, 255, 255)
Dim oSk3d As Sketch3D = oCompDef.Sketches3D.Add
Dim oIntersectionCurve As IntersectionCurve = oSk3d.IntersectionCurves.Add(oWp, oBody)
oSk3d.Profiles3D.AddClosed
Dim oEdges As List(Of Object) = oSk3d.Profiles3D.Cast(Of Profile3D).
SelectMany(Function(x As Profile3D) x.cast(Of ProfilePath3D).ToList).
SelectMany(Function(x As ProfilePath3D) x.Cast(Of ProfileEntity3D).Tolist).
Select(Function(x As ProfileEntity3D) x.Curve).ToList
For Each oedge As Object In oEdges
Dim oCourve As CurveGraphics= oSurfacesNode.AddCurveGraphics(oedge)
oCourve.Color = oColors
oCourve.BurnThrough=True
oCourve.LineWeight = 15
Next
oSk3d.Delete
End Function
Public Shared oInvApp As Inventor.Application