@thanh.trantuan,
Firstly, in order to use your code, we have to create new planes which is constraint with existing structures. Could we have another way to do without create new planes like this. As you see, in the skeleton.ipt, these workplanes are created already, so can we use them to position the sketch lines - The same code is modified to get planes from skeleton.ipt
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
Call oSheet.DrawingViews.AddSectionView(oView, oSketch, oPt, kFromBaseDrawingViewStyle)
i = i + 1
End If
Next
End Sub
Secondly, can we constraint these sketches after creating them - Yes, it constrained to vertical or horizontal.
Thirdly, in the section properties, the section depth is full, could it be set up with the distance (such as 50 mm or 100mm) to show the section at this area only. - Hoping the same answer to Geroge will help this.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network