City Engine Get Object attribute

3030
3
Jump to solution
07-24-2019 07:05 AM
JohnEsther2
New Contributor II

City Engine Get Object attribute to use as the rule default is not working. 

attr streetWidth = getObjectAttr("width")

used to work perfectly but now in ce 2019.0 it is telling me that:

Unused function:streetWidth
No such function: ? getObjectAttr(a:str)

what is the issue?

0 Kudos
1 Solution

Accepted Solutions
CherylLau
Esri Regular Contributor

getObjectAttr() does not work in cga rule files.  It is meant to only work in layer attribute code, which you can see in the Inspector when selecting a layer.  Code can be manually entered here, but it is more likely that it will be automatically entered here when connecting rule attributes to layer attributes.

L R's suggestion is a good way of getting values from an object attribute into a rule attribute with a different name.  I would go with this.  However, I want to describe another method so that I can give an example of how getObjectAttr is used.

Another way of doing this would be to connect your rule attribute to the object attribute through the layer.  Click on the drop down box next to your rule attribute in the Inspector and select Connect Attribute.

Then, connect through a layer attribute, and select the layer and name of the object attribute.

Then, if you select the layer, you'll see that the Layer Attributes section in the Inspector contains the code:

attr a = getObjectAttr("b")

Note: getObjectAttr() will most likely be deprecated soon to be replaced by separate functions for floats, strings, and bools.  The above automatic behavior is expected to work, but the code generated will use the new functions instead of the deprecated one.

View solution in original post

0 Kudos
3 Replies
LR
by
Occasional Contributor III

Try

attr quack = "" # this is your object attribute, might want to @hidden
attr whatgoes = quack

@StartRule 
 Lot --> 
 	 print(whatgoes)
JohnEsther2
New Contributor II

Thanks L R. That was helpful. this will enable me to script the attributes with python

0 Kudos
CherylLau
Esri Regular Contributor

getObjectAttr() does not work in cga rule files.  It is meant to only work in layer attribute code, which you can see in the Inspector when selecting a layer.  Code can be manually entered here, but it is more likely that it will be automatically entered here when connecting rule attributes to layer attributes.

L R's suggestion is a good way of getting values from an object attribute into a rule attribute with a different name.  I would go with this.  However, I want to describe another method so that I can give an example of how getObjectAttr is used.

Another way of doing this would be to connect your rule attribute to the object attribute through the layer.  Click on the drop down box next to your rule attribute in the Inspector and select Connect Attribute.

Then, connect through a layer attribute, and select the layer and name of the object attribute.

Then, if you select the layer, you'll see that the Layer Attributes section in the Inspector contains the code:

attr a = getObjectAttr("b")

Note: getObjectAttr() will most likely be deprecated soon to be replaced by separate functions for floats, strings, and bools.  The above automatic behavior is expected to work, but the code generated will use the new functions instead of the deprecated one.

0 Kudos