iLogic to Read & Use an iPart Table Value

iLogic to Read & Use an iPart Table Value

arkelec
Collaborator Collaborator
930 Views
5 Replies
Message 1 of 6

iLogic to Read & Use an iPart Table Value

arkelec
Collaborator
Collaborator

I want to read & use the value from a specific column in the iPart Table for the current iPart member.

Having spent an hour trying to understand the structure/syntax, I'm at a loss.

 

By way of example, how to read & use the text in the 'Member' column for the currently selected iPart member?

 

I want to read that value & add some additional text.  The adding of text I can do, but I can't see how to get the value from the Table.

 

Is it correct to say that 'Member' is a Project iProperty (as opposed to a Custom iProperty)?

 

Thanks in advance.

 

0 Likes
931 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @arkelec.  Member is the 'Heading' of an iPartTableColumn within the iPartTable that you get from the iPartFactory object.  It is not a regular iProperty, because there is a different value in each row of the table.  If you were in an iPart 'member' file, then there would only be one value...the name of the 'member' you have open.  Below is an example of getting to one of these cells within the table, when working from the iPart factory document.  This is just getting the first row in the table, not looping through every row in the table.  This is almost identical to navigating the ModelStatesTable, and similar to navigating a PartsList in a drawing.

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oFactory As iPartFactory = oPDef.iPartFactory
Dim oRow As iPartTableRow = oFactory.TableRows.Item(1)
Dim oCell As iPartTableCell = oRow.Item("Member") '"Member" is the Heading of the iPartTableColumn
Dim oMember As String = oCell.Value
MsgBox("oMember = " & oMember, vbInformation, "iPart Row Member")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Michael.Navara
Advisor
Advisor

Here is small sample how to access the iPart table values for specific instance

 

Dim occ As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick iPart occurrence")

Dim isiPartMember As Boolean = occ.IsiPartMember
If Not isiPartMember Then
	Logger.Warn("This is not an iPart member")
	Return
End If

Dim partDef As PartComponentDefinition = occ.Definition
Dim iPartTableRow As iPartTableRow = partDef.iPartMember.Row

'Direct access to MemberName
Dim memberName = iPartTableRow.MemberName
Logger.Info("MemberName: " & memberName)

'Access to all row values
Dim rowValues As New List(Of String)
rowValues.Add("Cell values:")
For Each cell As iPartTableCell In iPartTableRow
	rowValues.Add(String.Format("[{0}] - {1}", Cell.Column, Cell.Value))
Next

Logger.Info(String.Join(vbCrLf, rowValues))
0 Likes
Message 4 of 6

arkelec
Collaborator
Collaborator

Thanks @WCrihfield

 

What is the syntax for accessing the other columns in the Table?

The original from your post:

 

Dim oCell As iPartTableCell = oRow.Item("Member")

 

 

Here's a section of the Table showing some of the headings:

iPart Table.png

 

Replacing "Member" in the code below with one of the other Table column headings results in an error:

 

Dim oCell As iPartTableCell = oRow.Item("Part Number")
Dim oCell As iPartTableCell = oRow.Item("c_Part_Nº")
Dim oCell As iPartTableCell = oRow.Item("Stock Number")

 

 

This is the full code (I changed line 4 to use the member selected):

 

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oFactory As iPartFactory = oPDef.iPartFactory
Dim oRow As iPartTableRow = oFactory.DefaultRow
Dim oCell As iPartTableCell = oRow.Item("c_Part_Nº") '"Member" is the Heading of the iPartTableColumn
Dim oMember As String = oCell.Value
MsgBox("oMember = " & oMember, vbInformation, "iPart Row Member")

 

 

 

And also thanks @Michael.Navara 

As you can see from my question above, I'm still struggling a bit on the structure & how the function works.

I'll try your code once I've understood the issue above.

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Hi @arkelec.  The best way to see what you need to see and understand it better is to right-click on the iPart factory table in your model browser tree, then select 'Edit via Spreadsheet...' option.  Within that spreadsheet you can see that when a column for an iProperty is present, it has extra text to the right of its name, like "Part Number [Project]", instead of just "Part Number".  That extra text is the short iLogic version of the PropertySet name that the iProperty is associated with (the name you would specify when using the iLogic shortcut snippet 'iProperties.Value()'), but within brackets.  That is one little complication to keep in mind.  What really sucks in this case is that the iPartTableColumns.Item property will only accept an Integer as input, instead of a String, so you would have to use a 'For Each' or 'For i As Integer = 1 To #' type loop to loop through the columns, to check which one you have.  So, if you need to work with specific columns, and maybe don't want to specify that odd name, you might want to include a loop of the columns, and check if the Heading of the column .StartsWith() a specific name for each one before using it as needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Here is another similar exploratory iLogic rule you can play around with.  In this example, the oRow.Item() property is looking for either an Index Integer or the iPartTableColumn.Heading value as the input to specify which cell in that row you want.  What you see in the regular iPart table dialog for the column headers is like the value of the iPartTableColumn.DisplayHeading property value, but that can be different from the iPartTableColumn.Heading property value, which includes the extra stuff.

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oFactory As iPartFactory = oPDef.iPartFactory
Dim oRow As iPartTableRow = oFactory.DefaultRow
Dim oCols As iPartTableColumns = oFactory.TableColumns
For Each oCol As iPartTableColumn In oCols
	Dim oCell As iPartTableCell = oRow.Item(oCol.Heading)
	Dim oValue As String = oCell.Value 'the Value is always a String
	'oCol.DisplayHeading, oCol.FormattedHeading, oCol.Heading, oCol.Index
	MsgBox("Column DisplayHeading = " & oCol.DisplayHeading & vbCrLf & _
	"Column Heading = " & oCol.Heading & vbCrLf & _
	"Column Index = " & oCol.Index & vbCrLf & _
	"Cell.Value = " & oCell.Value, vbInformation, "iPart Table Data")
	If oCol.DisplayHeading = "Part Number" Then
		MsgBox("This member's Part Number is:  " & oCell.Value,,"")
	End If
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes