Is there a function to remove a layer?

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
jayh
Posts: 424
Joined: Thu Jan 15, 2009 10:34 pm

Is there a function to remove a layer?

Post by jayh »

A user submitted this question, and we wanted to share the process:
I can find removeAllLayers, is there a function to remove a specific layer?
Here is how you can accomplish this:
Assuming his displayed layer is referenced as "layer", for example:

layer = activeDisplay().createLayer('Image Display', data)

Then you can remove that individual layer with:

layer.doRemove()

He would just replace "layer" with whatever he called his layer at createDisplay().

If he isn't sure of the name of the layer, he could get a list of all layers in the display with:

layers = activeDisplay().getLayers()

And then remove individual layers by index number. For example, if he just has a map (index 0 in the list) and an image display (index 1 in the list) he could remove the image display layer with:

layers[1].doRemove()
Post Reply