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

Add parts list to drawing based on document type

Hey y'all. I am trying to create some code I can run in a drawing document that is going to automatically add a different parts list to my sheet depending on if the current view on the sheet is a part or assembly. I have pieced together some code, but have not had any success when running it. (no errors, but nothing happens) I think the problem is something to do with calling on "oDwgDoc.type" and not the type in the view on the sheet. I have pasted the code below:

 

oDwgDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDwgDoc.ActiveSheet
Dim oBaseView As DrawingView
Dim oPartsList As PartsList 
oBaseView = oSheet.DrawingViews.Item(1)

	If Not oBorder Is Nothing Then
    	oPlacementPoint = oBorder.RangeBox.MaxPoint
	Else
    	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width - 2.54/2, oSheet.Height - 2.54)
	End If

	Try
    oPartsList = oSheet.PartsLists(1)
	Catch
 		If oDwgDoc.Type = kAssemblyDocumentObject Then
			oPartsList = oSheet.PartsLists.Add(oBaseView, oPlacementPoint)
	 		oPartsList.Style = oDwgDoc.StylesManager.PartsListStyles.Item("Assembly List")
		Else If oDwgDoc.Type = kPartDocumentObject Then
			oPartsList = oSheet.PartsLists.Add(oBaseView, oPlacementPoint)
	 		oPartsList.Style = oDwgDoc.StylesManager.PartsListStyles.Item("Parts List Dimensionless")
 		End If
	End Try
	
End Sub