Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic code to display custom iproperty of selected part

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
DRLTKSE
2231 Views, 3 Replies

ilogic code to display custom iproperty of selected part

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

 

 
3 REPLIES 3
Message 2 of 4
DRLTKSE
in reply to: DRLTKSE

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)
Message 3 of 4
LukeDavenport
in reply to: DRLTKSE

 

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
DRLTKSE
in reply to: LukeDavenport

Hi Luke,

 

As ever thanks for this solution!

 

David

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report