Map Attributes from rules

2112
3
04-28-2012 04:38 PM
RobertHexter
New Contributor III
How do I have a cga rule attribute retrieve and use a value from a particular source Layer, if I do not want to set a shapes attribute source manually in the Inspector?(I may want to use different image maps (sources) to control a particular attribute under different rule conditions)

cgaFile - pseudoCode:

attr value=getValueFromLayer(Layer, Layer_Attribute)
attr height=getValueFromLayer("map1", "buildingHeight")

Sorry if this is very obvious, I'm getting lost in the help documentation and the way some of it is written.
0 Kudos
3 Replies
MatthiasBuehler1
Frequent Contributor
hey !

that's easy to do.



just create a new Map Layer of the 'mapping type'. choose your image file and create an attribute in the dialog. once the layer has been generated, you can check (and edit) the layer attributes in the Inspector.

usually, I create mapped attributes based on the image brightness, then create a simple function which maps that value range from 0-1 to a desired range, e.g. 300 x brightness + 20

once this is created, point your CGA rule via the Attribute Connection Editor to the specific layer's target attr value.

don't forget to initialize the attr in your rule too ! (e.g. just attr mappedHeight = 0)

let me know if it works.
0 Kudos
RobertHexter
New Contributor III
Thanks for the reply,

I am confused by this:

point your CGA rule via the Attribute Connection Editor to the specific layer's target attr value.

If I have this initialized in my rule:

attr mappedHeight = 0

how do I:

point your CGA rule via the Attribute Connection Editor

I am currently only understanding this to be a manual process of changing the shapes attribute source input within the Attribute Connection Editor?
I would like to have the rule tell the shape what its specific layer/map and attribute of interest is, not do it myself.


I am confused because I want to, within my rule, have the rule determine the connection to which mapLayer:

//set/connect the shapes "mappedHeight" attribute, to the MapLayers attribute "mappedHeight", where MapLayer is determined by something else..
set(shape.mappedHeight, MapLayer.mappedHeight)
0 Kudos
MatthiasBuehler1
Frequent Contributor
first step : check the following manual page, it shows the Connection Editor basics :

Help > Manual > Mapping Attributes > Mapping Attributes with Connection Editor

[ check the attr icon with the black triangle pointing in a rectangle ]


additionally :
it is important to understand that CityEngine uses some heuristics to find the right connections automatically when a rule is assigned to a shape :

If you assign a rule e.g. to a 'Lot' via Drag'n'Drop, CityEngine checks if :
1st priority] an Object Attr exists for the initialized attrs. If so, the connection automatically is made to the Object Attr
2nd priority] a Map Layer attribute exists for the initialized attrs. If so, the connection automatically is made to the corresponding Map Layer attr
3rd priority] the Rule value is used



I hope this helps you further !

oh, and also good to know, the @StartRule annotation adapts some behavior : Once drag-n-dropped and a StartRule is defined within a cga rule file, the model generation is directly triggered ( great for demos ! ).



let me know if questions remain.
0 Kudos