Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: koenroovers

Hi @koenroovers.  I assume that by "group the assemblies" that are the same but on different lines you mean combine their quantities into one line, then get rid of the other row (or all other rows), not just move the rows to be next to each other.  So, I think I have some more advanced iLogic code that may accomplish that task for you, but I haven't tested it yet myself.  You can give this rule a try if you want.

Sub Main
	Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oPartList As PartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
	Dim oUniquePNRows As New Dictionary(Of String, PartsListRow)
	'get Part Number column
	Dim oPNCol As PartsListColumn = GetPartNumberColumn(oPartList)
	If IsNothing(oPNCol) Then
		MsgBox("Part Number Column Not Found.", vbExclamation, "")
		Exit Sub
	End If
	'get Quantity column
	Dim oQtyCol As PartsListColumn = GetQuantityColumn(oPartList)
	If IsNothing(oQtyCol) Then
		MsgBox("Quantity Column Not Found.", vbExclamation, "")
		Exit Sub
	End If

	For Each oRow As PartsListRow In oPartList.PartsListRows
		Dim oPN As String = oRow.Item(oPNCol).Value 'Part Number
		If oPN.Contains("WA") Then 
			oRow.Visible = True
		Else
			oRow.Visible = False
		End If
		If Not oUniquePNRows.ContainsKey(oPN) Then
			oUniquePNRows.Add(oPN, oRow)
		Else
			'the Dictionary already contains a 'Row' with that Part Number
			'so, value is not unique, so combine its quantity with
			'previous row that had same cell value, then hide this row
			'first get previous row with this cell value
			oPreviousRow = oUniquePNRows.Item(oPN)
			Dim oPreviousRowQuantity As Integer = CInt(oPreviousRow.Item(oQtyCol).Value)
			Dim oThisRowQuantity As Integer = CInt(oRow.Item(oQtyCol).Value)
			oPreviousRow.Item(oQtyCol).Value = (oPreviousRowQuantity + oThisRowQuantity).ToString
			'oRow.Remove 'only works for custom rows
			oRow.Visible = False
		End If
	Next
End Sub

Function GetPartNumberColumn(oPList As PartsList) As PartsListColumn
	If IsNothing(oPList) OrElse oPList.PartsListColumns.Count = 0 Then Return Nothing
	For Each oCol As PartsListColumn In oPList.PartsListColumns
		If oCol.PropertyType = PropertyTypeEnum.kFileProperty Then
			Dim oPropSetID As String
			Dim oPropID As Integer
			oCol.GetFilePropertyId(oPropSetID, oPropID)
			If oPropSetID = "{32853F0F-3444-11d1-9E93-0060B03C1CA6}" And _
				oPropID = 5 Then
				Return oCol
			End If
		End If
	Next
	Return Nothing
End Function

Function GetQuantityColumn(oPList As PartsList) As PartsListColumn
	If IsNothing(oPList) OrElse oPList.PartsListColumns.Count = 0 Then Return Nothing
	For Each oCol As PartsListColumn In oPList.PartsListColumns
		If oCol.PropertyType = PropertyTypeEnum.kQuantityPartsListProperty Then
			Return oCol
		End If
	Next
	Return Nothing
End Function

Wesley Crihfield

EESignature

(Not an Autodesk Employee)