Notifications
Clear all

[Closed] CustAttributes Help

I’m currently dealing with adding custattributes to objects in a scene. I can create / add the cust attribute fine, but the problem I’m having is that I can’t figure out how to have the script check to see if the attribute is already declared in the scene, so everytime I run the script it adds another custattribute to the scene… so custattributes.getscenedefs() will keep getting bigger and bigger and bigger… not what I want.

global scenedef = true
   sceneattrib = custattributes.getscenedefs()
   	for o in sceneattrib do
   	(
   		if (matchpattern o.name pattern:"*asset*" ) then 
   		(
   			Print "Asset Def Found... continuing."
   			scenedef = true
   			exit
   		)
   		else if ((matchpattern o.name pattern:"*asset*" ) == false) then
   		(
   			Print "Asset Def not found."
   			scenedef = false
   		)
   	)
   	
   	if scenedef == false then
   	(
   		global addassetdata = attributes assetdata
   			(
   			parameters data
   				(
   				Asset type:#string
   				)
   			)
   			print "Adding Scene Def"
   		
   	)
   
2 Replies
 eek

local object = $point01

if object.testca == undefined do
(
testca = attributes testAttributes
(

)
custAttributes.add testca object #unique
)

Or just get the count of custAttributes of the object, if its larger than 0 add it if not dont:

if (custAttributes.getDefs object).count < 1 do
(
– add your custom attribute here.
)

Thanks for the help! I decided to go with including the custattr. in startup, so I will just check to see if it’s added to the objects or not, like you suggested.