Create a list of predefined instance properties to preselected items using i logic

Create a list of predefined instance properties to preselected items using i logic

mark_brennan2
Explorer Explorer
154 Views
4 Replies
Message 1 of 5

Create a list of predefined instance properties to preselected items using i logic

mark_brennan2
Explorer
Explorer

Hi, can anyone help?

I have a list of instance properties that I need to add to components within an assembly.

At the moment I have to type them in each time which is inefficient.  The properties have a unique value to be added manually.  Is this possible using i logic?

The properties are listed below.

Plant_No

Room_No

System

System_Group

 

Thanks for any help

0 Likes
Accepted solutions (1)
155 Views
4 Replies
Replies (4)
Message 2 of 5

C_Haines_ENG
Collaborator
Collaborator

Maybe something like this would work? Its not the most elegant solution ever, but it does work. You also don't have to preselect the components, but if you would like to have that as a feature I can tweak the code pretty easily.

 

Sub Main

	Dim oAsm As AssemblyDocument = ThisDoc.Document

	Dim oNames As New List(Of String)
	oNames.AddRange({"Plant_No", "Room_No", "System", "System Group" })

	Do

		Dim oComp As ComponentOccurrence = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select Component")
		If oComp Is Nothing Then Exit Sub
		Dim oCustomProps As PropertySet = oComp.Definition.Document.PropertySets("Inventor User Defined Properties")

		For Each oName As String In oNames
			Try
				oCustomProps(oName).Value = oCustomProps(oName).Value
			Catch
				oCustomProps.Add("", oName)
			End Try
				Dim oAsk As String = InputBox("Current Component : " & oComp.Name & vbLf & vbLf _
				& "Enter value for : " & oName, "iProp Customizer", oCustomProps(oName).Value)
				If oAsk = "" Then Exit Sub
				
				oCustomProps(oName).Value = oAsk
		Next

	Loop

End Sub
0 Likes
Message 3 of 5

mark_brennan2
Explorer
Explorer

Thanks for your help.

I have run the rule and it works well.

could this ilogic be made to create instance properties instead of iproperties.

 

Regards

Mark

0 Likes
Message 4 of 5

C_Haines_ENG
Collaborator
Collaborator

Ah, I misunderstood. To be honest I had no clue Instance Properties were a thing until your post! This new code should work:

Sub Main

	Dim oAsm As AssemblyDocument = ThisDoc.Document

	Dim oNames As New List(Of String)
	oNames.AddRange({"Plant_No", "Room_No", "System", "System Group" })

	Do

		Dim oComp As ComponentOccurrence = ThisApplication.CommandManager.Pick(kAssemblyLeafOccurrenceFilter, "Select Component")
		If oComp Is Nothing Then Exit Sub
		'Dim oCustomProps As PropertySet = oComp.Definition.Document.PropertySets("Inventor User Defined Properties")

		For Each oName As String In oNames
			Try
				iProperties.InstanceValue(oComp.Name, oName) = iProperties.InstanceValue(oComp.Name, oName)
			Catch
				iProperties.InstanceValue(oComp.Name, oName) = ""
			End Try
			
				Dim oAsk As String = InputBox("Current Component : " & oComp.Name & vbLf & vbLf _
				& "Enter value for : " & oName, "iProp Customizer", iProperties.InstanceValue(oComp.Name, oName))
				If oAsk = "" Then Exit Sub
				
				iProperties.InstanceValue(oComp.Name, oName) = oAsk
				
		Next

	Loop

End Sub

 

0 Likes
Message 5 of 5

mark_brennan2
Explorer
Explorer
Accepted solution

That worked perfectly.  Thanks very much for your time and effort.

 

Regards

 

Mark