i = MessageBox.Show("Do you wish to Renumber & Sort BOM?", "My iLogic Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) If i = vbyes Then Trace.WriteLine ("INV - Transfer; User Selection; Do you wish to Renumber & Sort BOM? - YES") 'Renumbers & Sort BOM oPartsList1.Renumber oPartsList1.SaveItemOverridesToBOM oPartsList1.Sort("ITEM") Trace.WriteLine ("INV-ExternalRule - Renumber & Sort BOM#") Else if i = vbno Trace.WriteLine ("INV - Transfer; User Selection; Do you wish to change Renumber & Sort BOM? - NO") End if
what am i doing wrong?
what i want to do, is renumber the BOM by (001) then go to part list and sort by item.
Have not debugged your code, below is my sort, maybe you can extract something usefull from it?
On Error Resume Next
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oPartsList As PartsList
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
If Not oPartsList Is Nothing Then
Call oPartsList.Sort("ITEM")
End If
I've had a look at this aswell as I think it is quite useful. I've attached the code I've been using for you to try, it seems to work for me.
Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oPartsList As PartsList oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1) i = MessageBox.Show("Do you wish to Renumber & Sort BOM?", "My iLogic Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) If i = vbYes Then Trace.WriteLine ("INV - Transfer; User Selection; Do you wish to Renumber & Sort BOM? - YES") 'Renumbers & Sort BOM oPartsList.Renumber oPartsList.SaveItemOverridesToBOM oPartsList.Sort("ITEM") Trace.WriteLine ("INV-ExternalRule - Renumber & Sort BOM#") Else If i = vbNo Trace.WriteLine ("INV - Transfer; User Selection; Do you wish to change Renumber & Sort BOM? - NO") End If On Error Resume Next If Not oPartsList Is Nothing Then Call oPartsList.Sort("ITEM") End If
Mike
I hope I've understoos what you were trying to do with this. My work flow with it is to order my parts list on the drawing as required and then let the code renumber the bom accordingly.
Mike
The way we usually do it here;
1. go to BOM, renumber from there with the start # @ (001).
2. Go to Parts List and sort by #.
I will try your code, and see what happens.
I succeeded in getting the part list to overide the BOM, but is there any BOM functions that we can use instead of partslist?
Great!
working so far..
i really really want to renumber the parts by 001,002,003.etc.. not 1,2,3.etc.... any ideas?
In pursuit of all my inventor problems I need to know what are all the funstions i can call in ilogic to get the BOM to do things for me.
If you provide something as simple as opening the BOM through ilogic, i can figure out all the rest.
any ideas?
Thanks!
Hi m.teleguz1,
If I understand correctly, you can just write to the ITEM cells as an override, and then save the item overrides to the assembly BOM.
Here is a quick example that first sorts the BOM by the PART NUMBER column, then steps through the ITEM column and sets the override value starting with 001, and then finally writes the overrides to the BOM.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
' Set a reference to the first parts list on the active sheet.
' This assumes that a parts list is on the active sheet.
Dim oPartsList As PartsList
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
'sort by named column in ascending order
oPartsList.Sort("PART NUMBER", 1)
Dim i As Integer
i = 1
' Iterate through the contents of the parts list.
Dim oRow As PartsListRow
For each oRow in oPartsList.PartsListRows
'look at only the ITEM column
oCell = oPartsList.PartsListRows.Item(i).Item("ITEM")
'write to the target cell
'formats correctly up to 099 rows
oCell.Value = If(i < 10, "00" + CStr(i), "0" + CStr(i))
i = i+1
Next
'save new item numbers to assembly BOM
oPartsList.SaveItemOverridesToBOM
This code basically runs that rule individually for each cell...really takes a long time when you have 81 rows.
Thank you for the code, that is way more than enough for me to go by and reverse learn what you did there. Hopefully with some patience and time i can figure something else out.
Hi,
I get some errors when I tried to run these Ilogic
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
' Set a reference to the first parts list on the active sheet.
' This assumes that a parts list is on the active sheet.
Dim oPartsList As PartsList
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
'sort by named column in ascending order
oPartsList.Sort("PART NUMBER", 1)
Dim i As Integer
i = 1
' Iterate through the contents of the parts list.
Dim oRow As PartsListRow
For each oRow in oPartsList.PartsListRows
'look at only the ITEM column
oCell = oPartsList.PartsListRows.Item(i).Item("ITEM")
'write to the target cell
'formats correctly up to 099 rows
oCell.Value = If(i < 10, "00" + CStr(i), "0" + CStr(i))
i = i+1
Next
'save new item numbers to assembly BOM
oPartsList.SaveItemOverridesToBOM
The errors are:
error message
Error in rule: Testirule3, in document: LED-seinä ehdotus.idw
Määrittämätön virhe. (Exception from HRESULT: 0x80004005 (E_FAIL))
More info
System.Runtime.InteropServices.COMException (0x80004005): Määrittämätön virhe. (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.PartsList.Sort(String PrimaryColumnTitle, Boolean PrimaryColumnAscending, String SecondaryColumnTitle, Boolean SecondaryColumnAscending, String TertiaryColumnTitle, Boolean TertiaryColumnAscending)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Could sombody help me? I am so noob 😞
Hi
I am also a noob, so I did not debug your error message. What I did do was compare your code to mine. The only difference is the renumber section.
I don't have the Counter, and item number rename. If I may ask what are you trying to achive, that is not already there, I might have missed it.
Therefore give the following a try:
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
' Set a reference to the first parts list on the active sheet.
' This assumes that a parts list is on the active sheet.
Dim oPartsList As PartsList
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
'sort by named column in ascending order
oPartsList.Sort("PART NUMBER", 1)
'save new item numbers to assembly BOM
oPartsList.SaveItemOverridesToBOM
Apologies, I missed a step.
See new code
Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oPartsList As PartsList oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1) oPartsList.Sort("PART NUMBER",1) oPartsList.Renumber oPartsList.SaveItemOverridesToBOM