[Closed] Custom Attribute – Redefine spinner limit?
I have a spinner that is incorporated into a Custom attibute to control the stretch for an object.
The attribute’s spinner has a range in the definition and is applied onto the object.
What i would like is for the attribute to be able to take settings for the stretch range via a user inputed variable.
So, a rollout with min/max stretch spinners then applies a CA def to an object with a stretch value spinner that has a stretch range of [min.value,max.value,0].
I am trying to get my head around this. At the moment im thinking i have to generate the CA def as a string via a function so that i could pass the range values from the min/max spinners into the Def and apply it.
Am i way off here or is there a simpler or more elegant way?
I’d ideally like to be able to use the same function to redefine the spinner later should you want to change the range after applying the def, so each def would actually contain a stretchvalue spinner, and a min, max value spinner also.
I guess if the generate def string function could generate the string for the original def, it has the functionality to return different string for the redefine also.
any thoughts appreciated.
here’s what i’ve come up with so far – adding and redefining are separate functions and the calls are commented out at the end. it seems to be working as i want now, but i still need to test it further for gremlins. you need to have an object selected!
global AttribDefString
fn FormatAttributeString Attminval Attmaxval =
(
(
AttribDefString = stringstream ""
format "attributes Stretchrig
(
parameters StretchControls rollout:StrSettings
(
minstr Type:#float ui:minstr Default:" to:AttribDefString
format (Attminval as string)to:AttribDefString
format "
maxstr Type:#float ui:maxstr Default:" to:AttribDefString
format (Attmaxval as string) to:AttribDefString
format "
Strval Type:#float ui:Strval Default:0.0
" to:AttribDefString
format " )
rollout StrSettings \"Stretchrig Setup\" width:162 height:161
(
" to:AttribDefString
format " spinner minstr \"Min Stretch \" pos:[26,25] width:119 height:16 scale:0.01 " to:AttribDefString
format ("range:[-10,10,"+(Attminval as string)+"]
") to:AttribDefString
format " spinner maxstr \"Max Stretch \" pos:[26,44] width:119 height:16 scale:0.01 " to:AttribDefString
format ("range:[-10,10,"+(Attmaxval as string)+"]
") to:AttribDefString
format " spinner Strval \"Stretch Value \" pos:[22,114] width:127 height:16 scale:0.01 " to:AttribDefString
format ("range:[" + (Attminval as string) + "," + (Attmaxval as string) + "," + "0]
") to:AttribDefString
format " GroupBox grpbxLimit \"\" pos:[10,14] width:142 height:73
" to:AttribDefString
format " GroupBox grp1 \"\" pos:[10,-4] width:142 height:22
" to:AttribDefString
format " GroupBox grp2 \"\" pos:[10,105] width:142 height:28
" to:AttribDefString
format " GroupBox grp3 \"\" pos:[10,84] width:142 height:22
" to:AttribDefString
format " label lblSset \"Stretch Settings\" pos:[43,91] width:80 height:14
" to:AttribDefString
format " label lblLimitSet \"Limit Setup\" pos:[56,3] width:60 height:14
" to:AttribDefString
format " button Redef \"Redefine Limits\" pos:[16,64] width:129 height:19
on Redef pressed do (redefinethedef this.minstr this.maxstr)
)
)
" to:AttribDefString
)
seek AttribDefString 0
return AttribDefString
)
fn applythedef minv maxv =
(
AttribDefString = ""
generatetheDef = FormatAttributeString minv maxv
defholder = execute AttribDefString
try(custAttributes.delete $ 1)catch()
custAttributes.add $ defholder
)
fn redefinethedef minv maxv =
(
olddef = custAttributes.getDef $ 1
newdefstring = FormatAttributeString minv maxv
custAttributes.redefine olddef newdefstring
)
--testing
--applythedef -0.5 2.2
--redefinethedef -0.35 1.12
couldn’t you just do the range adjustment like Paul mentioned some threads before:
[path_to_spinner].range = [newmin, newmax, 0]
?
I must admit I don’t see the need for rewriting the CA here – but I don’t know the dependencies.
speaking of dependecies:
If you had linked some controllers to the spinners/control you would need to relink them after updating the definition, wouldn’t you?
Georg
hi georg, thanks for your reply. I had read that and your suggestion was what i tried first before i went down this route. Problem is that with the property change Strval.range =[minval,maxval,0] method, this works fine, until you deselect the object and reselect – it reloads the original CAdef and you lose the limits. Unless i’m missing something, im redefining the def, not rewriting it, so you wont lose any dependancies as you aren’t changing the controller. In my case its not a big issue as the controls that acces the CAdef data will be generated on the fly – the def will be bound to a slider in a control rollout so that will be done when that opens.
In any case – my function is useful because i can have custom limits for a load of objects and apply them at the same time, with the limits i pass along with the function call.
yes, I forgot about this fact. having a internal linkage to update the spinnerranges after (re-)selection might be much more work. Though we could store them in a variable floattab and update them on rollout open.
I have to take another look into redefining, until now my controller links always broke.
Georg