Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Custom iProperties add to selected parts

kresh.bell
Collaborator

Custom iProperties add to selected parts

kresh.bell
Collaborator
Collaborator

I have this iLogic which works great for me. I add a description in the assembly environment by selecting the parts. When I'm done click escape.

 

Dim oOccurrence As ComponentOccurrence

msg = "Select a component (press ESC to exit)"
While True
	oOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, msg)

	' If nothing gets selected then we're done	
	If IsNothing(oOccurrence) Then Exit While

	oName = oOccurrence.Name

	ThisApplication.ActiveDocument.selectset.select(oOccurrence)
	oDesc = iProperties.Value(oName, "Project", "Description")
	oDesc = InputBox(oName & " Description", "iLogic", oDesc)
	If Not oDesc = Nothing Then iProperties.Value(oName, "Project", "Description") = oDesc

End While

 


I am interested in whether it is possible to first create a custom iproperty (in case it does not exist) and then add a value to it in the same way in the assembly environment. The name custom iLogic does not need to be created through the toolbox, through iLogic is perfectly fine.
If it is possible to use the same iLogic also in a part environment, that would be really great

0 Likes
Reply
Accepted solutions (2)
486 Views
7 Replies
Replies (7)

Michael.Navara
Advisor
Advisor
Accepted solution

You need just to wrap property value obtaining to Try-Catch. 

 

Dim oOccurrence As ComponentOccurrence

msg = "Select a component (press ESC to exit)"
While True
	oOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, msg)

	' If nothing gets selected then we're done	
	If IsNothing(oOccurrence) Then Exit While

	oName = oOccurrence.Name

	ThisApplication.ActiveDocument.SelectSet.Select(oOccurrence)
	oDesc = iProperties.Value(oName, "Project", "Description")
	oDesc = InputBox(oName & " Description", "iLogic", oDesc)
	If Not oDesc = Nothing Then iProperties.Value(oName, "Project", "Description") = oDesc

	'Custom description
	Dim customDesc As String
	Try
		customDesc = iProperties.Value(oName, "Custom", "CustomDescription")
	Catch
		customDesc = ""
	End Try
	customDesc = InputBox(oName & " Custom Description", "iLogic", customDesc)

	If Not customDesc = Nothing Then iProperties.Value(oName, "Custom", "CustomDescription") = customDesc

End While

 

 

0 Likes

kresh.bell
Collaborator
Collaborator

thanks, realy nice

0 Likes

kresh.bell
Collaborator
Collaborator

Hi,

one more thing.

 

Is it possible to make a rule for part envirovment that, when runing, checks if there is a custom property name eg "Sample"? If it does not exist, it will be created. In both cases (exist or no), after that, a small window will open with the possibility to add or change value for that custom property.

0 Likes

Michael.Navara
Advisor
Advisor

This is the same code (lines 17 - 26) without argument oName 

0 Likes

kresh.bell
Collaborator
Collaborator

Uncordiality,

it's not possible select part in part environment

 

Screenshot 2024-04-10 152259.png

0 Likes

Michael.Navara
Advisor
Advisor
Accepted solution

OK 😀

Try this code in part. If you want to change iProperties of the document where you run the rule, you don't need to select anything.

 

'Custom description
Dim customDesc As String
Try
	customDesc = iProperties.Value("Custom", "CustomDescription")
Catch
	customDesc = ""
End Try
customDesc = InputBox("Custom Description", "iLogic", customDesc)

If Not customDesc = Nothing Then iProperties.Value("Custom", "CustomDescription") = customDesc

 

0 Likes

kresh.bell
Collaborator
Collaborator

thanks, it works

0 Likes