- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everyone,
I am trying to write a code where I want to put a part list for each individual part that is available on the drawing sheet. But I don't know how to try and catch it part.
The following code is written such that it allows to select the view and also adds the parts list for that part.
But the problem arises when I want the section cut for the projected views as well and so it adds part lists for each projected view, Despite I only need one part list for that part. Please help!
Here's the code:
Sub Main() Start: Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' Select a drawing view. Dim oView As DrawingView oView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a drawing view.") 'Set a reference to the active sheet. Dim oSheet As Sheet oSheet = oView.Parent Dim dXval As Double dXval = oView.Left Dim dYval As Double dYval = oView.Center.Y Dim dLeftXval As Double dLeftXval = dXval - 3 'add height to y value Dim dUpperYval As Double dUpperYval = dYval + (0.5 * oView.Height) + 1 'subract height To y value Dim dLowerYval As Double dLowerYval = dYval - (0.5 * oView.Height) - 1 'Dim oPoint1 As Point2d 'oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X,dUpperYval) 'Dim oPoint2 As Point2d 'oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X,dLowerYval) Dim oPoint1 As Point2d oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval,dUpperYval) Dim oPoint2 As Point2d oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval,dLowerYval) 'create a new sketch For the section Dim oDrawingSketch As DrawingSketch = oView.Sketches.Add Dim oSketchPoint1 As Point2d oSketchPoint1 = oDrawingSketch.SheetToSketchSpace(oPoint1) Dim oSketchPoint2 As Point2d oSketchPoint2 = oDrawingSketch.SheetToSketchSpace(oPoint2) oDrawingSketch.Edit Dim oSketchLine As SketchLine oSketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oSketchPoint1,oSketchPoint2) oDrawingSketch.ExitEdit 'set the location for the view Dim olocal As Point2d olocal = ThisApplication.TransientGeometry.CreatePoint2d(6,oView.Center.Y) Dim oView2 As SectionDrawingView oView2 = oSheet.DrawingViews.AddSectionView(oView, oDrawingSketch, olocal,DrawingViewStyleEnum.kFromBaseDrawingViewStyle, Nothing, , , False, True) oDrawingSketch.Visible = True 'AutoGenerate PartList Dim oPlacementPoint As Point2d oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval+22, dUpperYval+3) iLogicVb.UpdateWhenDone = True Dim oPartslist As PartsList 'Dim C As Double Try 'try to get the parts list oPartslist = oSheet.PartsLists.Item(1) Catch 'catch error when no parts list is found 'and then create one oPartslist = oSheet.PartsLists.Add(oView, oPlacementPoint) End Try 'Selection if you want to continue with section cut Dim oChoice As String oChoice = MsgBox(" Do you want to create another section cut?", vbQuestion + vbYesNo + vbDefaultButton2, "Section Cut") If oChoice = vbYes Then GoTo Start Else End If End Sub
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
does this work for you?
[iLogic]
Start: Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument ' Select a drawing view. Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view.") 'Set a reference to the active sheet. Dim oSheet As Sheet = oView.Parent Dim dXval As Double = oView.Left Dim dYval As Double = oView.Center.Y Dim dLeftXval As Double = dXval - 3 'add height to y value Dim dUpperYval As Double = dYval + (0.5 * oView.Height) + 1 'subract height To y value Dim dLowerYval As Double = dYval - (0.5 * oView.Height) - 1 Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval, dUpperYval) Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval, dLowerYval) 'create a new sketch For the section Dim oDrawingSketch As DrawingSketch = oView.Sketches.Add Dim oSketchPoint1 As Point2d = oDrawingSketch.SheetToSketchSpace(oPoint1) Dim oSketchPoint2 As Point2d = oDrawingSketch.SheetToSketchSpace(oPoint2) oDrawingSketch.Edit() Dim oSketchLine As SketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oSketchPoint1, oSketchPoint2) oDrawingSketch.ExitEdit() 'set the location for the view Dim olocal As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(6, oView.Center.Y) Dim oView2 As SectionDrawingView = oSheet.DrawingViews.AddSectionView(oView, oDrawingSketch, olocal, DrawingViewStyleEnum.kFromBaseDrawingViewStyle, Nothing, , , False, True) oDrawingSketch.Visible = True 'AutoGenerate PartList Dim oPlacementPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval + 22, dUpperYval + 3) ' check if we can find a partlist that belongs to the seelcted view Dim viewPartName = oView.ReferencedFile.FullFileName Dim aPartListIsFound = False For Each pl As PartsList In oSheet.PartsLists Dim plFileName = pl.ParentView.ReferencedFile.FullFileName If (viewPartName.Equals(plFileName)) Then aPartListIsFound = True End If Next ' If none partslist was found then create it. If (aPartListIsFound = False) Then oSheet.PartsLists.Add(oView, oPlacementPoint) End If 'Selection if you want to continue with section cut Dim oChoice As String oChoice = MsgBox(" Do you want to create another section cut?", vbQuestion + vbYesNo + vbDefaultButton2, "Section Cut") If oChoice = vbYes Then GoTo Start Else End If
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I condensed the code a little and change the Try/Catch into a loop:
Sub Main()
If ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then MessageBox.Show("This rule is designed to only work in drawing documents.", "Wrong Document Type") : Exit Sub
Start:
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
' Select a drawing view.
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a drawing view.")
'Set a reference to the active sheet.
Dim oSheet As Sheet = oView.Parent
Dim dXval As Double = oView.Left
Dim dYval As Double = oView.Center.Y
Dim dLeftXval As Double = dXval - 3
'add height to y value
Dim dUpperYval As Double = dYval + (0.5 * oView.Height) + 1
'subract height To y value
Dim dLowerYval As Double = dYval - (0.5 * oView.Height) - 1
Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval,dUpperYval)
Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval,dLowerYval)
'create a new sketch For the section
Dim oDrawingSketch As DrawingSketch = oView.Sketches.Add
Dim oSketchPoint1 As Point2d = oDrawingSketch.SheetToSketchSpace(oPoint1)
Dim oSketchPoint2 As Point2d = oDrawingSketch.SheetToSketchSpace(oPoint2)
oDrawingSketch.Edit
Dim oSketchLine As SketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oSketchPoint1,oSketchPoint2)
oDrawingSketch.ExitEdit
'set the location for the view
Dim olocal As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(6,oView.Center.Y)
Dim oView2 As SectionDrawingView = oSheet.DrawingViews.AddSectionView(oView, oDrawingSketch, olocal,DrawingViewStyleEnum.kFromBaseDrawingViewStyle, Nothing, , , False, True)
oDrawingSketch.Visible = True
'AutoGenerate PartList
Dim oPlacementPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(dLeftXval+22, dUpperYval+3)
iLogicVb.UpdateWhenDone = True
For Each pl As PartsList In oSheet.PartsLists
If pl.ReferencedDocumentDescriptor.FullDocumentName = oView.ReferencedDocumentDescriptor.FullDocumentName
GoTo Done 'Parts list Exists so exiting loop to avoid making again
End If
Next
'If exiting loop normally, then Partslist was not found so we will make it
Dim oPartslist As PartsList = oSheet.PartsLists.Add(oView, oPlacementPoint)
Done :
'Selection if you want to continue with section cut
Dim oChoice As String = MsgBox(" Do you want to create another section cut?", vbQuestion + vbYesNo + vbDefaultButton2, "Section Cut")
If oChoice = vbYes Then GoTo Start
End SubLet me know if you're still having issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you very much. This one also worked perfectly. Really appreciate it!
Both the ways gave me the insight the use of ReferencedDocumentDescriptor and how the same thing is achieved in two different ways.
Got to learn something new! ![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
This rule works awesome for section cuts and part lists. However, it creates the section cut on the left side. Is there a way to create them on the right side as well for custom representations. Any help is appreciated.
@J-Camper @Anonymous @JelteDeJong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You would need to change the X value for the section line to be on the right side of the view and reverse the direction of the section cut when making it. I’m away from my computer so I can’t rewrite the code right now, but it shouldn’t be too difficult.
and the section line x value can be set to the right side by setting it equal to drawingview.left + drawingview.width + an offset.
Let me know if you need help actually rewriting it