Quantcast
Channel: From the Trenches with Autodesk Inventor
Viewing all articles
Browse latest Browse all 61

iLogic: Custom Sort PartsList with Temporary Column

$
0
0

 



Issue: 

You have a parts list that has a challenging sort criteria, due to needing to sort for values that might or might not exist in the same column. 

In the example above we want to sort the description column based on all items with a mark number (MK) value, and then sort those without a mark number alphabetically.



Solution:

Although we can't accomplish this out of the box, here is a code example to this that using iLogic and some API calls.


sSortColumnName = "KEYWORDS"

' Set a reference to the drawing document.
' This assumes a drawing document is active.
DimoDrawDocAsDrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the first parts list on the active sheet.
DimoPartsListAsPartsList
Try
oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
Catch
Return'exit rule
EndTry

DimoADocAsAssemblyDocument
oADoc = oPartsList.ReferencedDocumentDescriptor.ReferencedDocument
DimoPropSetAsPropertySet
oPropSet = oADoc.PropertySets.Item("Inventor Summary Information")

'add temporary column to the parts list
oID = oPropSet.Item(sSortColumnName).PropId
Try
oPartsList.PartsListColumns.Add _
(PropertyTypeEnum.kFileProperty, oPropSet.InternalName, oID)
Catch
EndTry

' Iterate through the contents of the parts list.
DimiAsLong
Fori = 1 TooPartsList.PartsListRows.Count

'get the Description value
oCell = oPartsList.PartsListRows.Item(i).Item("DESCRIPTION")

'split the string at the comma
'expecting a string like:
' Bracket, MK B-114
sArray = Split(oCell.Value, ",")
sType = sArray(0)

Try
sMK = sArray(1)
Catch'error when no comma in string
sMK = ""
EndTry


'get the temp column cell
oTempColumnCell = oPartsList.PartsListRows.Item(i).Item(sSortColumnName)

'write to temp column
IfsMK.Contains("MK") Then
'strip off the MK
sMK = Replace(sMK, "MK ", "")
oTempColumnCell.Value = sMK
Else
oTempColumnCell.Value = sType
EndIf
Next

'sort and renumber
oPartsList.Sort(sSortColumnName)
oPartsList.Renumber
'remove temp column
oPartsList.PartsListColumns(sSortColumnName).remove

Viewing all articles
Browse latest Browse all 61

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>