Create an Instance Property with i-logic

Create an Instance Property with i-logic

Guthery1
Enthusiast Enthusiast
490 Views
2 Replies
Message 1 of 3

Create an Instance Property with i-logic

Guthery1
Enthusiast
Enthusiast

Has anyone figured out how to create instance properties for components in an assembly with i-logic?  I'm trying to create a  tool that will allow me to select multiple components in an assembly and create/fill-in an instance property based on a text pop-up.  I'm not seeing any other examples and I'm not even sure if it's possible.

0 Likes
Accepted solutions (1)
491 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Guthery1.  I did not know if you intended to pre-select the components, or select them after you run the rule, so I designed this rule with pre-selection in mind.  If you run the rule with nothing pre-selected, it will let you know, then exit the rule.  If there is something pre-selected, it will then prompt you to enter the name of the property, then the value for it.  Then it will iterate through the selected items, making sure they are assembly components, then either creating new, or updating existing instance properties in them.

Dim oSS As SelectSet = ThisDoc.Document.SelectSet
If oSS.Count = 0 Then
	MsgBox("Nothing Pre-Selected - exiting rule", vbCritical, "iLogic")
	Return
End If
Dim sPropertyName As String = InputBox("Enter Property Name", "Property Name", "")
If sPropertyName = "" Then Return
Dim oPropertyValue As Object = InputBox("Enter Property Value", "Property Value")
If oPropertyValue Is Nothing Then Return
For Each oObj In oSS
	If TypeOf oObj Is ComponentOccurrence Then
		Dim oOcc As ComponentOccurrence = oObj
		oOcc.OccurrencePropertySetsEnabled = True
		Dim oPropSet As PropertySet = oOcc.OccurrencePropertySets.Item(1)
		Dim oProp As Inventor.Property = Nothing
		Try
			oProp = oPropSet.Item(sPropertyName)
		Catch
			oProp = oPropSet.Add(oPropertyValue, sPropertyName)
		End Try
		If oProp IsNot Nothing AndAlso oProp.Value <> oPropertyValue Then
			Try : oProp.Value = oPropertyValue : Catch : End Try
		End If
	End If
Next 'oObj

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

Guthery1
Enthusiast
Enthusiast

This worked brilliantly.  Thanks for the assistance. 

0 Likes