03-02-2020
10:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
03-02-2020
10:34 PM
Thanks for sample files to investigate,
To section view in drawings, it is suggested to use workplanes as shown in below image. Later, same workplanes are used for creating section line and section views are added into drawing.
Using below VBA code, section views are added into drawing.
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 oComp As Document
Set oComp = oView.ReferencedDocumentDescriptor.ReferencedDocument
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 wpCnt = 4 To oComp.ComponentDefinition.WorkPlanes.count
Set wp = oComp.ComponentDefinition.WorkPlanes.Item(wpCnt)
Call oView.SetIncludeStatus(wp, True)
Call oView.SetVisibility(wp, 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
Next
End Sub
To demonstrate the same, a screencast video is prepared and uploaded into below link.
The modified assembly with workplanes is attached with this post.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network
