Notifications
Clear all

[Closed] Quick custom attributes question

I swear I’ve done this before, but it’s been a while and now I can’t seem to find it anywhere.

I have added a rollout with a slider to one of the objects in my scene via custom attributes, and it works fine. Now, I want to add the /same/ rollout to another object. I had /thought/ that simply doing it like this would work:

box01 = box name:"Box01"
box02 = box name:"Box02" pos:[50,0,0]

CA_Box = attributes attr
(
	parameters params_Box rollout:RO_Box
	(
		param_Size	type:#float animatable:on ui:slider_Size default:25
	)

	rollout RO_Box "Box Size"
	(
		slider slider_Size "Size" range:[10,40,25]

		on slider_Size changed val do
		(
			for b in #(box01, box02) do b.height = b.length = b.width = val
		)
	) -- end rollout
)

custAttributes.add box01 CA_Box
custAttributes.add box02 CA_Box

Now, moving the slider on either of the boxes will change the size of both boxes, as the script would indicate. HOWEVER, if you move the slider on one box and then click on the other, the slider values are different. I want the sliders to be more like “instances”, whereas now they are “copies”.

What do I need to add and/or change in order to get this to work?

7 Replies
custAttributes.add box01 (createInstance CA_Box name:"CA_Box")
custAttributes.add box02 (createInstance CA_Box name:"CA_Box")

not tested but it is something like this.

Tested it, got the following:

-- Error occurred in anonymous codeblock; filename: C:\Users\Malkalypse\Desktop\IKFK_Rig\; position: 492; line: 25
-- Type error: custAttributes.add requires MSCustAttribDef, got: attr:attr
-- Error occurred in anonymous codeblock; filename: C:\Users\Malkalypse\Desktop\IKFK_Rig\; position: 527; line: 26
-- Type error: custAttributes.add requires MSCustAttribDef, got: attr:attr

Looking in the documentation, I don’t see anything indicating that createInstance can be used for anything besides geometry…

2 Replies
(@feranti)
Joined: 11 months ago

Posts: 0

Yes you can.

appendifunique box01.custAttributes (createInstance CA_Box name:"CA_Box")
-- or on the baseobject
appendifunique box01.baseobject.custAttributes (createInstance CA_Box name:"CA_Box")
(@malkalypse)
Joined: 11 months ago

Posts: 0

I get exactly the same results from that that I get from using custAttributes.add

That worked for the example I posted here, but for some reason it’s not working when I try to apply it to the scene I’m working on. I guess one of the other functions I have running must be getting in the way… ><

Thanks for the help though!

The link is only bi-directional for the selected box so you need to change the param_Size of the other box as well as its L,W,H.

box01 = box name:"Box01"
box02 = box name:"Box02" pos:[50,0,0]

CA_Box = attributes attr
(
	parameters params_Box rollout:RO_Box
	(
		param_Size	type:#float animatable:on default:25 ui:slider_Size 
	)

	rollout RO_Box "Box Size"
	(
		slider slider_Size "Size" range:[10,40,25]

		on slider_Size changed val do
		(
			for b in #(box01, box02) do b.height = b.length = b.width = b.param_Size = val
		)
	) -- end rollout
)

custAttributes.add box01 CA_Box
custAttributes.add box02 CA_Box

here is how to add the same instance of a CA to multiple nodes:


 attr = attributes attr
 (
 	parameters params rollout:params
 	(
 		value type:#float ui:ui_value
 	)
 	rollout params "Parameters" 
 	(
 		slider ui_value width:150
 	)
 )
 delete objects
 b0 = box pos:[15,0,0] wirecolor:red
 b1 = box pos:[-15,0,0] wirecolor:blue
 
 a = createinstance attr
 append b0.baseobject.custattributes a
 append b1.baseobject.custattributes a
 
 

Hey Denis, thanks for the help once again x)

Now that I actually see it, it makes perfect sense!


EDIT: And more importantly than making sense, it actually works