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

Adding Part List to each view present in the Drawing sheet and skip if the part list already Exist

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

Labels (1)