wiki:CodeSamples/Other/MaestroScripts/ScaleRangeUpdate

Version 1 (modified by jng, 11 years ago) ( diff )

--

This page is one of the MapGuide Community CodeSamples. Visit the CodeSamples page to view more!

This sample script contains a series of utility functions to batch update a series of Layer Definitions in a folder to conform to a specified minimum/maximum scale range.

How to use this script

  1. Launch MapGuide Maestro
  2. In the IronPython console, click Run File
  3. Browse to scale_ranges_utils.py and click Open to load this script

Once loaded, you will have the following functions available for you to use from the IronPython console:

def FixScaleRangesMinMax(conn, folder, min, max):
    """
    Modifies the first scale range of all Layer Definitions under the specified folder to the specified
    minimum and Mmximum scales
    """
def FixScaleRangesZeroToMax(conn, folder, max):
    """
    Modifies the first scale range of all Layer Definitions under the specified folder to the specified
    maximum scale. The minimum scale is un-set (ie. Set to 0)
    """
def FixScaleRangesMinToInfinity(conn, folder, min):
    """
    Modifies the first scale range of all Layer Definitions under the specified folder to the specified
    minimum scale. The maximum scale is un-set (ie. Set to infinity)
    """
def FixScaleRangesZeroToInfinity(conn, folder):
    """
    Modifies the first scale range of all Layer Definitions under the specified folder to [0, Infinity]
    """

To modify all layers under Library://Samples/Sheboygan/Layers/ to have a scale range of 50 to 12000, you would run the following snippets in your IronPython console. This assumes a session with only one active site connection:

>>> conn = app.GetConnection(app.GetConnectionNames()[0])
>>> FixScaleRangesMinMax(conn, "Library://Samples/Sheboygan/Layers/", 50, 12000)

This will output something similar to this:

Fixing: Library://Samples/Sheboygan/Layers/CityLimits.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/CityLimits.LayerDefinition
Fixing: Library://Samples/Sheboygan/Layers/Buildings.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/Buildings.LayerDefinition
Fixing: Library://Samples/Sheboygan/Layers/Districts.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/Districts.LayerDefinition
Fixing: Library://Samples/Sheboygan/Layers/Hydrography.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/Hydrography.LayerDefinition
Fixing: Library://Samples/Sheboygan/Layers/Islands.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/Islands.LayerDefinition
Fixing: Library://Samples/Sheboygan/Layers/Parcels.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/Parcels.LayerDefinition
Fixing: Library://Samples/Sheboygan/Layers/Roads.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/Roads.LayerDefinition
Fixing: Library://Samples/Sheboygan/Layers/Tracks.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/Tracks.LayerDefinition
Fixing: Library://Samples/Sheboygan/Layers/Trees.LayerDefinition
Scale range set to [50, 12000]
Saved: Library://Samples/Sheboygan/Layers/Trees.LayerDefinition
>>> 

Limitations

This only operates on the first scale range it finds of each Layer Definition in the folder you specify.

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.