Find rowvalue of a specific column in iPart table with iLogic

Find rowvalue of a specific column in iPart table with iLogic

Daan_M
Collaborator Collaborator
1,598 Views
8 Replies
Message 1 of 9

Find rowvalue of a specific column in iPart table with iLogic

Daan_M
Collaborator
Collaborator

Hello!

 

As the title suggests im looking to extract the value of a certain column of an iPart inside my assembly.

I have 5 iParts inside my assembly, i just need the column value of the active row of one of the five iParts, I see snippet;

 

iPart.CurrentRowValue("columnName")

 

It seems to me i need to to assign this to a certain iPart, because now it is just a general piece of code. i'm basically looking for something like this...

 

 

iPart.CurrentRowValue('iPartname, "columnName")

 

 

 

0 Likes
Accepted solutions (1)
1,599 Views
8 Replies
Replies (8)
Message 2 of 9

JhoelForshav
Mentor
Mentor

Hi @Daan_M 

You can use the iPartMember object in your occurrence definition like this 🙂

 

'Get the Component Occurrence in your Assembly
Dim oOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick iPart.")

If oOcc.IsiPartMember 'Just a check
Dim oMember As iPartMember = oOcc.Definition.iPartMember
MsgBox(oMember.Row.Item("columnName").Value) 'The row value
Else
	MsgBox("Not an iPart-member")
End If

 

Message 3 of 9

Daan_M
Collaborator
Collaborator

Hey Jhoel! 

 

Thanks for the reply, i'm sure this is a fitting solution. However i used ComponentOccurence earlier in my code to suppress and unsupress some iParts;

 

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oOcc As ComponentOccurrence

For Each oOcc In oAsmDoc.ComponentDefinition.Occurrences

If oOcc.Name.StartsWith("occ")Then
oOcc.Suppress
End If

'etc etc unsupress

 

i get the error; "Rule Compile Errors in WormwielMotor3D, in wormwielconfiguratorv1.iam

Error on Line 92 : Local variable 'oOcc' is already declared in the current block."

 

which makes sense but i'm too much of a noob to figure out how to solve this haha

 

 

0 Likes
Message 4 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

oOcc is just a variable name set by you. You can call it anything 😄

 

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

If SomethingElseThanoOcc.IsiPartMember 'Just a check
Dim oMember As iPartMember = SomethingElseThanoOcc.Definition.iPartMember
MsgBox(oMember.Row.Item("columnName").Value) 'The row value
Else
	MsgBox("Not an iPart-member")
End If
Message 5 of 9

Daan_M
Collaborator
Collaborator

It works! But i need one last thing.

Instead of picking manually by mouseclick i want to assign the part automatically (since this will be a automated model). It's always the same part 

 

So i guess i need to change the "Pick" part?

ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "oTypeKast")

 

 

0 Likes
Message 6 of 9

Daan_M
Collaborator
Collaborator

Adjusted it a bit to the code below that worked, thanks!

Dim iPartOcc As ComponentOccurrence
For Each iPartOcc In oAsmDoc.ComponentDefinition.Occurrences
If iPartOcc.IsiPartMember And iPartOcc.Name.Equals("oTypeKast")
Dim oMember As iPartMember = iPartOcc.Definition.iPartMember
MsgBox(oMember.Row.Item("AsDiameterKast").Value) 'The row value
Else
	MsgBox("Not an iPart-member")
End If
Next
0 Likes
Message 7 of 9

JhoelForshav
Mentor
Mentor

I think the easiest way in your case would be to use oAsm.ComponentDefinition.ItemByName.

Dim iPartOcc As ComponentOccurrence = oAsmDoc.ComponentDefinition.Occurrences.ItemByName("NameOfTheIpart")

If iPartOcc.IsiPartMember 'Just a check
Dim oMember As iPartMember = iPartOcc.Definition.iPartMember
MsgBox(oMember.Row.Item("columnName").Value) 'The row value
Else
	MsgBox("Not an iPart-member")
End If

Just make sure you have manually renamed the iPart-occurrence in the assembly tree. Otherwise the name will change whenever you change the iPart-row 🙂 You can of course name it whatever you want.

nameIpart.PNG

 

EDIT: I see you fixed it yourself while i wrote this (Y)

Message 8 of 9

Daan_M
Collaborator
Collaborator

It works fine on my laptop. I pack n go the assembly to a desktop PC and when i run the rule i get the following error message;

 

"System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.iPartMember.get_Row()
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"

 

It is caused by the code i added that you suggested, also the slightly adjusted solution i gave gives the same error, any idea what causes this?

 

your latest code

 

 

Dim iPartOcc As ComponentOccurrence = oAsmDoc.ComponentDefinition.Occurrences.ItemByName("NameOfTheIpart")

If iPartOcc.IsiPartMember 'Just a check
Dim oMember As iPartMember = iPartOcc.Definition.iPartMember
MsgBox(oMember.Row.Item("columnName").Value) 'The row value
Else
	MsgBox("Not an iPart-member")
End If

 

 

 

My slightly adjusted version since i already used Occurences earlier;

 

 

'If oOcc.Name = "oTypeKast" Then
'Dim oMember As iPartMember = oOcc.Definition.iPartMember
'oND = oMember.Row.Item("AsDiameterKast").Value'The row value
'End If

 

 

EDIT; I think it might have to do with the Office version of Excel, the Embedded file is a 1997-2003 workbook. (on both my laptop and desktop i use Inventor 2021)

 

0 Likes
Message 9 of 9

JhoelForshav
Mentor
Mentor

Hi @Daan_M 

In the code i posted:

Dim iPartOcc As ComponentOccurrence = oAsmDoc.ComponentDefinition.Occurrences.ItemByName("NameOfTheIpart")

If iPartOcc.IsiPartMember 'Just a check
Dim oMember As iPartMember = iPartOcc.Definition.iPartMember
MsgBox(oMember.Row.Item("columnName").Value) 'The row value
Else
	MsgBox("Not an iPart-member")
End If

 You'll have to change "NameOfTheIpart" to the actual name of the ipart in your assembly-tree