ilogic code to display custom iproperty of selected part

ilogic code to display custom iproperty of selected part

Anonymous
Not applicable
2,424 Views
3 Replies
Message 1 of 4

ilogic code to display custom iproperty of selected part

Anonymous
Not applicable

Hi,

 

I would like to be able to select a part/sub-assembly in the assembly environent and then run a rule which displays an iproperty from the selected part/sub-assembly.

 

It's driving me crazy

 

Thanks for any help

 

 
0 Likes
Accepted solutions (1)
2,425 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

This is the code I am using. Everything works except for the last part. Even though I (think) I'm asking for the iproperties of the selected item I only get the iproperties of the top level assembly

 

SyntaxEditor Code Snippet

Dim oOccurrence As ComponentOccurrence
Try
  oOccurrence = ThisDoc.Document.SelectSet.Item(1)
Catch
  MessageBox.Show("Please select a component before running this rule.", "iLogic")
  Return
End Try

Dim doc As Document
Dim Prop As String

'Set the selected item
oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(1)

'get the selected item document occurrence name
doc = oOccurrence.Definition.Document

'get the property'Prop = iProperties.Value(doc:1, "Custom", "Stroke")
Prop = iProperties.Value(doc, "Project", "Part Number")


'Dispaly Property in Msg Box
MessageBox.Show(Prop)
0 Likes
Message 3 of 4

LukeDavenport
Collaborator
Collaborator
Accepted solution

 

Hi David,

 

I think this'll work. We need to refer to the occurrence name, and also be aware that if you have selected an occurrence in a sub-component, then the object you have selected will actually be a 'componentoccurrenceproxy' object, that you need to find the native componentoccurrence from to use the iLogic iProperties line afterwards.

 

SyntaxEditor Code Snippet

Dim oOccurrence As ComponentOccurrence
Dim Prop As String

Try
  oOccurrence = ThisDoc.Document.SelectSet.Item(1)
Catch
  MessageBox.Show("Please select a component before running this rule.", "iLogic")
  Return
End Try

If TypeOf oOccurrence Is ComponentOccurrenceProxy Then
    Prop = iProperties.Value(oOccurrence.NativeObject.Name, "Project", "Part Number")
Else 
    Prop = iProperties.Value(oOccurrence.Name, "Project", "Part Number")
End If

'Display Property in Msg Box
MessageBox.Show(Prop)
Message 4 of 4

Anonymous
Not applicable

Hi Luke,

 

As ever thanks for this solution!

 

David

0 Likes