Setting a slider value from within the code

696
2
07-16-2013 11:35 PM
AleksandarLalovic
New Contributor II
I would like to set the slider value from within the code but then still be able to modify the slider/attribute value manualy affterwards?

Lets say that i have a generic rule which defines several building typologyes. If every typology has a different number of floors i would normaly set the "number_of_floors" attribute within the typology definition to a certain valuey using "set" comand and then extrude.




attr number_of_floors  = 0

Building_type_1 -->

set(number_of_floors, 5)
extrude (floor_height*number_of_floors)
...

Building_type_2 -->

set(number_of_floors, 3)
extrude (floor_height*number_of_floors)
...





This should be just a starting point, showing the defalut settup (default number of floors/height) which you should be able to manually edit using parameters afterwards. But in this case the "number_of_floors" attribute gets assigned a certain value within the code and is not possible to edit it with the slider anymore, ie. the modifying the slider values dont affect the model generation anymore. Is there a way just the set, lets say "user" attribute value and not "rule" value?
Tags (2)
0 Kudos
2 Replies
MatthiasBuehler1
Frequent Contributor
Hi ..

CGA can not dictate the attribute source. CGA gets the attribute values to work with.

==>
the Connection Editor dictates, which value is used. There's just the 4 states 'Rule', 'User', 'Object Attr' [[or 'Mapped']].

So in your case, I'd create a second attribute which dictates the source for your attribute of interest.

E.g.


@Hidden // = generic attribute to transport the info
attr finalValue = 0

@Range ( "Rule", "User", "Object" )
attr useWhichAttr = "Rule"

attr ruleDefaultValue = rand(10,20) // connection : attr source = "rule"

attr userValue = rand(10,20)         // connection : attr source = "user" // = you playing with slider

attr objectAttrValue = 0         // value initialized with 0  // connection : attr source = "object" 


Then :

Lot -->
    case useWhichAttr == "Rule" :
        set(finalValue, ruleDefaultValue )
        GoExtrude
    case useWhichAttr == "User" :
        set(finalValue, userValue ) 
        GoExtrude 
    else :
        set(finalValue, objectAttrValue )
        GoExtrude

GoExtrude -->
    extrude( finalValue )
    Done.



Like this, you control all possibilities.

Ok ?

matt
0 Kudos
AleksandarLalovic
New Contributor II
Good to know. Thanks.
0 Kudos