<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using ilogic to search subname in partnumber in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11175319#M138195</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5836695"&gt;@koenroovers&lt;/a&gt;.&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; You can give this rule a try if you want.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;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&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 17 May 2022 18:04:06 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2022-05-17T18:04:06Z</dc:date>
    <item>
      <title>Using ilogic to search subname in partnumber</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11171756#M138132</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my first post on the forum, i've looked around but i couldnt find the answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;We use partnumbers that are a mix of letters and numbers. Example:&lt;/P&gt;&lt;P&gt;651-004-WA001&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This partnumber will show in the partslist. Now i want to make an ilogic that only shows WA numbers in the partslist.&lt;/P&gt;&lt;P&gt;I've come to this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;' Set a reference to the drawing document.&lt;/SPAN&gt;
&lt;SPAN&gt;' This assumes a drawing document is active.&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingDocument&lt;/SPAN&gt;
&lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;
    
&lt;SPAN&gt;' Set a reference to the first parts list on the active sheet.&lt;/SPAN&gt;
&lt;SPAN&gt;' This assumes that a parts list is on the active sheet.&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oPartList&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;PartsList&lt;/SPAN&gt;
&lt;SPAN&gt;oPartList&lt;/SPAN&gt; = &lt;SPAN&gt;oDrawDoc&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveSheet&lt;/SPAN&gt;.&lt;SPAN&gt;PartsLists&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(1)
   
&lt;SPAN&gt;' Iterate through the contents of the parts list.&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;i&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Long&lt;/SPAN&gt;
&lt;SPAN&gt;For&lt;/SPAN&gt; &lt;SPAN&gt;i&lt;/SPAN&gt; = 1 &lt;SPAN&gt;To&lt;/SPAN&gt; &lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Count&lt;/SPAN&gt;
&lt;SPAN&gt;'look at only the part number column&lt;/SPAN&gt;
&lt;SPAN&gt;oCell&lt;/SPAN&gt;  = &lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;i&lt;/SPAN&gt;).&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"Part Number"&lt;/SPAN&gt;)
	&lt;SPAN&gt;'look at iproperty value&lt;/SPAN&gt;
	&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oCell&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt; = &lt;SPAN&gt;""&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt; 
		&lt;SPAN&gt;'show the row&lt;/SPAN&gt;
		&lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;i&lt;/SPAN&gt;).&lt;SPAN&gt;Visible&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;
	&lt;SPAN&gt;Else&lt;/SPAN&gt;
		&lt;SPAN&gt;'hide the row&lt;/SPAN&gt;
		&lt;SPAN&gt;oPartList&lt;/SPAN&gt;.&lt;SPAN&gt;PartsListRows&lt;/SPAN&gt;.&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;i&lt;/SPAN&gt;).&lt;SPAN&gt;Visible&lt;/SPAN&gt; = &lt;SPAN&gt;False&lt;/SPAN&gt;
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
&lt;SPAN&gt;Next&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;But a i dont know how to filter on the WA section of the partslist. (xxx-xxx-WAxxx)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can somebody help me?&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 12:38:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11171756#M138132</guid>
      <dc:creator>koenroovers</dc:creator>
      <dc:date>2022-05-16T12:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using ilogic to search subname in partnumber</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11171932#M138134</link>
      <description>&lt;P&gt;Dim Test As String&lt;BR /&gt;Test = "12-123-WA123"&lt;/P&gt;
&lt;P&gt;If InStr(1, Test, "WA") &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;Debug.Print "Found"&lt;BR /&gt;Else&lt;BR /&gt;Debug.Print "Not Found"&lt;/P&gt;
&lt;P&gt;End If&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 13:42:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11171932#M138134</guid>
      <dc:creator>Hochenauer</dc:creator>
      <dc:date>2022-05-16T13:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using ilogic to search subname in partnumber</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11172044#M138137</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5836695"&gt;@koenroovers&lt;/a&gt;.&amp;nbsp; If I am understanding the need/want correctly, you want to leave any parts list rows visible only if the part number contains "WA", right?&amp;nbsp; If so, I believe you can just change this one line as follows:&lt;/P&gt;
&lt;P&gt;Change this:&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oCell&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt; = "" &lt;SPAN&gt;Then&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;to this:&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oCell&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;.&lt;SPAN&gt;Contains&lt;/SPAN&gt;(&lt;SPAN&gt;"WA"&lt;/SPAN&gt;) &lt;SPAN&gt;Then&lt;/SPAN&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 14:21:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11172044#M138137</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-05-16T14:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using ilogic to search subname in partnumber</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11172131#M138140</link>
      <description>&lt;P&gt;Here is another little bit of iLogic/vb.net code you might find useful/informational in a situation like this:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oPN As String = "651-004-WA001"
Dim oLastPart As String = oPN.Split("-").Last
MsgBox("oLastPart = " &amp;amp; oLastPart, , "")
If oLastPart.StartsWith("WA") Then
	MsgBox("oLastPart.StartsWith(""WA"") = True", , "")
Else
	MsgBox("oLastPart.StartsWith(""WA"") = False", , "")
End If&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 16 May 2022 14:49:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11172131#M138140</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-05-16T14:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using ilogic to search subname in partnumber</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11173635#M138168</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;This worked like a charm!&lt;BR /&gt;However i am looking for a little more functionality. Is it possible to group the assemblies that are in different sub assemblies?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So for example part list below is now filtered on WA parts. But WA103 is used in multiple assemblies. The partlist is structured (legacy). Therefore it will show 2 different positions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="koenroovers_0-1652768600224.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1068066iA558A49BA8B52E54/image-size/medium?v=v2&amp;amp;px=400" role="button" title="koenroovers_0-1652768600224.png" alt="koenroovers_0-1652768600224.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 06:24:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11173635#M138168</guid>
      <dc:creator>koenroovers</dc:creator>
      <dc:date>2022-05-17T06:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using ilogic to search subname in partnumber</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11175319#M138195</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5836695"&gt;@koenroovers&lt;/a&gt;.&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; You can give this rule a try if you want.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;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&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 17 May 2022 18:04:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/using-ilogic-to-search-subname-in-partnumber/m-p/11175319#M138195</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-05-17T18:04:06Z</dc:date>
    </item>
  </channel>
</rss>

