Question about automatic Parts List

GKR2023
Enthusiast

Question about automatic Parts List

GKR2023
Enthusiast
Enthusiast

Hello,

 

I am trying a code that I found online for an automatic partslist.

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
    
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet

'Detect if the template has a parts list
Try 
Dim oPartslistCheck As PartsList
oPartslistCheck = oSheet.PartsLists(1)
partslistpresent=True
Catch
partslistpresent=False
End Try

If partslistpresent=True
        
        'Delete the current parts list
        Dim oPartsList As PartsList
        oPartsList = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
        oPartsList.Delete
        
End If
                
    ' Set a reference to the first drawing view on
    ' the sheet. This assumes the first drawing
    ' view on the sheet is not a draft view.
    Dim oDrawingView As DrawingView
    oDrawingView = oSheet.DrawingViews(1)
    
    ' Set a reference to the sheet's border
    Dim oBorder As Border
    oBorder = oSheet.Border
	    
    Dim oPlacementPoint As Point2d
    
        xrev = oBorder.RangeBox.MaxPoint.X
        yrev = oBorder.RangeBox.MinPoint.Y
	
		Dim oTitleBlockItem As TitleBlock
		oTitleBlockItem = oSheet.TitleBlock
			
		Dim oHeightTitleBlock As Double
		oHeightTitleBlock = oTitleBlockItem.RangeBox.MaxPoint.Y - oTitleBlockItem.RangeBox.MinPoint.Y
		
'		Dim oPartsListItem As PartsList
'		oPartsListItem = oSheet.PartsLists
			
'		Dim oHeightPartsList As Double
'		oHeightPartsList = oPartsListItem.RangeBox.MaxPoint.Y - oPartsListItem.RangeBox.MinPoint.Y
		
        oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev + oHeightTitleBlock) 
        
    ' Create the parts list.
    Dim oPartsList1 As PartsList
    oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
oPartsLis1t = oDrawingDoc.ActiveSheet.PartsLists.Item(1)


oPartsList1.Sort("Part Nr. / Drawing Nr.")
oPartsList1.Renumber

oPartsList1.Style.UpdateFromGlobal 

'Switch style back and forth to ensure style is up-to-date    
'    oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ANSI)")
    oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ISO)")

InventorVb.DocumentUpdate()

 

Now I was wondering if it is possible to switch the insert point.

Schermafbeelding 2023-07-10 101449.png

Now it uses corner/point 1 as insert point. And I would like corner/point 2. Is it possible to change this in the code?

Ciao
0 Likes
Reply
Accepted solutions (1)
544 Views
6 Replies
Replies (6)

Andrii_Humeniuk
Advisor
Advisor

Hi @GKR2023 . I modified your code a bit and made it more logical. Line 46 and 47 is the new positioning for point 2 as in your screenshot.

Dim oDrawingDoc As DrawingDocument = ThisDoc.Document  
Dim oSheet As Sheet = oDrawingDoc.ActiveSheet
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
                
' Set a reference to the first drawing view on
' the sheet. This assumes the first drawing
' view on the sheet is not a draft view.
Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    
' Set a reference to the sheet's border
Dim oBorder As Border = oSheet.Border

Dim xrev, yrev, dWList As Double
xrev = oBorder.RangeBox.MaxPoint.X
yrev = oBorder.RangeBox.MinPoint.Y
	
Dim oTitleBlockItem As TitleBlock = oSheet.TitleBlock
Dim oHeightTitleBlock As Double = oTitleBlockItem.RangeBox.MaxPoint.Y - oTitleBlockItem.RangeBox.MinPoint.Y
		
'Dim oPartsListItem As PartsList
'oPartsListItem = oSheet.PartsLists

'Dim oHeightPartsList As Double
'oHeightPartsList = oPartsListItem.RangeBox.MaxPoint.Y - oPartsListItem.RangeBox.MinPoint.Y
Dim oPlacementPoint As Point2d = oTG.CreatePoint2d(xrev, yrev + oHeightTitleBlock) 

'Detect if the template has a parts list
Dim oPartsList As PartsList
Try
	oPartslistCheck = oSheet.PartsLists.Item(1)
	oPartsList.Delete
Catch
	' Create the parts list.
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
End Try

oPartsList.Sort("Part Nr. / Drawing Nr.")
oPartsList.Renumber

oPartsList.Style.UpdateFromGlobal 

'Switch style back and forth to ensure style is up-to-date    
'oPartsList1.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ANSI)")
oPartsList.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts List (ISO)")

dWList = oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y
oPartsList.Position = oTG.CreatePoint2d(xrev, yrev + oHeightTitleBlock + dWList)

InventorVb.DocumentUpdate()

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

GKR2023
Enthusiast
Enthusiast

I tried the code thanks, and so far it works. The only strange bit is that when I use an other parts list format it will look different.test1.png

It still will come underneath it (green). 

This is the style of the two:

test2.png

The one on the left is the one that is the default, and mostly used. And also the one that is in the Titleblock

Ciao
0 Likes

Andrii_Humeniuk
Advisor
Advisor

I did not change the code that is commented out. You need to remove the number 1 - oPartsList1
PartsList1.png

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

GKR2023
Enthusiast
Enthusiast

Okey, but that didn't solve it

Ciao
0 Likes

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Use 2 different rules to place your PartsLists. In line 25, write the desired name PartsLists ("Parts List (ISO)"). Please note that the "Parts List (ISO)" style is missing the "Part Nr. / Drawing Nr." column.

Dim oDrawingDoc As DrawingDocument = ThisDoc.Document  
Dim oSheet As Sheet = oDrawingDoc.ActiveSheet
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
Dim oBorder As Border = oSheet.Border

Dim xrev, yrev, dWList As Double
xrev = oBorder.RangeBox.MaxPoint.X
yrev = oBorder.RangeBox.MinPoint.Y
	
Dim oTitleBlockItem As TitleBlock = oSheet.TitleBlock
Dim oHeightTitleBlock As Double = oTitleBlockItem.RangeBox.MaxPoint.Y - oTitleBlockItem.RangeBox.MinPoint.Y

Dim oPlacementPoint As Point2d = oTG.CreatePoint2d(xrev, yrev + oHeightTitleBlock) 

Dim oPartsList As PartsList
Try
	oPartsList = oSheet.PartsLists.Item(1)
Catch
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
End Try

oPartsList.Style.UpdateFromGlobal()
oPartsList.Style = oDrawingDoc.StylesManager.PartsListStyles.Item("Parts list *****")
oPartsList.Sort("Part Nr. / Drawing Nr.")
oPartsList.Renumber

dHList = oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y
oPartsList.Position = oTG.CreatePoint2d(xrev, yrev + oHeightTitleBlock + dHList)

InventorVb.DocumentUpdate()

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

GKR2023
Enthusiast
Enthusiast

Sorry for the late reply. But it works! 😀

Ciao