Using ilogic to search subname in partnumber

Using ilogic to search subname in partnumber

koenroovers
Enthusiast Enthusiast
393 Views
5 Replies
Message 1 of 6

Using ilogic to search subname in partnumber

koenroovers
Enthusiast
Enthusiast

Hello Everyone,

 

This is my first post on the forum, i've looked around but i couldnt find the answer. 

We use partnumbers that are a mix of letters and numbers. Example:

651-004-WA001

 

This partnumber will show in the partslist. Now i want to make an ilogic that only shows WA numbers in the partslist.

I've come to this:

 

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
    
' Set a reference to the first parts list on the active sheet.
' This assumes that a parts list is on the active sheet.
Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
   
' Iterate through the contents of the parts list.
Dim i As Long
For i = 1 To oPartList.PartsListRows.Count
'look at only the part number column
oCell  = oPartList.PartsListRows.Item(i).Item("Part Number")
	'look at iproperty value
	If oCell.Value = "" Then 
		'show the row
		oPartList.PartsListRows.Item(i).Visible = True
	Else
		'hide the row
		oPartList.PartsListRows.Item(i).Visible = False
	End If
Next

But a i dont know how to filter on the WA section of the partslist. (xxx-xxx-WAxxx)

 

Can somebody help me?

Kind regards,

 

Koen

0 Likes
Accepted solutions (1)
394 Views
5 Replies
Replies (5)
Message 2 of 6

Hochenauer
Autodesk
Autodesk

Dim Test As String
Test = "12-123-WA123"

If InStr(1, Test, "WA") <> 0 Then
Debug.Print "Found"
Else
Debug.Print "Not Found"

End If



Gerald Hochenauer
Senior Principal Engineer, Inventor
Autodesk, Inc.

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @koenroovers.  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?  If so, I believe you can just change this one line as follows:

Change this:

If oCell.Value = "" Then

to this:

If oCell.Value.Contains("WA") Then

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

Here is another little bit of iLogic/vb.net code you might find useful/informational in a situation like this:

Dim oPN As String = "651-004-WA001"
Dim oLastPart As String = oPN.Split("-").Last
MsgBox("oLastPart = " & oLastPart, , "")
If oLastPart.StartsWith("WA") Then
	MsgBox("oLastPart.StartsWith(""WA"") = True", , "")
Else
	MsgBox("oLastPart.StartsWith(""WA"") = False", , "")
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

koenroovers
Enthusiast
Enthusiast

Hello @WCrihfield 

This worked like a charm!
However i am looking for a little more functionality. Is it possible to group the assemblies that are in different sub assemblies? 

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. 

 

Thanks in advance.

 

koenroovers_0-1652768600224.png

 

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

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)

0 Likes