Maestro Python api example script setScaleRange for a drawingLayer

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Maestro Python api example script setScaleRange for a drawingLayer

lucvanlinden
This post was updated on .
Hi

I have tried to use the ScaleRangeUpdate example python script with Maestro.

Unfortunately this does not work for a DrawingLayer as it does not have a vectorscalerange.

After a lot of trying I managed to find out that it is possible to call:

ldf.SubLayer.MinScale = min

So we added a new function to the pyton script:

def FixScaleRangesMinMaxDrawing(conn, folder, min, max):
    """
    Modifies the first scale range of all Layer Definitions under the specified folder to the specified
    minimum and Mmximum scales
    """
    resList = conn.ResourceService.GetRepositoryResources(folder, "LayerDefinition")
    for child in resList.Children:
        ldf = conn.ResourceService.GetResource(child.ResourceId)
        print "Fixing: %s" % (child.ResourceId)
        # vsr is a IVectorScaleRange instance
        #vsr = ldf.SubLayer.GetScaleRange()
        ldf.SubLayer.MinScale = min
        # MinScale is a nullable property, so you also need to set the respective MinScaleSpecified property to true
        # in order for this change to be persisted
        ldf.SubLayer.MaxScale = max
        # MaxScale is a nullable property, so you also need to set the respective MaxScaleSpecified property to true
        # in order for this change to be persisted
        # Save the changes back
        conn.ResourceService.SaveResource(ldf)
        print "Scale range set to [%d, %d]" % (min, max)
        print "Saved: %s" % (child.ResourceId)

However, this will not set the scale range at all.

I believe this is because the tags are optional<MinScale></MinScale> <MaxScale></MaxScale>
Compared with the other functions in the example script, we tried setting ldf.SubLayer.MinScaleSpecified = True and  ldf.SubLayer.MaxScaleSpecified = True
But this will cause the python console to report

AttributeError: ‘DrawingLayerDefintionType’ object has no attributes MinScaleSpecified

I found the MaestroAPI.chm file which has both properties MaxMinScaleSpecified documented for the DrawingLayerDefintionType, so I am not sure where to go next to get this solved.



Questions:

1. How can we make this work?


Thanks

Luc
Reply | Threaded
Open this post in threaded view
|

Re: Maestro Python api example script setScaleRange for a drawingLayer

lucvanlinden
Some more feedback:

The MaestroAPI.chm does list a MinScaleSpecified property for the DrawingLayerDefintionType.

However when running the script in the console reports a non existing attribute :

AttributeError: ‘DrawingLayerDefintionType’ object has no attributes MinScaleSpecified

Also when using the context menu from the python console, the MinScaleSpecified is not listed.

However, when setting the MinScale property to a value other then 0, Maestro seems to include the MinScale tag by default in the XML defintion.

For the MaxScale it is required to set the MaxScaleSpecified = True in order to have it saved.

Luc

Reply | Threaded
Open this post in threaded view
|

Re: Maestro Python api example script setScaleRange for a drawingLayer

Jackie Ng
In reply to this post by lucvanlinden
You are correct that a Drawing Layer has no vector scale range.

This is because min/max scale is a root property of a DrawingLayerDefinition, so you python code is correct. But what you're failing to do is to check is the property layer type of the ldf.SubLayer property (as this could be a vector or raster layer which do not have min/max scale properties at this level).

So you should check that ldf.SubLayer.LayerType == LayerType.Drawing before proceeding with your scale setting code.

- Jackie