Notifications
Clear all

[Closed] Multilistbox Custom Attribute

I’m not entirely clear on how the parameters and multilistbox work with one another on custom attributes.
I want to be able to hit append on a button within the custom attribute and it add the item to the listbox.
Just create any object in the scene and run this script. Try to hit the append button. That is where it bugs out.

John


hitDataCA = attributes hitData
(
	parameters main rollout:rlFXHits
	(		
		lbHitTimes type:#stringTab ui:lbHitTimes tabSize:1 tabSizeVariable:true default:"#(1)"
	)

	rollout rlFXHits "Weapon Parameters"
	(
		button btnSliderHit "Append Slidertime" width:110 height:30
		multilistbox lbHitTimes "Active Hit Times:" height:7
		
		on btnSliderHit pressed do
		(
			times = #()
			appendIfUnique times 10
			$.modifiers[1].lbHitTimes.items = times
		)
	)
)

deleteClasses = #(EmptyModifier)
for obj in selection do
(
	for i = obj.modifiers.count to 1 by -1 where findItem deleteClasses (classof obj.modifiers[i]) != 0 do 
	(
		deleteModifier obj obj.modifiers[i]
	)
)

attr = addmodifier $ (EmptyModifier ui:on)
$.modifiers[#Attribute_Holder].name = "FX_Hit"

custAttributes.add $.modifiers[#FX_Hit] hitDataCA

showproperties $.modifiers[1]

13 Replies

So I’ve got the append part working for the listbox.
I for whatever reason can’t get it to save the data to the objects attribute holder. As soon as the user deselects the object and then reselects it, the list is empty?
Could use some help here.

Thanks

John


hitDataCA = attributes hitData
(
	parameters main rollout:rlFXHits
	(		
		etUserHit type:#string ui:etUserHit default:"10"
		lbHitTimes type:#stringTab tabSize:1 tabSizeVariable:true ui:lbHitTimes
	)

	rollout rlFXHits "FX Parameters"
	(
		groupbox gbHitTimes "Hit Times" width:136 height:134
			button btnSliderHit "Append Slidertime" width:110 height:30 pos:[26,30]
			edittext etUserHit "" text:"5,0,50" width:114 pos:[22,70]
			button btnUserHit "Append Times" width:110 height:30 pos:[26,97]
		multilistbox lbHitTimes "Active Hit Times:" height:7 pos:[13,154]
		button btnClear "Clear Active Times" width:136 height:24
		
		on btnSliderHit pressed do
		(
			times = #()
			appendIfUnique times 10
			$.modifiers[1].lbHitTimes.items = times
		)
		
		on btnSliderHit pressed do
		(
			lbHitTimes.items = append lbHitTimes.items (((currentTime as integer)/TicksPerFrame) as string)
		)
	)
)

deleteClasses = #(EmptyModifier, Vol__Select)
for obj in selection do
(
	for i = obj.modifiers.count to 1 by -1 where findItem deleteClasses (classof obj.modifiers[i]) != 0 do 
	(
		deleteModifier obj obj.modifiers[i]
	)
)

addModifier $ (Vol__Select level:2 volume:0)
attr = addmodifier $ (EmptyModifier ui:on)
$.modifiers[#Attribute_Holder].name = "FX_Hit"
$.modifiers[#Vol__Select].Gizmo.scale *= 1.1
$.modifiers[#Vol__Select].Gizmo.controller.Position.controller = position_script()

custAttributes.add $.modifiers[#FX_Hit] hitDataCA


Does anyone know how to get the information to store with the custom attribute.

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

what information do you want to get?

I have a multilistview on an attribute mod which the listview itself stores an array of numbers the user adds to the list by hitting an append button.

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

probably you are talking about a multilistbox…
however the path to some control of a CA rollout is <node>.<attributename>.<rolloutname>.<controlname>
in your case it’s <node>.hitData.rlFXHits.lbHitTimes

I understand how to get the information but when i deselect the object and then reselect it the multilistbox is empty. Which i want it to store the numbers that the user created. For some reason it does not remember the values and resets the list to be empty every time it is deselected.

1 Reply
(@denist)
Joined: 10 months ago

Posts: 0

if a control is not wired to a parameter you have to fill it up yourself using the rollout’s open event for example

why is this pink smile face in the header of my post. i didn’t set it.
edited:
i found the way to remove it. cool!

haha I have no idea, that is pretty funny though.

So here is what I have so far. Just select and object and run this script.
I’m not sure why it is not storing the information so when i click back on the object the values in the listbox still remain there.


hitDataCA = attributes hitData
(
	parameters main rollout:rlFXHits
	(		
		etUserHit type:#string ui:etUserHit default:"10"
		lbHitTimes type:#stringTab tabSize:1 tabSizeVariable:true ui:lbHitTimes
	)

	rollout rlFXHits "FX Parameters"
	(
		groupbox gbHitTimes "Hit Times" width:136 height:134
			button btnSliderHit "Append Slidertime" width:110 height:30 pos:[26,30]
			edittext etUserHit "" text:"5,0,50" width:114 pos:[22,70]
			button btnUserHit "Append Times" width:110 height:30 pos:[26,97]
		multilistbox lbHitTimes "Active Hit Times:" height:7 pos:[13,154]
		button btnClear "Clear Active Times" width:136 height:24
		
		on btnSliderHit pressed do
		(
			times = #()
			appendIfUnique times 10
			$.modifiers[1].lbHitTimes.items = times
		)
		
		on btnSliderHit pressed do
		(
			lbHitTimes.items = append lbHitTimes.items (((currentTime as integer)/TicksPerFrame) as string)
		)
	)
)

deleteClasses = #(EmptyModifier, Vol__Select)
for obj in selection do
(
	for i = obj.modifiers.count to 1 by -1 where findItem deleteClasses (classof obj.modifiers[i]) != 0 do 
	(
		deleteModifier obj obj.modifiers[i]
	)
)

addModifier $ (Vol__Select level:2 volume:0)
attr = addmodifier $ (EmptyModifier ui:on)
$.modifiers[#Attribute_Holder].name = "FX_Hit"
$.modifiers[#Vol__Select].Gizmo.scale *= 1.1
$.modifiers[#Vol__Select].Gizmo.controller.Position.controller = position_script()

custAttributes.add $.modifiers[#FX_Hit] hitDataCA

The information is not stored to the list with the maxfile.

Just do what Denis recommends:
Since you set the listbox indirectely via the buttons, you need to populate it using the “on open” handler of the rollout:

...
 on rlFX open do
 (
 times = this.lbHitTimes as array
 lbHitTimes.item = times
 )

Aight man so bellow you will find a version that works, you were declaring lbHitTimes twice, first as a stringTab parameter, then as a multiListbox they were both under the custAttribute so they are local to it therefore that variable name got declared twice.

I went ahead and changed the parameter name to HitTimes and unassigned the UI item that you had assigned to it. I do not believe you can assign a UI item to a stringTab like you can to a Float or Integer value, in the case of a slider or spinner ( I could be wrong ).

Whenever an item gets appended to the lbHitTimes, I copy it to the HitTimes parameter, I also added a on open event that checks if the stringTab is empty if it is not then it collects the stringTab items into the lbHitTimes.items now it should work like you described.

hope that helps :). commented the script a bit for ya to help !


   hitDataCA = attributes hitData
   (
   	parameters main rollout:rlFXHits
   	(		
   		etUserHit type:#string ui:etUserHit default:"10"
   		HitTimes type:#stringTab tabSize:0 tabSizeVariable:true -- changed the parameter name also changed tabsize to 0 so it would not add an undefined item to the array
   	)
   
   	rollout rlFXHits "FX Parameters"
   	(
   		groupbox gbHitTimes "Hit Times" width:136 height:134
   			button btnSliderHit "Append Slidertime" width:110 height:30 pos:[26,30]
   			edittext etUserHit "" text:"5,0,50" width:114 pos:[22,70]
   			button btnUserHit "Append Times" width:110 height:30 pos:[26,97]
   		multilistbox lbHitTimes "Active Hit Times:" height:7 pos:[13,154]
   		button btnClear "Clear Active Times" width:136 height:24
   		
   		on btnSliderHit pressed do -- BOTH BUTTON EVENTS ARE USING THE SAME HANDLER ???
   		(
   			times = #()
   			appendIfUnique times 10
   			$.modifiers[1].lbHitTimes.items = times
   		)
   		
   		on btnSliderHit pressed do -- BOTH BUTTON EVENTS ARE USING THE SAME HANDLER ???
   		(
   			lbHitTimes.items = append lbHitTimes.items (((currentTime as integer)/TicksPerFrame) as string)
   			HitTimes = lbHitTimes.items-- here we copy the items onto the stringTab
   		)
   		
   		on rlFXHits open do
   		(
   			if HitTimes.count != 0 do -- this makes sure that the stringTab is not empty
   			(
   				lbHitTimes.items = for x in HitTimes collect x -- assigning the stringTab directly gives you an error so we go through and collect everyitem
   			)
   		)
   	)
   )
   
   deleteClasses = #(EmptyModifier, Vol__Select)
   for obj in selection do
   (
   	for i = obj.modifiers.count to 1 by -1 where findItem deleteClasses (classof obj.modifiers[i]) != 0 do 
   	(
   		deleteModifier obj obj.modifiers[i]
   	)
   )
   
   addModifier $ (Vol__Select level:2 volume:0)
   attr = addmodifier $ (EmptyModifier ui:on)
   $.modifiers[#Attribute_Holder].name = "FX_Hit"
   $.modifiers[#Vol__Select].Gizmo.scale *= 1.1
   $.modifiers[#Vol__Select].Gizmo.controller.Position.controller = position_script()
   
   custAttributes.add $.modifiers[#FX_Hit] hitDataCA
   
Page 1 / 2