IDW Parts list sorting with I logic

IDW Parts list sorting with I logic

Ikruse
Contributor Contributor
3,621 Views
21 Replies
Message 1 of 22

IDW Parts list sorting with I logic

Ikruse
Contributor
Contributor

Hello all,

 

I am looking to setup an I logic rule to sort our parts list. I would like it to be in alpha numerical order by "part number", and then re arrange the "item" column in numerical order from 1-20 and so on. Is there anyone on here who can provide me the rule for this? I have found parts of this code online but nothing that meets this requirement. I would like to set this rule up on our active sheet template.

 

Any help in this matter would be greatly appreciated!

 

Thank you in advance!

 

Isaac Kruse

 

0 Likes
Accepted solutions (3)
3,622 Views
21 Replies
Replies (21)
Message 2 of 22

mdavis22569
Mentor
Mentor

...So if  have this right ..

 

1) put Part numbers in numerical/alphabetical order

2) Renumbers items

 

If I rearrange the Items, then I would lose my Numerical/Alphabetical order ...

 

 

 


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------
Mike Davis

EESignature

0 Likes
Message 3 of 22

Curtis_Waguespack
Consultant
Consultant

Hi Ikruse,

 

Here is a quick iLogic rule that I think will meet your needs.

 

 Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)
'use 1 to sort ascending order. 
'use 0 to sort descending order. 
oPartsList1.Sort("PART NUMBER", 1)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM

 

Related links:

http://inventortrenches.blogspot.com/search/label/Sort%20Parts%20List

http://forums.autodesk.com/t5/inventor-general-discussion/ilogic-to-sort-bom-renumber-and-sort-parts...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 4 of 22

Ikruse
Contributor
Contributor

Curtis,

 

I have added the provided code to my template. Attached is the error I am seeing. Also I have attached a screen shot of the rule in our active template.

 

Do you know what is wrong?

 

Thank you,

 

Isaac

0 Likes
Message 5 of 22

Curtis_Waguespack
Consultant
Consultant

Hi Ikruse,

 

It looks like the last two lines have run together. Try changing the line that reads:

 

oPartsList1.RenumberoPartsList1.SaveItemOverridesToBOM

 

to two lines that read:

 

oPartsList1.Renumber

oPartsList1.SaveItemOverridesToBOM

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 6 of 22

Ikruse
Contributor
Contributor

Curtis,

 

I made the change you suggested. Here is a detailed description of the error.

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

at Inventor.PartsLists.get_Item(Int32 Index)

at LmiRuleScript.Main()

at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

There is no parts list on the active template, could this be the problem? I have attached a view of our standard idw template.

 

Thanks,

 

Isaac

0 Likes
Message 7 of 22

MechMachineMan
Advisor
Advisor
Yes.

Add in an if statement around your code to check that it exists ie;

stuff that goes here.PartsLists.Count > 0
'Code in here
Else
MsgBox("No partslist found")
End if

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 8 of 22

MechMachineMan
Advisor
Advisor
More info on the error you got (ForwardCallToInvokeMember)

http://coderelief.net/2011/08/20/vsto-com-exception-0x800a01a8/

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 22

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Ikruse wrote: 

There is no parts list on the active template, could this be the problem?

 


Hi Ikruse,

 

Yep, I think that's the issue. Here's a quick version of what I posted previously with the addtion of a TRY/CATCH.

 

So basically this will allow the rule to try to sort the parts list, and if one is not found, it simply returns (bails out).

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

 Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oPartsList1 As PartsList
Try oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)   'use 1 to sort ascending order.   'use 0 to sort descending order.   oPartsList1.Sort("PART NUMBER", 1)   oPartsList1.Renumber   oPartsList1.SaveItemOverridesToBOM Catch   'Catch error when no parts list found   Return End Try

 

 

Note also, that there is still a typo, as shown:

 

Redline.png

EESignature

0 Likes
Message 10 of 22

Ikruse
Contributor
Contributor

Curtis,

 

It finally works. Now that it works I tested it on a new print, and it works fine. However on previously drawn prints it does not show up as a rule. Is there a way to push this to old drawings? Also is there a way to better trigger this rule such as Control+1 for example?

 

Here is the code as of now.

 

Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument  Dim oPartsList1 As PartsListTry oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)oPartsList1.Sort("PART NUMBER", 1) oPartsList1.Renumber   oPartsList1.SaveItemOverridesToBOMCatch   Return End Trytrigger = iTrigger0

 

Is there any training videos I could buy to learn more about I logic? Or any online classes or books?

 

Thank you for your help thus far! Looking forward to your response.

 

Isaac

 

0 Likes
Message 11 of 22

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi Ikruse,

 

I would suggest creating this iLogic rule as an external rule, an then using the Before Save Document event trigger to automatically run the rule anytime the file is saved.

 

iLogic External Rules:

http://autodeskmfg.typepad.com/blog/2012/01/working-with-external-ilogic-rules.html

 

iLogic Event Triggers:

http://help.autodesk.com/view/INVNTOR/2014/ENU/?guid=GUID-9369AEB8-F01A-4865-812D-14B21AA4AA22

 

Ilogic Information and tutorials :

http://help.autodesk.com/view/INVNTOR/2014/ENU/?guid=GUID-BEBDED71-ED75-4329-ADBA-2E5DDCCF8DE8

http://help.autodesk.com/view/INVNTOR/2014/ENU/?guid=GUID-2B4A8270-D1F5-4CF7-BEB3-7B12E9CF78F3

http://help.autodesk.com/view/INVNTOR/2014/ENU/?guid=GUID-9BAF2360-FC00-499C-A710-9D7988B2CFFB

 

There is some information on the Inventor API here:

http://inventortrenches.blogspot.com/2013/10/ilogic-how-to-learn-inventors.html?utm_source=BP_recent

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 12 of 22

ankurGCK9S
Contributor
Contributor

Hi , I have tried the codes. It does not give the error but it is not sorting my part list. I like to sort part list alphanumerically. 

 

0 Likes
Message 13 of 22

johnsonshiue
Community Manager
Community Manager

Hi! What release of Inventor are you on? If you are on 2017 and later, the alpha sort should be available in the Sort dialog in the PartsList. Edit the PartsList -> click on Sort -> expand the dialog -> select "Sort by string." Please try it and see if it works for you.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 14 of 22

ankurGCK9S
Contributor
Contributor

Hi Johnson ,

 

thank you for the reply . I am on   2019, however I like to sort the partlist with illogic (Link with trigger on save or something else ) the BOM as well.

0 Likes
Message 15 of 22

rhasell
Advisor
Advisor

Hi

The only reasons the code wont work are due to the following:

 

- There is a typo in your code

- Your parts list does not contain a column of 'PART NUMBER"

             example of mine:

oPartsList1.Sort("COST CENTER",1,"TYPE", 1, "STOCK NUMBER", 1)

- There is more than one Parts List on your drawing, the code will sort the first parts list on your drawing.

 oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)

Change the (1) as needed.

 

Other than that, the code should work as expected.

Can you share some additional information so that we can get it resolved.

Perhaps a dummy drawing with a parts list, or some screen captures of your data.

 

Reg
2026.1
Message 16 of 22

ankurGCK9S
Contributor
Contributor

Thanks for the reply  . I have fix the code with correct name and it works perfectly.  I use multiple part lists in the drawing. for example  - showing pipe lengths , or connection point between two drawings. 

I have copy the same rule to sort as per the CN#  in the second part list and it works ok . I am guessing sequence number of partlist is depend on the sequence of creation of the part list in the drawing. 

 

Now Is there any way that I can hide certain rows in the part list if it contain certain string !! for example , In the attached screen shot , on the first part list  (Bottom RHS) I am hiding  all the CN# , while on the second part list (ont top side)  I am hiding all the rows except CN# . it is tedious task specially when you add something in the assembly and forget to hide or show!!  hope I have not make too much confusing. 

 

 

0 Likes
Message 17 of 22

rhasell
Advisor
Advisor

Hi

 

Well in that case, try this. (Adjust your code to suit.)

 

This will as you for the parts list you wish to sort.

 

Sub Main
'Choose the parts list, 1 is the first one placed.
oPRTL = InputBox("Choose the Parts List", "Parts List Filter", "1")

'Once done, call the sort and pass the Parts List number through.
Call Sort(oPRTL)

End Sub

Sub Sort(oPRTL)
On Error Resume Next
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(oPRTL)
'Remove any "Purchesed item" filters on the parts list
oPartsList1.Style = oDrawDoc.StylesManager.PartsListStyles.Item("Parts List")
oPartsList1.Sort("COST CENTER",1,"TYPE", 1, "STOCK NUMBER", 1) ' Sort
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM 'Save Back the the assembly
End Sub
Reg
2026.1
0 Likes
Message 18 of 22

rhasell
Advisor
Advisor

I have just written some code to step though the parts list and look for a keyword.

 

Mine expands the list, so I will have to look a little to see if I can change the behavior to change the visibility of items.

 

I can share the code, if you are willing to debug it and change it to suit your environment?

 

Reg
2026.1
0 Likes
Message 19 of 22

rhasell
Advisor
Advisor

Hi

 

Try this. I have modified my code to suit, I tested it and it works. You should be able to adjust the variables as needed.

 

You might not need the row counter, my previous code changes the size of the parts list, so it had to update real-time to accommodate the increase in size.

 

 

Sub Main()
'Title: Parts List Row visibily
'Date: 02/05/2019
'Reg Hasell
'This rule checks the Parts List sequence number
'Looks for as set string E.G. "PLATE"
'If found, it will hide the Parts list row
'This will continue untill the entire parts list has been exposed.
'Caveat:
'I am unable to expand the parts list. This must be done manually.
'--oOo--
'Get the Parts list Sequence Number
oPRTL = InputBox("Choose the Parts List", "Parts List Filter", "1")
'Once done, call the sort and pass the Parts List number through.
Call oQTY(oPRTL)
End Sub
'--------------------------------
Sub oQTY(oPRTL)
	'On Error Resume Next
	' Set a reference to the drawing document.
	' This assumes a drawing document is active.
	Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisApplication.ActiveDocument
	Dim oPartList As PartsList
	'''---------------------
	' Set a reference to the first parts list on the active sheet.
	'Dim oPartList As PartsList
	'expand the parts list
	oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(oPRTL)
	' Iterate through the contents of the parts list.
	Dim i As Long
	Dim oRow As PartsListRow
	'Start counting the parts list rows
	'as the parts list grows due to expansion, the row counter will increase.
	Dim FirstRowCount As Integer = oPartList.PartsListRows.Count
	Dim LastRowCount As Integer = 0
	'
	Do Until FirstRowCount = LastRowCount
		FirstRowCount = oPartList.PartsListRows.Count ' Included in the loop.
		For i = 1 To oPartList.PartsListRows.Count
			'look for the cell titled "Description"
			'oCell = oPartList.PartsListRows.Item(i).Item("DESCRIPTION")
			oCell = oPartList.PartsListRows.Item(i).Item("TYPE")
			'oCell2  = oPartList.PartsListRows.Item(i).Item("LENGTH") ' left this for possible later use.

			Try
				If oCell.Value = "PLATE" Or oCell.Value = "plate" Then
					'oPartList.PartsListRows.Item(i).Expanded = True
					oPartList.PartsListRows.Item(i).Visible = False
					End If
			Catch ex As Exception
			End Try
		Next
		'Count the new size of the Parts List
		LastRowCount = oPartList.PartsListRows.Count
	Loop

	MessageBox.Show("All Done", "BOM QTY")
	'End Sub 'Added the repeat for multiple parts lists
	oAgain = MessageBox.Show("Again", "Rinse and Repeat", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) 'Added rev2
	If oAgain = vbYes
		AGAIN
	End If
End Sub

Sub AGAIN
	Main
End Sub
Reg
2026.1
Message 20 of 22

ankurGCK9S
Contributor
Contributor

Hi,

 

Thank you for providing codes . I have changed to my requirement works however it work only if string specified in rule meets exactly to the part list . For my case there are several CN numbers , CN-1 to CN50. I want to hide all raws which part number contain CN. 

 

I have done below changes in your codes . May be I am thinking to add custom property for CNs and use it to hide the rows. After that hide that property manually from part list . Do you know the code to hide the part list coloum ? 

'
Do Until FirstRowCount = LastRowCount
FirstRowCount = oPartList.PartsListRows.Count ' Included in the loop.
For i = 1 To oPartList.PartsListRows.Count
'look for the cell titled "PART No."
oCell = oPartList.PartsListRows.Item(i).Item("PART No.")

Try
If oCell.Value = "CN-18" Or oCell.Value = "cn-18" Then
'oPartList.PartsListRows.Item(i).Expanded = True
oPartList.PartsListRows.Item(i).Visible = False
End If
Catch ex As Exception
End Try
Next
'Count the new size of the Parts List
LastRowCount = oPartList.PartsListRows.Count

0 Likes