Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

@thanh.trantuan,

 

Try below code to change depth of section and rotate the section view.

 

Dim oSection As SectionDrawingView
            Set oSection = oSheet.DrawingViews.AddSectionView(oView, oSketch, oPt, kFromBaseDrawingViewStyle)
            
            oSection.SectionDepth = 127
            
            Call oSection.RotateByAngle(1.57, True)

 

Full modified code is as below.

 

Sub Section_View()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews.Item(1)
    
    Dim occ As ComponentOccurrence
    If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
        Dim oComp As AssemblyDocument
        Set oComp = oView.ReferencedDocumentDescriptor.ReferencedDocument
        
        Set occ = oComp.ComponentDefinition.Occurrences.ItemByName("Skeleton:1")
        
        Dim oSkeletonDoc As PartDocument
        Set oSkeletonDoc = occ.Definition.Document
    Else
        Exit Sub
    End If
    
    Dim wpCnt As Integer
    
    Dim i As Integer
    i = 1
    Dim h As Integer
    h = 1
    Dim v As Integer
    v = 1
    Dim wp As WorkPlane
    For Each wp In oSkeletonDoc.ComponentDefinition.WorkPlanes
         
        If wp.Name Like "T*" Or wp.Name Like "L*" Then
            Dim oProxy As WorkPlaneProxy
            Call occ.CreateGeometryProxy(wp, oProxy)
            Call oView.SetIncludeStatus(oProxy, True)
            Call oView.SetVisibility(oProxy, False)
            
            Dim oSketch As DrawingSketch
            Set oSketch = oView.Sketches.Add
                 
            Call oSketch.Edit
        
            Dim oStartPt As Point2d
            Set oStartPt = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Centerlines.Item(i).StartPoint.X, oSheet.Centerlines.Item(i).StartPoint.Y)
            
            Dim oStart As Point2d
            Set oStart = oView.SheetToDrawingViewSpace(oStartPt)
            
            Dim oEndPt As Point2d
            Set oEndPt = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Centerlines.Item(i).EndPoint.X, oSheet.Centerlines.Item(i).EndPoint.Y)
            
            Dim oEnd As Point2d
            Set oEnd = oView.SheetToDrawingViewSpace(oEndPt)
            
            Dim oLine As SketchLine
            Set oLine = oSketch.SketchLines.AddByTwoPoints(oStart, oEnd)
            
            Dim oPt As Point2d
            If oEnd.X = oStart.X Then
                Set oPt = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width - (10 * v), oView.center.Y)
                Call oSketch.GeometricConstraints.AddVertical(oLine)
                v = v + 1
            Else
                Set oPt = ThisApplication.TransientGeometry.CreatePoint2d(oView.center.X, (10 * h))
                Call oSketch.GeometricConstraints.AddHorizontal(oLine)
                h = h + 1
            End If
            
            Call oSketch.ExitEdit
            
            Dim oSection As SectionDrawingView
            Set oSection = oSheet.DrawingViews.AddSectionView(oView, oSketch, oPt, kFromBaseDrawingViewStyle)
            
            oSection.SectionDepth = 127
            
            Call oSection.RotateByAngle(1.57, True)
            
            i = i + 1
        End If
    Next
    
    
End Sub

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network