Inventor General Discussion

Inventor General Discussion

Reply
Valued Contributor
dclunie
Posts: 70
Registered: ‎03-26-2008
Message 1 of 5 (600 Views)
Accepted Solution

Parts list sort Using Ilogic

600 Views, 4 Replies
11-07-2011 06:35 AM

I have got some ilogic code that i have patched together to sort my parts list in inventor which works great but it will not update all sheets at the same time as when we design we have multiple sheets with parts list on and the odd one without.

 

Can anyone help me to add to this code to update all sheets partlists and also recognise that some sheets will not have partslists on so this will need to skip. 

 

 

below is code that is used to sort

 

Format:HTML Format Version:1.0 StartHTML:     165 EndHTML:    4558 StartFragment:     314 EndFragment:    4526 StartSelection: 314 EndSelection:     314
SyntaxEditor Code Snippet

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 4558 StartFragment: 314 EndFragment: 4526 StartSelection: 314 EndSelection: 314
SyntaxEditor Code Snippet

'parts list sort Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oPartsList1 As PartsList oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1) oPartsList1.Sort("MATERIAL", 0, "L", 0, "W", 0) 'oPartsList1.Sort("ITEM", 1, "DESCRIPTION", 1, "QTY", 1) oPartsList1.Renumber oPartsList1.SaveItemOverridesToBOM
iLogicVb.UpdateWhenDone = True ThisApplication.ActiveView.Fit

 

 

 

Try this code, it works for me anyway.  Currently only sorts by part number but does so on every sheet and skips sheets without a partlist on them.  Hope this helps.

 

On Error Resume Next
Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
Dim Sheet As Inventor.Sheet
Dim Cursheet As String
     Cursheet = oDrawDoc.ActiveSheet.Name
    
For Each oSheet In oDrawDoc.Sheets
        oSheet.Activate
Dim oPartsList As PartsList
    oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
        If Not oPartsList Is Nothing Then
         Resume Next
    Call oPartsList.Sort("ITEM")
End If
    Next
   

Many thanks  for the code it works great i have added some other areas to be sorted in vb and added additional lines to take you back to sheet 1 and update active view on all sheets .

 

On Error Resume Next
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim Sheet As Inventor.Sheet
Dim Cursheet As String
Cursheet = oDrawDoc.ActiveSheet.Name
For Each oSheet In oDrawDoc.Sheets
oSheet.Activate
Dim oPartsList As PartsList
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
If Not oPartsList Is Nothing Then
Resume Next
'Call oPartsList.Sort("ITEM")
Call oPartsList.Sort("PART NUMBER", 1, "DESCRIPTION", 1, "QTY", 1)
iLogicVb.UpdateWhenDone = True
ActiveSheet = ThisDrawing.Sheet("Sheet:1")
ThisApplication.ActiveView.Fit
End If
Next

 

Employee
MartinBernat
Posts: 29
Registered: ‎08-30-2011
Message 2 of 5 (587 Views)

Re: Parts list sort Using Ilogic

11-07-2011 08:27 AM in reply to: dclunie

Hi,

you're using DrawingDocument.ActiveSheet and its PartLists property (Item(1)) - this means you're sorting just the first partlist on the active sheet.

In order to do a sort on all partlists on all sheets you should iterate over DrawingDocument.Sheets property and then Sheet.PartLists property on each sheet. That means you should have 2 nested "for" loops.

 

Let me know if you need more advice. You can write me an email at martin (dot) bernat (at) autodesk (dot) com.

 

Thanks for your question.

 

Martin Bernat

Autodesk

Valued Contributor
dclunie
Posts: 70
Registered: ‎03-26-2008
Message 3 of 5 (574 Views)

Re: Parts list sort Using ilogic

11-07-2011 11:43 AM in reply to: MartinBernat

Hi Martin

 

Thanks for the response but as I have very little knowledge of manipulating code I am to be honest struggling to achieve as explained in reply.

 

Would it be possible to show me some pasted code with the appropriate modified code so I can better understand where I'm going wrong.

 

Sorry to be cheeky but I am not experienced enough .

 

Regards

 

Dave

 

'parts list sort
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort("PART NUMBER", 1, "DESCRIPTION", 1, "QTY", 1)
'oPartsList1.Sort("ITEM", 1, "DESCRIPTION", 1, "QTY", 1)
oPartsList1.Renumber
oPartsList1.SaveItemOverridesToBOM

iLogicVb.UpdateWhenDone = True
ThisApplication.ActiveView.Fit

 

Valued Mentor
coreyparks
Posts: 497
Registered: ‎06-07-2010
Message 4 of 5 (562 Views)

Re: Parts list sort Using ilogic

11-07-2011 12:05 PM in reply to: dclunie

Try this code, it works for me anyway.  Currently only sorts by part number but does so on every sheet and skips sheets without a partlist on them.  Hope this helps.

 

On Error Resume Next
Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
Dim Sheet As Inventor.Sheet
Dim Cursheet As String
     Cursheet = oDrawDoc.ActiveSheet.Name
    
For Each oSheet In oDrawDoc.Sheets
        oSheet.Activate
Dim oPartsList As PartsList
    oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
        If Not oPartsList Is Nothing Then
         Resume Next
    Call oPartsList.Sort("ITEM")
End If
    Next
   

Please mark this response "Accept as solution" if it answers your question.
-------------------------------------------------------------------------------------
Corey Parks
IV2014 Factory Design Suite Ultimate
Windows 7 64 bit
Synergis Adept document management software
16gb RAM --- Nvidia Quadro 4000 2gb
Valued Contributor
dclunie
Posts: 70
Registered: ‎03-26-2008
Message 5 of 5 (553 Views)

Re: Parts list sort Using ilogic

11-07-2011 10:36 PM in reply to: coreyparks

Many thanks  for the code it works great i have added some other areas to be sorted in vb and added additional lines to take you back to sheet 1 and update active view on all sheets .

 

On Error Resume Next
Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
Dim Sheet As Inventor.Sheet
Dim Cursheet As String
     Cursheet = oDrawDoc.ActiveSheet.Name
    
For Each oSheet In oDrawDoc.Sheets
        oSheet.Activate
Dim oPartsList As PartsList
    oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
        If Not oPartsList Is Nothing Then
         Resume Next
    'Call oPartsList.Sort("ITEM")
	Call oPartsList.Sort("PART NUMBER", 1, "DESCRIPTION", 1, "QTY", 1)
iLogicVb.UpdateWhenDone = True
ActiveSheet = ThisDrawing.Sheet("Sheet:1")
ThisApplication.ActiveView.Fit


End If
    Next

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.