Here is one method to achieve this. Projecting the workplane to the sketch was difficult, you need to pick up the centerline in the drawing view to use as the entity. Simply using the workplaneproxy did not work.
Once you have it working I suggest you make functions/sub routines in order to reuse objects as you can see there is some repetition setting in. The code below is clean up in terms of using consistent variable naming change as you would like.
Sub Main()
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oFirst_view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Please select the main view")
If oFirst_view Is Nothing Then Exit Sub
If Not oFirst_view.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then Exit Sub
Dim oComp As AssemblyDocument = oFirst_view.ReferencedDocumentDescriptor.ReferencedDocument
Dim oOcc As ComponentOccurrence = oComp.ComponentDefinition.Occurrences.ItemByName("Skeleton test:1")
Dim oSkeletonDoc As PartDocument = oOcc.Definition.Document
Dim wpList As New List(Of String)
Dim oWp As WorkPlane
For Each oWp In oSkeletonDoc.ComponentDefinition.WorkPlanes
wpList.Add(oWp.Name)
Next
Dim wpSel As String = InputListBox("Work planes found", wpList, "", "Select work plane", "work plane found")
If String.IsNullOrEmpty(wpSel) Then Return
oWp = oSkeletonDoc.ComponentDefinition.WorkPlanes(wpSel)
Dim oWPlaneProxy As WorkPlaneProxy
oOcc.CreateGeometryProxy(oWp, oWPlaneProxy)
oFirst_view.SetIncludeStatus(oWPlaneProxy, True)
oFirst_view.SetVisibility(oWPlaneProxy, False)
Dim oSketch As DrawingSketch = oFirst_view.Sketches.Add
oSketch.Edit()
Dim oCenterLine1 As SketchLine
For Each oCenterline As Centerline In oSheet.Centerlines
If oCenterline.ModelWorkFeature Is oWPlaneProxy Then
oCenterLine1 = oSketch.AddByProjectingEntity(oCenterline)
End If
Next
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oStartPoint As Point2d = oTG.CreatePoint2d(oCenterLine1.Geometry.StartPoint.X - 1, oCenterLine1.Geometry.StartPoint.Y + 1)
Dim oEndPoint As Point2d = oTG.CreatePoint2d(oCenterLine1.Geometry.EndPoint.X+1, oCenterLine1.Geometry.EndPoint.Y+1)
Dim oSectionLine1 As SketchLine = oSketch.SketchLines.AddByTwoPoints(oStartPoint,oEndPoint)
Dim oDimension1 As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance _
(oSectionLine1.StartSketchPoint, oCenterLine1.StartSketchPoint, _
DimensionOrientationEnum.kVerticalDim, oSectionLine1.Geometry.MidPoint)
Dim oDimension2 As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance _
(oSectionLine1.StartSketchPoint, oCenterLine1.StartSketchPoint, _
DimensionOrientationEnum.kHorizontalDim, oCenterLine1.Geometry.StartPoint)
Dim oDimension3 As DimensionConstraint = oSketch.DimensionConstraints.AddTwoPointDistance _
(oSectionLine1.EndSketchPoint, oCenterLine1.EndSketchPoint, _
DimensionOrientationEnum.kHorizontalDim,oCenterLine1.Geometry.EndPoint)
oSketch.ExitEdit
Dim oInsertionPoint As Point2d = oTG.CreatePoint2d((oFirst_view.Position.X + 10), (oFirst_view.Position.Y + 10))
Dim oSectionView As SectionDrawingView = oSheet.DrawingViews.AddSectionView _
(oFirst_view, oSketch, oInsertionPoint, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
oSectionView.SetDesignViewRepresentation(oSectionView.DesignViewRepresentation, True)
oSectionView.ReverseDirection
oSectionView.SectionDepth = 50/10
oSectionView.ReverseDirection
End Sub
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan