Select to view content in your preferred language

Layers On/Off

4440
14
10-25-2011 08:49 AM
MathieuCain
Occasional Contributor
Hello,

I have a map which I am publishing to be viewed in ArcReader.

I have 2 layer groups which I do not want visible at the same time (i.e., both can be turned off, or one or the other can be turned one, but not both on at the same time).

Is there a way to do this?

Thanks for your thoughts.
0 Kudos
14 Replies
JeffBarrette
Esri Regular Contributor
Is there a way you could use scale thresholds or are the two groups scale independent?

I can't think of a way to do it in the UI.  You would need to build a custom event handler.

Jeff
0 Kudos
MathieuCain
Occasional Contributor
Unfortunately they are scale independent.
0 Kudos
KerryStonestreet
Deactivated User
I'm searching the forum as I have a very similar need.  So I'll hijack/bump your post.

I have 20+ Group Layers, each with one feature class, a DWG and a raster.  I could employ Page Definition Queries if it wasn't for the darn raster.
I want one Group Layer visible per DDP.  I'm sure a little Python would go a long way but alas, I'm Python ignorant.  😞
Am I missing a simple way to do this?

Thanks!
0 Kudos
JonathanQuinn
Esri Notable Contributor
This may be off base, but how about clipping to the current extent of the data driven page?  You can include all layers within the clip so it'll clip vector and raster data.
0 Kudos
KerryStonestreet
Deactivated User
This may be off base, but how about clipping to the current extent of the data driven page?  You can include all layers within the clip so it'll clip vector and raster data.


Thanks for the suggestion.  I neglected to state my index feature class consists of 30+ identical polygons (i.e., exact same size and extent).

Thanks again for the quick reply, I just saw this.  I thought I had notifications enabled.  Will check on it.
0 Kudos
KerryStonestreet
Deactivated User
Perhaps I should move this to a new post?  Oh well, it's essentially the same question originally posted and unanswered.

I'm struggling through a crash course in Arcpy this week.  I've been putting this off for years.  🙂
I want to turn on (make visible) a Group Layer for each index page of my DDP. 

In my TOC:
"GroupLayer1" to "GroupLayer30".  30 Group Layers named same as my DDP index field.
A "New Basemap Layer"

I've believe the answer may along one or more of these concepts:
lyr.longName equal to lyr.name then lyr.visible = true, else false?
http://forums.arcgis.com/threads/957-Beta-10-List-Comprehensions?highlight=map+group+layer+u%27

yet another snippet I'm experimenting with, but currently only returns the "else" argument...
import arcpy, os 
... mxd = arcpy.mapping.MapDocument(r'C:\GIS\PROJECT\FrustratingArcPy.mxd')
... idxLyr = arcpy.mapping.ListLayers(mxd, 'MapBook_OCT09')[0]  # The DDP index FC
... Group = arcpy.mapping.ListLayers (mxd)
... df = arcpy.mapping.ListDataFrames(mxd, 'MapBook')[0] # The Data Frame name
... pageNameField = "Page_Title" #DDP Index Field
... 
... rows = arcpy.UpdateCursor(idxLyr)
... 
... for row in rows:
...     pageName = row.getValue(pageNameField).encode('ascii')
...     pageID = mxd.dataDrivenPages.getPageIDFromName(pageName)
...     mxd.dataDrivenPages.currentPageID = pageID
...     if str(pageName) == str(Group):
...         print str(Group) + str(" ") + str(pageName)
...     else:
...          print str(Group)
... del mxd, row, rows


Another incomplete sample which returns all Group Layers, including the "New Basemap Layer":
 import arcpy, os
... from arcpy.mapping import *  #Brings in entire functionality of the mapping module
... mxd = arcpy.mapping.MapDocument(r'C:\GIS\PROJECT\FrustratingArcPy.mxd')
... layerlist = arcpy.mapping.ListLayers(mxd)    
... for lyr in layerlist:    
...     if lyr.isGroupLayer:      
...         lyr.visible = True
...         print str(lyr)
...     else:
...         lyr.visible = False
... arcpy.RefreshTOC()        
... del mxd



Please help?!
Thanks!
Kerry
0 Kudos
JeffBarrette
Esri Regular Contributor
I think the following script will do what you need.  Make sure to save the MXD with ALL group layers checked off (and all layers within the group layer checked on).  See attached screen shot. A field was added to the index layer called "GroupLayerName".  It has the values "GroupLayer1, GroupLayer2, etc).  After exporting to PDF, the script then turns the group layer back off again before going to the next DDP page.


import arcpy
mxd = arcpy.mapping.MapDocument(r"c:\Temp\test.mxd")
ddp = mxd.dataDrivenPages

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  fieldValue = mxd.dataDrivenPages.pageRow.GroupLayerName
  for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.name == fieldValue:
      lyr.visible = True
      arcpy.mapping.ExportToPDF(mxd, r"C:\\Temp\\" + fieldValue + ".pdf")
      lyr.visible = False
del mxd


[ATTACH=CONFIG]18285[/ATTACH]

Jeff
0 Kudos
KerryStonestreet
Deactivated User
I think the following script will do what you need.  Make sure to save the MXD with ALL group layers checked off (and all layers within the group layer checked on).  See attached screen shot. A field was added to the index layer called "GroupLayerName".  It has the values "GroupLayer1, GroupLayer2, etc).  After exporting to PDF, the script then turns the group layer back off again before going to the next DDP page.
... <edited>
Jeff


Ahhhhh Jeff, that's smoooth.  Works like a charm!
I'm inspired to continue learning Arcpy.
I voted your reply up one, wish I could vote it up 10x's. 
Thank you!
Kerry
0 Kudos
TraceyKing
New Contributor
I am trying to make changes to a map document using a python stand alone script.  My script runs  and I can get information from the map document but it does not make any changes to the document.  One example is just to turn the layers on and off.  A snippet of part of the script is included.  Any help would be appreciated as even my instructor has not been able to make it work.

# Import system modules

import arcpy, sys, os, traceback, datetime
from arcpy.mapping import *

# set the current workspace (in the case a folder)
arcpy.env.workspace = "E:\MapProject\MapProject.gdb"

# Define Variables   
datapath = "E:\MapProject\MapProject.gdb\\"
mappath =  "E:\\MapProject\\Maps"

try:   
   
    # Get the map document. In this case a custom template set up for map production
    mxd = MapDocument(mappath + os.sep + "ReportMapsTemplate9.mxd")

    print "Getting Map Document properties..."
   
    # Report properties of the Map Document
   
    print "Map Document Title: " + str(mxd.title)
    print "Map Document Author: " + str(mxd.author)
    mxd.author = "Tracey A. King"
    print "Map Document Author is now: " + str(mxd.author)
    print mxd.filePath
    print mxd.pageSize
   
    # Get a list of data frames
    # [0] indicates the first data frame
    # The data frame names is "Map Frame" 
    df = ListDataFrames(mxd, "Map Frame")[0]

    print "Getting Data Frame properties..."

    # Report properties of the data frame named "Map Frame"
  
    print 'Data Frame Name: ' + str(df.name)
    print "Map Frame Map Units: " + str(df.mapUnits)
    print "Map Frame Scale: " + str(df.scale)         

    # Get a list of layers in the table of contents of the map document
    TOCLayers = ListLayers(mxd)
       
    print "Processing layout elements..."

    # Loop through the layers 
       
    for TOCLayer in ListLayers(mxd):
        print 'Layer Name: ' + str(TOCLayer.name)
        print 'Longname: ' + str(TOCLayer.longName)

    # 3. Set initial layer visibility               
        if TOCLayer.name=="SSLT_Boundary":
            TOCLayer.visible=True
        if TOCLayer.name=="SSLT_Easements":
            TOCLayer.visible=True
        if TOCLayer.name=="NatGeo_World_Map":
            TOCLayer.visible=True
0 Kudos