// Shape Tag Mapping streetscale = 1 // street width scale factor width = getObjectAttr("width") swide = getObjectAttr("sidewalk") lwide = getObjectAttr("VEH_WIDE") check = getObjectAttr("ROW_WIDE") default_road = 0 default_side = 0 attr streetWidth = case check == 0: default_road * streetscale else: width * streetscale attr sidewalkWidthLeft = case check == 0: default_side * streetscale else: swide * streetscale attr sidewalkWidthRight = case check == 0: default_side * streetscale else: swide * streetscale attr laneWidth = case check == 0: default_road * streetscale else: lwide * streetscale
from scripting import * # get a CityEngine instance ce = CE() # helper function def update_attr(shape, get_name="", set_name="",check_name=""): """helper function: used to get attribute values from the shape and set them in the layer""" # get the value from the shape attribute that will be written value = ce.getAttribute(shape, get_name) # get the check value from the shape that will be written check = ce.getAttribute(shape, check_name) if check == 0: ce.setAttribute(x , set_name, 0) else: ce.setAttribute(x, set_name, value) ce.setAttributeSource(x, "/ce/street/%s" % set_name, "OBJECT") # selection graph_network = ce.getObjectsFrom(ce.selection()) # iteration for x in graph_network: # check parameter check_name = "check_attr" # run update function for each attribute update_attr(x, "in_carriageway", "street_width", check_name) update_attr(x, "outside_carriageway", "sidewalkWidthLeft", check_name) update_attr(x, "outside_carriageway", "sidewalkWidthRight", check_name) update_attr(x, "lane_width", "laneWidth", check_name) if __name__ == '__main__': pass
Hi Christian,
I have a question regarding your Python script. Did it work?
I am using CE Python API and came into your topic. I want to know why didn't you put the variables "set_name" and "get_name" inside quotation marks in setAttribute and getAttribute methods?!