0

I'd like to only display an inset map, inset map scale bar, frame and leader if an associated layer is displayed. Similar to Associate Point Layer, Annotation Group and Line Layer in Map Legend but for an inset map rather than annotation.

I can't put up an image through the firewall but the inset is the same as the main map at a different scale in ArcGIS 10.2.1 for Desktop under Win7. It has a few line and point layers, same labels and the scalebar.

Following on from https://gis.stackexchange.com/a/311066/121893 and using a framework from https://community.esri.com/thread/178874. This arcpy code has no affect on inset or scalebar. How can I get it to work (including where to put code in project)?

def display_layer_inset(glayername):
    mxd = arcpy.mapping.MapDocument('CURRENT')
    df = mxd.activeDataFrame
    df2 = arcpy.mapping.ListDataFrames(mxd, "inset")[0]
    layers = arcpy.mapping.ListLayers(df)
    for lyr in layers:
        if lyr.isGroupLayer and lyr.name == glayername:
            print "Layer: " + glayername
            if lyr.visible == True:
                print "visible"
                df2.visible = True
            else:
                print "not visible"
                df2.visible = False

# use as
display_layer_inset("MyGroupLayer")

Output:

Layer: MyGroupLayer
not visible
  • What does a small Table of Contents with perhaps two group layers, with two layers in each, look like? A picture of test TOC would be useful. What happens when you run the code that you have presented? Any errors or other messages from your print statements would be useful. – PolyGeo Feb 6 at 0:12
  • 1
    How are you setting sclbr? See sample code here. – Kirk Kuykendall Feb 6 at 0:56
  • To focus your question some more simply delete those sclbr lines because you have not yet created the scalebar object named sclbr. – PolyGeo Feb 6 at 1:05
  • 3
    I'm not sure if it still behaves this way, but in earlier versions if you wanted to hide an element that's in the layout you could move it off the page (some large negative distance) then move it back to show it. IIRC this was a workaround to the lack of a visible property. – Kirk Kuykendall Feb 6 at 1:34
  • 1
    @nealei, did you read Kirk's second comment? He already told you how to do it. You can't set the order with arcpy, so the best way to show/hide some element (and it works for all element types, including DataFrames) is to change the elementPositionX or elementPositionY properties. – Tom Feb 7 at 18:15
1

This answer uses the workaround in comment on question from @Kirk Kuykendall to move dataframe off the page. It does not support dataframe extent or leader line. Note it requires a unique inset scalebar name.

Also: http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/guidelinesforarcpymapping.htm

def AssociateSecondaryDataframeWithGroup(glayername, insetname, insetscalebarname):
# Secondary dataframe moved on/off dataframe based on group visibility
# Elements and locations hardcoded
    mxd = arcpy.mapping.MapDocument('CURRENT')
    df = mxd.activeDataFrame
    df2 = arcpy.mapping.ListDataFrames(mxd, insetname)[0]
    scalebar = arcpy.mapping.ListLayoutElements(mxd,"MAPSURROUND_ELEMENT",insetscalebarname)[0]
    lyrs = arcpy.mapping.ListLayers(df)
    for lyr in lyrs:
        if lyr.isGroupLayer and lyr.name == glayername:
            # print "Layer: " + glayername
            if lyr.visible == True:
                # print "visible"
                df2.elementPositionX = 10
                scalebar.elementPositionX = 12.5
            else:
                # print "not visible"
                df2.elementPositionX = -10
                scalebar.elementPositionX = -7.5
    arcpy.RefreshActiveView()


# use as
AssociateSecondaryDataframeWithGroup("MyGroupLayer", "inset", "InsetScaleBar")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.