Arcpy Layer class minScale

707
7
Jump to solution
04-28-2017 01:32 PM
DevinUnderwood2
Occasional Contributor

What is the syntax to retrieve all layers' set minimum scale ?

0 Kudos
1 Solution

Accepted Solutions
DevinUnderwood2
Occasional Contributor
for layer in layers:
                    if layer.isFeatureLayer:
                        lyr_source = layer.dataSource
                        lyr_name = layer.name.encode("utf8", "replace")
                        print fullpath + " " + lyr_source + " " + str(layer.minScale)
                        scale = [layer.minScale]

                        # Write to Excel
                        b = fullpath.split('\\') + lyr_source.split('\\') + scale
                        writer.writerow(b)

Thanks, everyone I arrived at my final solution.

View solution in original post

0 Kudos
7 Replies
DanPatterson_Retired
MVP Esteemed Contributor

not sure what you mean beyond it returning a double (number).  Are you wanting to cycle through all the layers and return the minScale for each?  Did you try something and it didn't work?

0 Kudos
DevinUnderwood2
Occasional Contributor

I haven't tried anything yet and yes you are correct as I did not have any luck searching the internet to achieve this.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

The arcpy help is your best bet... this is the layer section

and from there, nothing too exciting ... maybe...  mylayer.minScale if it is property

 

minScale
(Read and Write)

Provides the ability to set or get the layer's minimum scale threshold.

Double

As for arcpy.... bookmark the start of its menu tree... Arcpy ... , Dr Google isn't very good at tracking down all the properties and methods

DevinUnderwood2
Occasional Contributor

I know that it can be done, documentation is lacking.

0 Kudos
RandyBurton
MVP Regular Contributor

Try:

mxd = arcpy.mapping.MapDocument("CURRENT")

for lyr in arcpy.mapping.ListLayers(mxd):
    # to read minScale
    print lyr.minScale
    # to set minScale
    lyr.minScale = 500.0
‍‍‍‍‍‍‍‍‍‍‍‍
DevinUnderwood2
Occasional Contributor

Perfect, I arrived at the same.

Make sense, set the mxd and loop layers.

I will add this to an existing script that write data to csv.

Thanks

0 Kudos
DevinUnderwood2
Occasional Contributor
for layer in layers:
                    if layer.isFeatureLayer:
                        lyr_source = layer.dataSource
                        lyr_name = layer.name.encode("utf8", "replace")
                        print fullpath + " " + lyr_source + " " + str(layer.minScale)
                        scale = [layer.minScale]

                        # Write to Excel
                        b = fullpath.split('\\') + lyr_source.split('\\') + scale
                        writer.writerow(b)

Thanks, everyone I arrived at my final solution.

0 Kudos