iLogic - Creating Structured Parts List

iLogic - Creating Structured Parts List

JoãoASilva
Advocate Advocate
940 Views
8 Replies
Message 1 of 9

iLogic - Creating Structured Parts List

JoãoASilva
Advocate
Advocate

Hello everyone and Happy New Year! 😎

 

I came across this thread about automatically placing a Parts List in a drawing.

After a few tweaks, got it *almost* working as I need it to.

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

' Set a reference to the sheet's title block
Dim oTitleBlock As TitleBlock
oTitleBlock = oSheet.TitleBlock

'['Temporary Parts List
Dim oPlacementPoint As Point2d
	xrev = 0
	yrev = 0
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev)
    
' Create the parts list
Dim oPartsList1 As PartsList
oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
']

'['Definitive Parts List
Dim oPlacementPoint2 As Point2d
	xrev2 = oTitleBlock.RangeBox.MaxPoint.X - 0.5
	yrev2 = oTitleBlock.RangeBox.MaxPoint.Y - oPartsList1.RangeBox.MinPoint.Y
	oPlacementPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(xrev2, yrev2)

' Delete Temporary Parts List
oPartsList1 = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Delete

' Create Definitive Parts List
Dim oPartsList2 As PartsList
oPartsList2 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint2, PartsListLevelEnum.kFirstLevelComponents)
']

oPartsList2.Sort("PART NUMBER")
oPartsList2.Renumber

oPartsList2.Style.UpdateFromGlobal 

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

InventorVb.DocumentUpdate()

Only thing left is to create a Parts List with a "Structured BOM View".

 

When I manually select "Structured (legacy)", I get to expand the Parts List and see all sub-assemblys:

JoãoASilva_0-1609848578224.png  JoãoASilva_1-1609848632888.png

But I can't find how to get the rule to do so:

JoãoASilva_2-1609849081312.png

 

Any thoughts?

João Silva

Mechanical Engineer

 

0 Likes
Accepted solutions (1)
941 Views
8 Replies
Replies (8)
Message 2 of 9

dutt.thakar
Collaborator
Collaborator

@JoãoASilva 

 

Can you change this line in your code, when you are placing Definitive parts list?

 

oPartsList2 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint2, PartsListLevelEnum.kStructuredAllLevels)

See if it works.

 

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 3 of 9

JoãoASilva
Advocate
Advocate

@dutt.thakar 

If I change that it gives an error.

Expected, since it only accepts kFirstLevelComponents and kPartsOnly.

JoãoASilva_0-1609854874803.png

But I found how I can change it manually:

JoãoASilva_1-1609854982540.png  JoãoASilva_2-1609855008979.png

I'm trying to get here, thru code, when run on the drawing document.

Any inputs are welcome.

João Silva

Mechanical Engineer

 

0 Likes
Message 4 of 9

dutt.thakar
Collaborator
Collaborator

@JoãoASilva 

 

What I would suggest you is to take a model document from the drawing reference and then you can reference its BOM object from iLogic and in BOm you can set the structured view and also the all levels.

 

I think you can see this link may be a help.

 

https://forums.autodesk.com/t5/inventor-customization/ilogic-bom-enabled-for-all-child-assemblies/m-...

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 5 of 9

JoãoASilva
Advocate
Advocate

@dutt.thakar 

 

I was replying with exactly that!

 

I found a way to reach the BOM of the model in the drawing:

Dim oDrawingView As DrawingView
oDrawingView = oSheet.DrawingViews(1)
' get model doc
Dim oModelDoc As Document
oModelDoc = ActiveSheet.View(oDrawingView.Name).ModelDocument
' get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure the BOM view is enabled
oBOM.StructuredViewEnabled = True
' Make sure the BOM first level is disabled
oBOM.StructuredViewFirstLevelOnly = False
' Set the delimiter for the BOM view
oBOM.StructuredViewDelimiter = "."

And this works perfectly!

 

The problem now is that I get an error: HRESULT: 0x80070057

From what I have seen, it has to do with the temp file, wich has to be deleted.

Sometimes the rule works, other times it doesn't.

 

And the part that is giving an error is: 

oPartsList1 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)

 I placed a "return" before (nothing happend), and placed a "return" after and got that error.

João Silva

Mechanical Engineer

 

0 Likes
Message 6 of 9

dutt.thakar
Collaborator
Collaborator

@JoãoASilva 

 

I tried the code in my assembly and I got the same error here : oPartsList.Sort("PART NUMBER") , This has happened because I don't have the same column in my BOM so when I changed the column name in "oPartsList.Sort", The error is resolved. Apart from that everything works perfectly.

 

Is it possible for you to attach your assembly and drawing here, so I can try and look in to it?

 

Hope this is helpful.

 

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 7 of 9

JoãoASilva
Advocate
Advocate

@dutt.thakar ,

 

In my case, it doesn't even reach that part 😅

I've attached the files for you to test. Hope none are missing.

I've included a copy of my rule, in a .txt format.

 

Can't yet figure out why the rule runs sometimes, other times it doesn't.

Even though the conditions seem to be the same...

João Silva

Mechanical Engineer

 

0 Likes
Message 8 of 9

dutt.thakar
Collaborator
Collaborator
Accepted solution

@JoãoASilva 

 

Thanks for providing the files, The thing that was happening with your code is if you are updating the structure and all levels in the assembly, then you need to place the parts list with kStructuredAllLevels enum. I just changed a bit in your code, and it worked. see below code. I also added one mode thing when you are updating BOM level in model document, I added two lines, one is to rebuild the model and another is to save after you enable all levels.

 

If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
	Dim a As String = a
Else
	MessageBox.Show("This Rule can only be executed on the following documents:" & vbNewLine _
	& " • Drawing", "Rule not executed!" & " • " & iLogicVb.RuleName, MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End If

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.Item(1)


' Set a reference to the sheet's border
Dim oBorder As Border
oBorder = oSheet.Border

' Set a reference to the sheet's title block
Dim oTitleBlock As TitleBlock
oTitleBlock = oSheet.TitleBlock

'['Update BOM to Structured View
InventorVb.DocumentUpdate()
' get model doc
Dim oModelDoc As Document
oModelDoc = ActiveSheet.View(oDrawingView.Name).ModelDocument
' get the BOM database
oBOM = oModelDoc.ComponentDefinition.BOM
' Make sure the BOM view is enabled
oBOM.StructuredViewEnabled = True
' Make sure the BOM first level is disabled
oBOM.StructuredViewFirstLevelOnly = False
' Set the delimiter for the BOM view
oBOM.StructuredViewDelimiter = "."
oModelDoc.Rebuild2
oModelDoc.Save
InventorVb.DocumentUpdate()
']

'['Temporary Parts List
Dim oPlacementPoint As Point2d
	xrev = 1
	yrev = 1
	oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(xrev, yrev)
    
'' Create the parts list.
Dim oPartsList1 As PartsList
oPartsList1 = oSheet.PartsLists.Add(oDrawingView,oPlacementPoint,PartsListLevelEnum.kStructuredAllLevels) '<- This line gives me the error HRESULT: 0x80070057, but not everytime...
']

'['Definitive Parts List
Dim oPlacementPoint2 As Point2d
	xrev2 = oTitleBlock.RangeBox.MaxPoint.X - 0.5
	yrev2 = oTitleBlock.RangeBox.MaxPoint.Y - oPartsList1.RangeBox.MinPoint.Y
	oPlacementPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(xrev2, yrev2)

' Delete Temporary Parts List
oPartsList1 = oDrawingDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Delete

' Create Definitive Parts List
Dim oPartsList2 As PartsList
oPartsList2 = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint2,PartsListLevelEnum.kStructuredAllLevels)
']

oPartsList2.Sort("PART NUMBER")
oPartsList2.Renumber
oPartsList2.Style.UpdateFromGlobal 

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

InventorVb.DocumentUpdate()

 

Hope this will help.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 9 of 9

JoãoASilva
Advocate
Advocate

@dutt.thakar 

 

Thank you for your help, this way it worked on all files! 👊

The rule got slower because it needs to rebuild and save, but i'm fine with it.

Now I just need to adjust the placement of the Parts List and it's ready to be implemented.

 

Kudos!

João Silva

Mechanical Engineer

 

0 Likes