- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I try to write an add-in to create the sections automatically in Inventor drawing after basing the model
For example, I have a model like below picture with 3 longitudinal beams and 5 transverse beams
I base this model to Inventor drawing
and create sections like this
Could anyone suggest me the way to code the add-in to do this task automatically by using C#?
Many thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Please provide non confidential files to test the feasibility.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Many thanks your reply and it's highly appreciate your great support I have some questions, could you share your thought
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
Secondly, can we constraint these sketches after creating them
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.
Thanks & Best Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello @chandra.shekar.g,
is it possible to get longer section lines (text should be outside of the geometry)?
Thank you Georg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
At below code, extension of lines can be added depends on line type (Like Horizontal or Vertical).
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)
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @chandra.shekar.g,
thanks for this. Would you mind adding bit of comments to each part describing what the code does.
Best regards,
Sam
@chandra.shekar.g wrote:
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Many thanks for your great support
Regarding to 3rd question, I mean the depth value when we edit section properties. Section depth is "distance" instead of "Full"
Besides, I try to arrange the section, break the alignment and rotate the vertical section
I see that in your code, the distance between each section can be controlled, so how about rotate these vertical sections?
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sorry, I just have one question that
If I use frame generator to create stiffener, so it means that there are no work planes at the position of stiffener (because frame generator generate beams from sketch line). I want to make sections at the position of stiffeners by picking the part's edge (step 1) but it cannot work. Can you suggest me to do this task like this?
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Could you please take a look this question and give me any supports
Sorry, I just have one question that
If I use frame generator to create stiffener, so it means that there are no work planes at the position of stiffener (because frame generator generate beams from sketch line). I want to make sections at the position of stiffeners by picking the part's edge (step 1) but it cannot work. Can you suggest me to do this task like this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Are you trying through UI?
Please provide non confidential drawing files and supporting files to test the feasibility.
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I attached model here, please take a look
Besides, if it's possible, may I ask for help about customizing the text format of the section view like picture below by using VBA
there are 2 options, firstly is change single text of the section view, secondly is change all text of the all section view within the drawing sheet.
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Try below code to change the label of drawing view.
Dim oSection As SectionDrawingView
Set oSection = oSheet.DrawingViews.AddSectionView(oView, oSketch, oPt, kFromBaseDrawingViewStyle)
oSection.Label.FormattedText = "<StyleOverride Bold='True' Underline='True' FontSize='0.8'>SECTION <DrawingViewName/>-<DrawingViewName/></StyleOverride><Br/>SCALE <DrawingViewScale/>"
Thanks and regards,
CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you so much, so how about the question
"Sorry, I just have one question that
If I use frame generator to create stiffener, so it means that there are no work planes at the position of stiffener (because frame generator generate beams from sketch line). I want to make sections at the position of stiffeners by picking the part's edge (step 1) but it cannot work. Can you suggest me to do this task like this?"
could you give me any clues about this?
Thanks in advance