Not getting how to modify layer attributes


#1

I must be doing something stupid here:

import scriptcontext as sc

def CopyLayerAttribs(source_layer,target_layer):
    layers=sc.doc.Layers
    si=layers.Find(source_layer,True)
    ti=layers.Find(target_layer,True)
    layers[ti].Color=layers[si].Color  
    layers[ti].CommitChanges()

layerA="Layer 01"
layerB="Layer 02"
CopyLayerAttribs(layerA,layerB)

I also tried with layers.Modify() but i couldn’t get that to work either… I’m sure I missed something simple…

Thx, --Mitch


#2

Hi Mitch,

Modify() is definitively the way to do it.
Other than that I noticed that it is always better to assign the specific object to a variable, and then change it’s Geometry, Attributes - Color, and so on. In this case that would be “Layer 01” and “Layer 02”.
I guess @stevebaer or @dale might tell us more about this.

import scriptcontext as sc

def CopyLayerAttribs(source_layer,target_layer):
    si=sc.doc.Layers.Find(source_layer,True)
    ti=sc.doc.Layers.Find(target_layer,True)
    sLay = sc.doc.Layers[si]
    tLay = sc.doc.Layers[ti]
    tLay.Color=sLay.Color
    sc.doc.Layers.Modify(tLay, tLay.LayerIndex, False)


layerA="Layer 01"
layerB="Layer 02"
CopyLayerAttribs(layerA,layerB)

#3

Yep, that seems to be the key… I’m going to assume that you can’t modify the layer’s attributes in place, that you need to create a new object, change its attributes and then transfer those to the existing layer in the table. I had just assumed that CommitChanges() would let one do that directly for an individual layer in the table…

Anyway, thanks for testing djordje…!

–Mitch


(Steve Baer) #4

Assigning to a variable is the correct way to go about it. I’ll probably be able to fix this in V6, but I can’t really change this for V5.


#5

OK, thanks Steve! --Mitch