Sort BOM and renumber / Sort parts list

Sort BOM and renumber / Sort parts list

j.wolbers-NoTech
Enthusiast Enthusiast
2,226 Views
9 Replies
Message 1 of 10

Sort BOM and renumber / Sort parts list

j.wolbers-NoTech
Enthusiast
Enthusiast

Hi,

 

I would like my BOM to be sorted by Ilogic according to the first image. Then I would like the whole thing to be renumbered according to the second image.

 

sort.PNG

 

renumber.PNG

 

Finally, I want to use a separate Ilogic for the 2D drawings to automatically adjust the parts list order so that it increases from 1 (see image below).

 

Sort partslist.PNG

 

I would really appreciate if someone can help me with this. This would save us a lot of time while making the drawings. Unfortunately, I have no knowledge of Ilogic

 

Kinds regards,

Jeffrey

0 Likes
Accepted solutions (1)
2,227 Views
9 Replies
Replies (9)
Message 2 of 10

JelteDeJong
Mentor
Mentor

I create this rule that will work if you are in your Assembly or in your drawing. So there is 1 rule that works in both situations.

Dim doc As DrawingDocument = ThisDoc.Document
Dim partslist As PartsList
Dim aDoc As AssemblyDocument

If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
    Dim dDoc As DrawingDocument = ThisDoc.Document
    partslist = dDoc.ActiveSheet.PartsLists.Item(1)
    aDoc = partslist.ReferencedDocumentDescriptor.ReferencedDocument
Else
    aDoc = doc
End If

Dim BOM As BOM = aDoc.ComponentDefinition.BOM
BOM.StructuredViewEnabled = True

Dim oBOMView As BOMView = BOM.BOMViews("Structured")

oBOMView.Sort("BOM Structure", True, "Vendor", False)
oBOMView.Renumber(1, 1)

If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
    partslist.Sort("POS")
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.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 10

j.wolbers-NoTech
Enthusiast
Enthusiast

Hi @JelteDeJong 

 

Thanks for your help.
I'm going to test the code tomorrow.

I have one more question ...
Is it possible to check whether the Title Iproperty of the 3D model has been entered while saving a 2D drawing? If this field is empty I would like to get a pop-up with a warning.

Kind regards,
Jeffrey
0 Likes
Message 4 of 10

j.wolbers-NoTech
Enthusiast
Enthusiast

Hi @JelteDeJong 

 

You can forget the above reaction.

 

I have tested your code in 2D drawing.
This works well!!
However, the code does not work in an assembly (see error message below)

 

error 1.PNG

 

I have one more question...

Is it possible to check whether the ''Category'' Iproperty of the 3D model (part or assembly) has been entered while saving a 2D drawing? If this field is empty I would like to get a pop-up with a warning or if possible a form to fill it in. 

 

The reason that this should only be checked when saving a drawing is because the category does not have to be entered for parts of which we do not make a drawing. And the category is only filled in when creating drawings, so we can prevent the message from appearing every time when saving a 3D part or assembly.

Kind regards,
Jeffrey

 

0 Likes
Message 5 of 10

JelteDeJong
Mentor
Mentor
Accepted solution

i found a bug in the code (in the first line). It should be fixed in the code below.

 

Dim doc As Document = ThisDoc.Document
Dim partslist As PartsList
Dim aDoc As AssemblyDocument

If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
    Dim dDoc As DrawingDocument = ThisDoc.Document
    partslist = dDoc.ActiveSheet.PartsLists.Item(1)
    aDoc = partslist.ReferencedDocumentDescriptor.ReferencedDocument
Else
    aDoc = doc
End If

Dim BOM As BOM = aDoc.ComponentDefinition.BOM
BOM.StructuredViewEnabled = True

Dim oBOMView As BOMView = BOM.BOMViews("Structured")

oBOMView.Sort("BOM Structure", True, "Vendor", False)
oBOMView.Renumber(1, 1)

If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
    partslist.Sort("POS")
End If

  about your second question. I would have been better if you started a new topic for that. So other people can find a solution more easy. but any way this is how you could do it.

Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)
Dim refDoc As Document = view.ReferencedDocumentDescriptor.ReferencedDocument


Dim category As String = iProperties.Value(refDoc.DisplayName ,"Summary", "Category")

If (String.IsNullOrWhiteSpace(category)) Then
	Dim newCategory = InputBox("What is the category", "Title here", "Default Entry")
	iProperties.Value(refDoc.DisplayName ,"Summary", "Category") = newCategory
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.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 10

j.wolbers-NoTech
Enthusiast
Enthusiast

Hi @JelteDeJong 

 

Thanks a lot for your help!

 

Unfortunately, this code gives an error when saving a 2D drawing of a part. In this way I cannot automatically run the rule for all 2D drawings. Is there anything that can be done about this?

 

 

Error in rule: Rule3, in document: 34694.idw

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.AssemblyDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D465-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: Interface wordt niet ondersteund (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

 

 

 

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.AssemblyDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D465-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: Interface wordt niet ondersteund (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at ThisRule.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

 

The second iLogic code works perfectly. Thanks

 

Kinds regards,

Jeffrey

0 Likes
Message 7 of 10

j.wolbers-NoTech
Enthusiast
Enthusiast

Hi,

 

Is there someone else who could possibly help me fix this?

I will appreciate it very much.

 

Kinds regards,

Jeffrey

 

 

0 Likes
Message 8 of 10

JelteDeJong
Mentor
Mentor

Sorry i missed the follow up question. does this work for you?

Dim doc As Document = ThisDoc.Document
Dim partslist As PartsList
Dim aDoc As AssemblyDocument

If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
    Dim dDoc As DrawingDocument = ThisDoc.Document
    partslist = dDoc.ActiveSheet.PartsLists.Item(1)
    aDoc = partslist.ReferencedDocumentDescriptor.ReferencedDocument
Else If (doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then
    aDoc = doc
Else
	Return
End If

If (aDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject)
	Return
End If

Dim BOM As BOM = aDoc.ComponentDefinition.BOM
BOM.StructuredViewEnabled = True

Dim oBOMView As BOMView = BOM.BOMViews("Structured")

oBOMView.Sort("BOM Structure", True, "Vendor", False)
oBOMView.Renumber(1, 1)

If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
    partslist.Sort("POS")
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.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 9 of 10

j.wolbers-NoTech
Enthusiast
Enthusiast

Hi,

 

This still gives an error.


I have now solved it together with a colleague and it now works.
Maybe not in the most beautiful way but it works;)

 

Dim doc As Document = ThisDoc.Document
Dim partslist As PartsList
Dim oPartsList As partslist
Dim aDoc As AssemblyDocument
Dim pDoc As PartDocument
Dim typeDoc As String, typeint As String



typeint = doc.DocumentType

If typeint = "12291" Then typeDoc = "Assembly"
If typeint = "12292" Then typeDoc = "Drawing"
If typeint = "12290" Then typeDoc = "Part"
	
	

If typeDoc = "Part" Then Exit Sub
	
If typeDoc = "Drawing" Then
	Dim dDoc As DrawingDocument = ThisDoc.Document
	If dDoc.ActiveSheet.PartsLists.Item(1).PartsListRows.Count = 1 Then Exit Sub
End If


If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
	Dim dDoc As DrawingDocument = ThisDoc.Document
    partslist = dDoc.ActiveSheet.PartsLists.Item(1)
    aDoc = partslist.ReferencedDocumentDescriptor.ReferencedDocument
Else
    aDoc = doc
End If

Dim BOM As BOM = aDoc.ComponentDefinition.BOM
BOM.StructuredViewEnabled = True

Dim oBOMView As BOMView = BOM.BOMViews("Structured")

oBOMView.Sort("BOM Structure", True, "Vendor", False, "Authority", True )
oBOMView.Renumber(1, 1)

If (doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject) Then
    partslist.Sort("POS")
End If

 

Thanks for your help.

0 Likes
Message 10 of 10

AMN3161
Advocate
Advocate

i am also very new to logic but i am very shocked on how helpful this community is.

 

No one is getting paid for offering their help but some of the heavy hitting logic people are so helpful. You will reconize their names quickly

0 Likes