Notifications
Clear all

[Closed] rollout CA would not hold

When I run the help script weaponDataCA the value selected from the dropdownlist would not hold, as soon as I deselect the sphere it goes back to “boom”. Is this CA not supposed to be saved with the node?

weaponDataCA = attributes weaponData
(
 parameters main rollout:params
 (
 hitPoints type:#float ui:hits default:10
 cost type:#float ui:cost default:100
 sound type:#string 
 )
 rollout params "Weapon Parameters"
 (
 spinner hits "Hit Points" type:#float
 spinner cost "Cost" type:#float
 dropdownlist sound_dd "Sound" items:#("boom", "sparkle", "zap", "fizzle") 
 )
)

custAttributes.add $sphere01 weaponDataCA

Many thanks in advance.

16 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

here is the right way how to work with ‘string’ parameter with fixed number of possible names:


  delete objects
 s = sphere isselected:on
 
 ca = attributes ca
 (
 	parameters main rollout:params
 	(
 		sound type:#integer default:1 ui:ui_sound
 	)
 	fn getSoundName index: = 
 	(
 		if index == unsupplied do index = this.sound
 		if index > 0 then this.params.ui_sound.items[index] else undefined
 	)
 
 	rollout params "Weapon Parameters"
 	(
 		dropdownlist ui_sound "Sound: " items:#("boom", "sparkle", "zap", "fizzle") 
 	)
 )
 custAttributes.add s ca baseobject:on
 /*
 s.sound = 2
 s.getsoundname() 
 $.getsoundname index:3
 */
  

as you see the sound index parameter is linked to ui dropdown control. Any changes in one are reflected automatically in the other (set, undo/redo).
if you need to get a name of current sound, you can make a function as shown above.

The rollout is a dynamic part of the CA-plugin, its created then needed and destroyed after that.
As quick fix (in this case) you can add a code to the rollout open event.

(
	parameters main rollout:params
	(
		...
	)
 
	rollout params "Weapon Parameters"
	(
		...
		on params open do (sound_dd.selection = findItem sound_dd.items sound)
	)
)

Thank you Panayot,

You mentioned that this is a quick fix, can you please further elaborate? What limitations are introduced with this statement?

Thanks again.

1 Reply
(@panayot)
Joined: 11 months ago

Posts: 0

Well, I can’t answer w/o inserting some criticism against the help file.
The CA’s are kind of plugin and that section in the help is prepared for coders whos already done a few plugins. Also a lack of examples there. The only one example (weaponData) is uncompleted and even harmful as it move the peoples in a wrong direction.

Of’cuz the examle can work as is but only if you plan to access/set this parameter (sound) using solely the ui (rollout). If you want to control it from the outside, for ex. from scripted controller, then you’ll meet other limitations (if you follow this example).

1st, If we have a few hard-coded/fixed amount of options to select, then RadioButtons is more suitable, as we can wire RB to the param-block parameter (type #integer) via #ui property.
The DropDownList logical is more eligible for list of items which varied. So, here come a question how and where you will save all changes (add/rem. items) in that list. The DDL items are array holding strings, but you can’t store new items there as they w’d not be saved. And for saving arrays there is ‘tab’ types parameters, in this case #stringTab, and the official example is too far away from this.

Ok, lets say and something positive about the help. I learn almost everything from there (no extra books, tuts or forums), but this take a time, especially for understanding. But you no need to go in the hard way like me, as here you have a lot of discussions about custom attributes, just search in this forum. But if you’re new to maxscript and wish to use CA’s for training, well, I’ll not recommend that.

Thanks a lot for your answer Panayot.
I had a feeling that the help file was not great on this topic (that’s why I posted) but would not say so because yes, I am a beginner.
What if we want to use editText? When I try to do so:

manufacturer type:#string
...
editText manufacturer "Manufacturer: "
...
on manufacturer entered i do manufacturer = manufacturer.text

when entering text I receive the following MAXscript Rollout Handler Exception:
–Runtime error: Cannot directly assign rollout controls: manufacturer

Many thanks in advance for your help.

i would do something like this:


    delete objects
 s = sphere isselected:on
 
 someCA = attributes someCA
 (
 	parameters main rollout:params
 	(
 		sound type:#integer default:1 ui:(ui_soundID, ui_soundName)
 	)
 	
 	fn getSoundName index: = 
 	(
 		if index == unsupplied do index = this.sound
 		if index > 0 then this.params.soundNames[index] else undefined
 	)
 	fn getSoundNames = (copy this.params.soundNames #nomap)
 	
 	rollout params "Weapon Parameters"
 	(
 		local soundNames = #("Boom", "Sparkle", "Zap", "Fizzle")
 		group "Sound: "
 		(
 			spinner ui_soundID "ID: " range:[1,soundNames.count,1] type:#integer fieldwidth:40 offset:[0,-4]
 			dropdownlist ui_soundName "Name: " items:soundNames offset:[0,-4]
 		)
 	)
 )
 custAttributes.add s someCA baseobject:on
 /*
 s.sound = 2
 s.getSoundName() 
 s.getsoundname index:3
 s.getSoundNames()
 */
    
As you see i used an undocumented feature of scripted plug-ins. You can link a parameter to more than one UI controls. Cool, isn't it?

yes, very cool. And thanks for showing this.

Hey denisT,
with the above solution, upon interrogation in regards to the soundtype CA stored value, maxscripts returns numbers:
1 for boom etc…
is there any way to receive the string instead?

Thanks for your advice.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

why do you think i added getSoundName method to the CA?

I am extracting using:

format o.sound

and it returns the number.

more precisely:

for o in $ do format "%,%" (classof o) o.sound
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

what is your problem? the sound parameter in my snippet is type of integer. it’s only way to link it to dropdown ui control. that’s how experienced max script developers handle this kind of property in scripted plug-ins and scripted custom attributes.

I have no problem.
I do have a question though and I do not expect you to answer if you prefer to do so, I would still be grateful for the answers you provided previously on this thread.
the question is:
is there any way to format the corresponding string instead of the integer?

I can do this after writing to an output file with an excel-like software but I was wondering if this can be done within maxscript.

Thanks in advance.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

THE FUNCTION OF CA GETSOUNDNAME DOES DO IT
how many times have i to say it? why am i wasting my time if you are not looking in code and not reading my posts?

Page 1 / 2