Query a Shapes Layer Name

2335
3
11-14-2011 09:43 AM
Jackde_Valpine
New Contributor
Hi,

More questions... Is there a way to use python to query/determine the name of the layer a shape is associated with based on a selection of shapes? Can shapes be moved/copied to new shape layers with python?

Thanks,

-Jack de Valpine
Tags (3)
0 Kudos
3 Replies
AndreasUlmer
Esri Contributor
We added ce.getLayer(object) as a Python command last week, which will return the layer an object is in. This will be available in the upcoming service release of Esri CityEngine 2011.


For 2010.3, the only option I see is to loop through the layers until the object is found:

def getLayer(object):
    uuid = ce.getUUID(object)
    layers = ce.getObjectsFrom(ce.scene, ce.isLayer)
    # this could be sped up by filtering layers by type of object
    for layer in layers:    
        for o in ce.getObjectsFrom(layer):
            if ce.getUUID(o) == uuid :
                return layer
    return None


if __name__ == '__main__':
    print getLayer(ce.selection()[0])



does that work for you?
0 Kudos
Jackde_Valpine
New Contributor
Hi Andreas,

Thanks for idea on this. It probably will be handy to have in your upcoming release. I am not sure but looping through a scene in this way seems like it could be pretty costly? In any event this is not critical to what I am looking into.

Thanks again,

-Jack
0 Kudos
AndreasUlmer
Esri Contributor
if your scene is really big, it might take a bit of time. in case this becomes an issue, you could probably filter layers that are to be searched. either by implicit knowledge, or only searching layers of a specific type (e.g. for graph segments one only needs to look in a graph network layer)
0 Kudos