Select - Select Objects By Map Layer in Python?

01-02-2013 08:32 AM
New Contributor

I'd like to automate the following process in the GUI:

Select -> Select Objects By Map Layer -> Obstacle:obstacle

In my scene I have lots that are being generated over a river, despite the obstacle map being correctly applied (because certain roads that are going across the river, in the imported OSM data I'm using, cause CE to think that these are valid spots for lot creation). It's pretty easy in the GUI to select these lots and then set their shapeCreation attribute to off, but I'm trying to automate this process.

Seems like there should be a "setSelectionByMapLayer()" command 🙂

Any advice?

Tags (3)
0 Kudos
4 Replies
Frequent Contributor
Hi !

You could try the following :

0] make an empty list for the stuff to select later on
1] Get all shapes in the layer
2] loop over all shapes
3] for each shape :
4] get the attribute value you have set up to select the shape via the GUI ( the boolean )
5] if attr == True : selectionList.append(shape)
6] after loop : select your list content.

Makes sense ?

Let me know ..

0 Kudos
Frequent Contributor
Here's a similar script to check out ..
0 Kudos
New Contributor
Thanks, yes, that was helpful information!

I ended up using a somewhat different implementation but you helped get me going
on the right track:

def SelectAllBlocksInObstacleMap():
    ''' turn off blocks if vertices are in obstacle map defined areas '''
    Obstacle = ce.getObjectsFrom(ce.scene, ce.isLayer, ce.withName("'Obstacle'"))[0]
    allBlocks = ce.getObjectsFrom(ce.scene, ce.isBlock)
    for o in allBlocks:
        verts = ce.getVertices(o)
        if verts:
            x = verts[0]
            z = verts[2]
            sampleSpot = ce.sampleBooleanLayerAttribute(Obstacle, "obstacle", x, z)
            if sampleSpot:
                ce.setAttribute(o, '/ce/block/shapeCreation', False)

as you can see, what I was missing was knowing to use the sampleBooleanLayerAttribute command,
so once I figured that out, I was able to proceed- although your implementation seems a bit cleaner, so I might
give that a try as well. 🙂
0 Kudos
Frequent Contributor
Glad you found a way.

There's usually multiple ways to do things .. 😮
0 Kudos