Use Selection of one Combobox to update the items list in another Combobox

895
3
Jump to solution
02-28-2013 06:46 AM
JohnDye
Occasional Contributor III
So I have a series of Comboboxes which I created to perform a "Quick-Jump" function in which a user can select AOIs at varying geography levels, and kind of quickly drill down into a very specific AOI without having to know where it is geographically.

The Comboboxes are Major Geographic Level (MajorGeoLevel.cbx) and Minor Geographic Level (MinorGeoLevel.cbx).

Major Geographic Level contains a static items list of containing the National Extent and 8 different regions around the US. When a user selects a region, the Combobox should:

  • Perform a selection against the Regions Layer for the Region selected in the Combobox, zoom to the selected feature, turn the layer on, clear the selection and refresh the active view.

  • Enable the MinorGeoLevel.cbx and update the items contained in the MinorGeoLevel.cbx with a predefined list of Minor Geographic Levels, which correspond to the selected item in the MajorGeoLevel.cbx, unless the item selected in MajorGeoLevel.cbx is 'National'.

I am having two issues.
1. The selection from MajorGeoLevel.cbx does not seem to be doing anything. ie. When I select National...nothing happens. It doesn't even reflect in the Combobox.
2. MinorGeoLevel.cbx is not becoming enabled once a selection is made in MajorGeoLevel. Because it's not becoming enabled, I can't even tell if it's updating the item list for MinorGeoLevel.cbx either.

Here is my code:
class QuickJump_MajorGeoLevel(object):     """Implementation for QuickJump_MajorGeoLevel.cbx (ComboBox)"""     def __init__(self):         self.items = ["National", "National-Direct", "Region I", "Region II", "Region III", "Region IV", "Region V", "Region VI", "Region VII", "Region VIII"]         self.editable = False         self.enabled = True         self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXX'         self.width = 'XXXXXXXXXXXXXXXXXXXX'     def onSelChange(self, selection):         #Instantiate the current MXD as a variable         mxd = arcpy.mapping.MapDocument("Current")          #Jump to the selected MajorGeoLevel and initialize the MinorGeoLevel combobox, populated with the MinorGeoList that corresponds to the current selection         #If the current selection is 'National', jump to the NationalExtent. MinorGeoLevel.cbx and SubGeoLevel.cbx remain disabled from Initialization.         if selection == "National":             #Jump to the 'NationalExtent'             df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]             NationalExtent = df.extent             NationalExtent.XMin, NationalExtent.YMin = -13978263.2599, -1547990.11744             NationalExtent.XMax, NationalExtent.YMax = -7429812.66299, 7011646.87809             df.extent = NationalExtent             arcpy.RefreshActiveView()          #if the current selection is National-Direct , refresh the MinorGeoLevel.cbx in the UI         elif selection == "National-Direct":             #Refresh the 'QuickJump_MinorGeoLevel' combobox which enables the combobox and updates the item list             QuickJump_MinorGeoLevel.refresh()             #Jump to the Full Extent of the National-Direct Region and Turn the layer On             for lyr in arcpy.mapping.ListLayers (mxd):              if lyr.name == "Regions_All":                 #if the layer is not currently visible, make the layer visible and refresh the Map Display Window                 if lyr.visible == False:                     lyr.visible = True                     #Establish the DataFrame and the 'Regions_All' variables                     df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]                     Regions_All = arcpy.mapping.ListLayers(mxd, "Regions_All", df)                     #Select 'Region 1' from the 'Regions_All' layer                     arcpy.SelectLayerByAttribute_management ("Regions_All", "NEW_SELECTION", ' "REGION" = ND')                     #Zoom to the selected feature                     df.zoomToSelectedFeatures()                     #Apply a 10% Buffer to the Extent of the Zoom                     df.scale = df.scale * 1.1                     #Clear the Selection                     arcpy.SelectLayerByAttribute_management ("Regions_All", "CLEAR_SELECTION")                     #Refresh the Map Display Window                     arcpy.RefreshActiveView()          #Report an with a MessageBox if the 'Regions_All' layer is not loaded in the MXD         else:             pythonaddins.MessageBox('The layer Regions_All is not loaded in the MXD. Unable to turn layer on or jump to extent.', 'Layer not Found', 5)  class QuickJump_MinorGeoLevel(object):     """Implementation for QuickJump_MinorGeoLevel.cbx (ComboBox)"""     def __init__(self):         #Create the Predefined Item Lists, which are  initialized depending on the QuickJump_MajorGeoLevel Combobox's current selection         self.items= []         self.editable = False         self.enabled = False         self.dropdownWidth = 'WWWWWW'         self.width = 'WWWWWW'     def SelChange(self, selection):         pass     def refresh(self):         #Create the Predefined Minor Geography Item Lists, which are  implemented in the QuickJump_MinorGeoLevel Combobox depending on the QuickJump_MajorGeoLevel Combobox's current selection         ND_MinorGeoList = ["Boston", "Los Angeles", "San Francisco", "Honolulu", "Chicago", "Minneapolis/St. Paul", "New York", "Philadelphia", "Wilmington"]         RegionI_MinorGeoList["New York-Northern New Jersey-Long Island, NY-NJ-PA"]         RegionII_MinorGeoList["New York-Northern New Jersey-Long Island, NY-NJ-PA"]         RegionIII_MinorGeoList["Bridgeport-Stamford-Norwalk, CT", "Hartford West-Hartford East, CT", "New Haven-Milford,CT", "New York-Northern New Jersey-Long Island, NY-NJ-PA", "Poughkeepsie-Newburgh-Middletown, NY", "Torrington, CT", "Trenton-Ewing, NJ", "Allentown-Bethlehem-Easton, PA-NJ", "Philadelphia-Camden-Wilmington, PA-NJ-DE-MD"]         RegionIV_MinorGeoList["Baltimore-Townsend, MD", "Cambridge, MD", "Dover, DE", "Easton, MD", "Gettysburg, PA", "Lexington Park, MD", "Ocean Pines, MD", "Salisbury, MD", "Seaford, DE", "Washington-Arlington-Alexandria, DC-VA-MD-WV", "York-Hanover, PA"]         RegionV_MinorGeoList["Baltimore-Townsend, MD", "Chambersburg, PA", "Charlottesville, VA", "Culpepper, VA", "Cumberland, MD-WV", "Gettysburg, PA", "Hagerstown-Martinsburg, MD-WV", "Harrisonburg, VA", "Richmond, VA", "Staunton-Waynesboro, VA", "Washington-Arlington-Alexandria, DC, VA-MD-WV", "Winchester,VA-WV"]         RegionVI_MinorGeoList["Athens, TX", "Bonham, TX", "Dallas-Fort Worth-Arlington, TX", "Durant, OK", "Gainesville, TX", "Palestine, TX", "Paris, TX", "Sherman-Denison, TX", "Sulpher Springs, TX", "Alexandria, LA", "Baton Rouge, LA", "Crowley, LA", "DeRidder, LA", "Fort Polk South, LA", "Jennings, LA", "Lufkin, TX", "Natchez, MS-LA", "Opelousas-Eunice, LA", "Bastrop, LA", "El Dorado, AR", "Jacksonville, TX", "Longview, TX", "Magnolia, AR", "MArshall, TX", "Minden, LA", "Monroe, LA", "Mount Pleasant, TX", "Nacogdoches, TX", "Natchitoches, LA", "Ruston, LA", "Shreveport-Bossier City, LA", "Tallulah, LA", "Texarkana, TX", "Tyler, TX", "Vicksburg, MS"]         RegionVII_MinorGeoList["Baton Rouge, LA", "Bogalusa, LA", "Crowley, LA", "Gulfport-Biloxi, MS", "Hammond, LA", "Houma-Bayou Cane-Thibodaux, LA", "Jennings, LA", "Lafayette, LA", "Lakes Charles, LA", "McComb, MS", "Morgan City, LA", "New Iberia, LA", "New Orleans-Metairie-Kenner, LA", "Opelousas-Eunice, LA", "Picayune, MS", "Pierre Part, LA"]         RegionVIII_MinorGeoList["Alice, TX", "Austin-Round Rock-San Marcos, TX", "Bay City, TX", "Brenham, TX", "Brownsville-Harlingen", "College Station-Bryan, TX", "Corpus Christi, TX", "El Campo, TX", "Huntsville, TX", "Kileen-Temple-Fort Hood, TX", "Kingsville, TX", "Marble Falls, TX", "McAllen-Edinburg-Mission, TX", "Raymondville, TX", "Rio Grande City-Roma, TX", "San Antonio-New Braunfels, TX", "Victoria, TX", "Abbeville, LA", "Beaumont-Port Arthur, TX", "DeRidder, LA", "Houston-Sugar Land-Baytown, TX", "Jennings, LA", "Lake Charles, LA"]         if QuickJump_MajorGeoLevel.selection == "National-Direct":             self.enabled = True             self.items = ND_MinorGeoList 


Any insight is greatly appreciated
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohnDye
Occasional Contributor III
So Chris,
You were right. My code was full on name collisions and once I resolved them all and massaged the code a bit more, it worked just fine. For anyone who made read this post down the road, its important to note that in order to get the another element to refresh and enable/disable, you have to call the element by its ID, which is not the same as the Class Name. While I'd known the two were different, I never recognized that there would be any difference between using one or the other. So my Class Names were always identical to my IDs. Hence the naming conflict. The script didn't know whether to call a Class or an ID because they were identical.

You can quickly determine what the ID for a given element in your code by looking directly under the Class Name for the element for the snippet
"""Implementation for MAP.QuickJump_MajorGeoLevel_CBX (ComboBox)"""

where "QuickJump_MajorGeoLevel_CBX" is my element ID. MAP is a reference I used to tell me what toolbar it is loaded on. It's also good to know that you shouldn't expect any assistance from Auto-Complete when referencing the IDs. I'm not exactly sure why that is, but PyScripter didn't give me any assistance with IDs which was confusing at first because I rely on it quite a bit to make sure that my syntax is correct.

So once I updated all of my IDs and ensured there were no conflicts and then changed the code to call the element by ID when enabling or refreshing, all was right with the world again! Here's the code to provide examples for anyone else reading this post.

class MAP_QuickJump_MajorGeoLevel(object):     """Implementation for MAP.QuickJump_MajorGeoLevel_CBX (ComboBox)"""     #Jump to the selected MajorGeoLevel and refresh the Minor and Sub GeoLevel comboboxes if the current selection is anything other than 'National'     def __init__(self):         self.items = ["National", "National-Direct", "Region I", "Region II", "Region III", "Region IV", "Region V", "Region VI", "Region VII", "Region VIII"]         self.editable = False         self.enabled = True         self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXX'         self.width = 'XXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxx'      def onSelChange(self, selection):         mxd = arcpy.mapping.MapDocument("Current")         df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]         ND_MinorGeoList = ["Boston", "Los Angeles", "San Francisco", "Honolulu", "Chicago", "Minneapolis/St. Paul", "New York", "Philadelphia", "Wilmington"]         RegionI_MinorGeoList = ["New York-Northern New Jersey-Long Island, NY-NJ-PA"]         RegionII_MinorGeoList = ["New York-Northern New Jersey-Long Island, NY-NJ-PA"]         RegionIII_MinorGeoList = ["Bridgeport-Stamford-Norwalk, CT", "Hartford West-Hartford East, CT", "New Haven-Milford,CT", "New York-Northern New Jersey-Long Island, NY-NJ-PA", "Poughkeepsie-Newburgh-Middletown, NY", "Torrington, CT", "Trenton-Ewing, NJ", "Allentown-Bethlehem-Easton, PA-NJ", "Philadelphia-Camden-Wilmington, PA-NJ-DE-MD"]         RegionIV_MinorGeoList = ["Baltimore-Townsend, MD", "Cambridge, MD", "Dover, DE", "Easton, MD", "Gettysburg, PA", "Lexington Park, MD", "Ocean Pines, MD", "Salisbury, MD", "Seaford, DE", "Washington-Arlington-Alexandria, DC-VA-MD-WV", "York-Hanover, PA"]         RegionV_MinorGeoList = ["Baltimore-Townsend, MD", "Chambersburg, PA", "Charlottesville, VA", "Culpepper, VA", "Cumberland, MD-WV", "Gettysburg, PA", "Hagerstown-Martinsburg, MD-WV", "Harrisonburg, VA", "Richmond, VA", "Staunton-Waynesboro, VA", "Washington-Arlington-Alexandria, DC, VA-MD-WV", "Winchester,VA-WV"]         RegionVI_MinorGeoList = ["Athens, TX", "Bonham, TX", "Dallas-Fort Worth-Arlington, TX", "Durant, OK", "Gainesville, TX", "Palestine, TX", "Paris, TX", "Sherman-Denison, TX", "Sulpher Springs, TX", "Alexandria, LA", "Baton Rouge, LA", "Crowley, LA", "DeRidder, LA", "Fort Polk South, LA", "Jennings, LA", "Lufkin, TX", "Natchez, MS-LA", "Opelousas-Eunice, LA", "Bastrop, LA", "El Dorado, AR", "Jacksonville, TX", "Longview, TX", "Magnolia, AR", "Marshall, TX", "Minden, LA", "Monroe, LA", "Mount Pleasant, TX", "Nacogdoches, TX", "Natchitoches, LA", "Ruston, LA", "Shreveport-Bossier City, LA", "Tallulah, LA", "Texarkana, TX", "Tyler, TX", "Vicksburg, MS"]         RegionVII_MinorGeoList = ["Baton Rouge, LA", "Bogalusa, LA", "Crowley, LA", "Gulfport-Biloxi, MS", "Hammond, LA", "Houma-Bayou Cane-Thibodaux, LA", "Jennings, LA", "Lafayette, LA", "Lakes Charles, LA", "McComb, MS", "Morgan City, LA", "New Iberia, LA", "New Orleans-Metairie-Kenner, LA", "Opelousas-Eunice, LA", "Picayune, MS", "Pierre Part, LA"]         RegionVIII_MinorGeoList = ["Alice, TX", "Austin-Round Rock-San Marcos, TX", "Bay City, TX", "Brenham, TX", "Brownsville-Harlingen", "College Station-Bryan, TX", "Corpus Christi, TX", "El Campo, TX", "Huntsville, TX", "Kileen-Temple-Fort Hood, TX", "Kingsville, TX", "Marble Falls, TX", "McAllen-Edinburg-Mission, TX", "Raymondville, TX", "Rio Grande City-Roma, TX", "San Antonio-New Braunfels, TX", "Victoria, TX", "Abbeville, LA", "Beaumont-Port Arthur, TX", "DeRidder, LA", "Houston-Sugar Land-Baytown, TX", "Jennings, LA", "Lake Charles, LA"]          #If the current selection is 'National', jump to the 'National' Spatial Bookmark. MAP_QuickJump_MinorGeoLevel_CBX and MAP_QuickJump_SubGeoLevel_CBX remain disabled from Initialization.         if selection == "National":             QuickJump_MinorGeoLevel_CBX.enabled = False             QuickJump_MinorGeoLevel_CBX.refresh()             QuickJump_SubGeoLevel_CBX.enabled = False             QuickJump_SubGeoLevel_CBX.refresh()             # Set the MXD and DataFrame variables             mxd = arcpy.mapping.MapDocument("Current")             df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]             print "mxd and df set as Map Document and DataFrame variables"             #'Jump' to the 'National' Spatial Bookmark             for bkmk in arcpy.mapping.ListBookmarks(mxd, "National", df):                 df.extent = bkmk.extent                 print "Jumped to 'National' extent"                 df.scale *1.1                 print "Applied a 10% buffer to current extent"                 arcpy.RefreshActiveView()                 for lyr in arcpy.mapping.ListLayers (mxd):                     #Find the 'Regions_All' layer in the Layer Index                     if lyr.name == "Regions_All":                         #Clear any currently set Definition Queries from the Layer                         lyr.definitionQuery = ""                         #if the layer visibility is currently set to 'False', set it to 'True', otherwise ignore                         if lyr.visible == False:                             lyr.visible = True                             print "Set 'Regions_All' layer visibility to 'True'"                             arcpy.RefreshActiveView()                         else:                             pass          #if the current selection is 'National-Direct' , refresh the MinorGeoLevel combobox in the UI         elif selection == "National-Direct":             QuickJump_MinorGeoLevel_CBX.enabled = True             QuickJump_MinorGeoLevel_CBX.items = ND_MinorGeoList             QuickJump_MinorGeoLevel_CBX.refresh()             print "Refreshed MinorGeoLevel"             mxd = arcpy.mapping.MapDocument("Current")             print "mxd set as MapDocument variable"             df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]             print "df set as Business Analyst Map dataframe variable."             #'Jump' to the 'National-Direct' Spatial Bookmark             for bkmk in arcpy.mapping.ListBookmarks(mxd, "National-Direct", df):                 df.extent = bkmk.extent                 print "Jumped to NationalDirectBKMK extent"                 df.scale *1.1                 print "Applied a 10% buffer to current extent"                 arcpy.RefreshActiveView()                 for lyr in arcpy.mapping.ListLayers (mxd):                     #Apply a Definition Query to the 'Regions_All' layer to only display the 'National-Direct' Region                     if lyr.name == "Regions_All":                         lyr.definitionQuery = '"RGN" = 9'                         print "Applied Definition Query to 'Regions_All' layer"                         #if the layer visibility is currently set to 'False', set it to 'True', otherwise ignore                         if lyr.visible == False:                             lyr.visible = True                             print "Set 'Regions_All' layer visibility to 'True'"                             arcpy.RefreshActiveView()                         else:                             pass

View solution in original post

0 Kudos
3 Replies
ChrisFox1
New Contributor
In debugging addins, it is helpful to have the python window open to see if any exceptions are being raised. Are any exceptions being printed to the python window? In addition you might want to add some print statements to your code while debugging which will print to the python window. This will help you see what code is being reached or what the value of specific variables are.

Looking at your add-in I see a problem that might be causing the issue. The ID's of your combo boxes are a little strange. Normally this is the structure:

namespace.id

From the comments in the code here are your combox boxes IDs:

QuickJump_MajorGeoLevel.cbx
QuickJump_MinorGeoLevel.cbx

So technically the ID of both combo boxes is "cbx", this could cause a problem. The namespace is generally the same as the name of your add-in. Instead I think you would want something like:

QuickJump.MajorGeoLevelCBX
QuickJump.MinorGeoLevelCBX

Then you would manage the state of each combobox using its ID MajorGeoLevelCBX or MinorGeoLevelCBX

http://resources.arcgis.com/en/help/main/10.1/#/Managing_the_state_of_Python_add_in_types/014p000000...
0 Kudos
JohnDye
Occasional Contributor III
Thanks Chris,
I suppose I was misunderstanding the breakdown of the ID.

I had always assumed the entire portion (namespace.ID) to compose the element ID. Now I know it's just the latter, so I can see there would be a lot of naming conflicts in my code.

I will update those elements and incorporate some print statements and see what I get.

Thanks!
0 Kudos
JohnDye
Occasional Contributor III
So Chris,
You were right. My code was full on name collisions and once I resolved them all and massaged the code a bit more, it worked just fine. For anyone who made read this post down the road, its important to note that in order to get the another element to refresh and enable/disable, you have to call the element by its ID, which is not the same as the Class Name. While I'd known the two were different, I never recognized that there would be any difference between using one or the other. So my Class Names were always identical to my IDs. Hence the naming conflict. The script didn't know whether to call a Class or an ID because they were identical.

You can quickly determine what the ID for a given element in your code by looking directly under the Class Name for the element for the snippet
"""Implementation for MAP.QuickJump_MajorGeoLevel_CBX (ComboBox)"""

where "QuickJump_MajorGeoLevel_CBX" is my element ID. MAP is a reference I used to tell me what toolbar it is loaded on. It's also good to know that you shouldn't expect any assistance from Auto-Complete when referencing the IDs. I'm not exactly sure why that is, but PyScripter didn't give me any assistance with IDs which was confusing at first because I rely on it quite a bit to make sure that my syntax is correct.

So once I updated all of my IDs and ensured there were no conflicts and then changed the code to call the element by ID when enabling or refreshing, all was right with the world again! Here's the code to provide examples for anyone else reading this post.

class MAP_QuickJump_MajorGeoLevel(object):     """Implementation for MAP.QuickJump_MajorGeoLevel_CBX (ComboBox)"""     #Jump to the selected MajorGeoLevel and refresh the Minor and Sub GeoLevel comboboxes if the current selection is anything other than 'National'     def __init__(self):         self.items = ["National", "National-Direct", "Region I", "Region II", "Region III", "Region IV", "Region V", "Region VI", "Region VII", "Region VIII"]         self.editable = False         self.enabled = True         self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXX'         self.width = 'XXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxx'      def onSelChange(self, selection):         mxd = arcpy.mapping.MapDocument("Current")         df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]         ND_MinorGeoList = ["Boston", "Los Angeles", "San Francisco", "Honolulu", "Chicago", "Minneapolis/St. Paul", "New York", "Philadelphia", "Wilmington"]         RegionI_MinorGeoList = ["New York-Northern New Jersey-Long Island, NY-NJ-PA"]         RegionII_MinorGeoList = ["New York-Northern New Jersey-Long Island, NY-NJ-PA"]         RegionIII_MinorGeoList = ["Bridgeport-Stamford-Norwalk, CT", "Hartford West-Hartford East, CT", "New Haven-Milford,CT", "New York-Northern New Jersey-Long Island, NY-NJ-PA", "Poughkeepsie-Newburgh-Middletown, NY", "Torrington, CT", "Trenton-Ewing, NJ", "Allentown-Bethlehem-Easton, PA-NJ", "Philadelphia-Camden-Wilmington, PA-NJ-DE-MD"]         RegionIV_MinorGeoList = ["Baltimore-Townsend, MD", "Cambridge, MD", "Dover, DE", "Easton, MD", "Gettysburg, PA", "Lexington Park, MD", "Ocean Pines, MD", "Salisbury, MD", "Seaford, DE", "Washington-Arlington-Alexandria, DC-VA-MD-WV", "York-Hanover, PA"]         RegionV_MinorGeoList = ["Baltimore-Townsend, MD", "Chambersburg, PA", "Charlottesville, VA", "Culpepper, VA", "Cumberland, MD-WV", "Gettysburg, PA", "Hagerstown-Martinsburg, MD-WV", "Harrisonburg, VA", "Richmond, VA", "Staunton-Waynesboro, VA", "Washington-Arlington-Alexandria, DC, VA-MD-WV", "Winchester,VA-WV"]         RegionVI_MinorGeoList = ["Athens, TX", "Bonham, TX", "Dallas-Fort Worth-Arlington, TX", "Durant, OK", "Gainesville, TX", "Palestine, TX", "Paris, TX", "Sherman-Denison, TX", "Sulpher Springs, TX", "Alexandria, LA", "Baton Rouge, LA", "Crowley, LA", "DeRidder, LA", "Fort Polk South, LA", "Jennings, LA", "Lufkin, TX", "Natchez, MS-LA", "Opelousas-Eunice, LA", "Bastrop, LA", "El Dorado, AR", "Jacksonville, TX", "Longview, TX", "Magnolia, AR", "Marshall, TX", "Minden, LA", "Monroe, LA", "Mount Pleasant, TX", "Nacogdoches, TX", "Natchitoches, LA", "Ruston, LA", "Shreveport-Bossier City, LA", "Tallulah, LA", "Texarkana, TX", "Tyler, TX", "Vicksburg, MS"]         RegionVII_MinorGeoList = ["Baton Rouge, LA", "Bogalusa, LA", "Crowley, LA", "Gulfport-Biloxi, MS", "Hammond, LA", "Houma-Bayou Cane-Thibodaux, LA", "Jennings, LA", "Lafayette, LA", "Lakes Charles, LA", "McComb, MS", "Morgan City, LA", "New Iberia, LA", "New Orleans-Metairie-Kenner, LA", "Opelousas-Eunice, LA", "Picayune, MS", "Pierre Part, LA"]         RegionVIII_MinorGeoList = ["Alice, TX", "Austin-Round Rock-San Marcos, TX", "Bay City, TX", "Brenham, TX", "Brownsville-Harlingen", "College Station-Bryan, TX", "Corpus Christi, TX", "El Campo, TX", "Huntsville, TX", "Kileen-Temple-Fort Hood, TX", "Kingsville, TX", "Marble Falls, TX", "McAllen-Edinburg-Mission, TX", "Raymondville, TX", "Rio Grande City-Roma, TX", "San Antonio-New Braunfels, TX", "Victoria, TX", "Abbeville, LA", "Beaumont-Port Arthur, TX", "DeRidder, LA", "Houston-Sugar Land-Baytown, TX", "Jennings, LA", "Lake Charles, LA"]          #If the current selection is 'National', jump to the 'National' Spatial Bookmark. MAP_QuickJump_MinorGeoLevel_CBX and MAP_QuickJump_SubGeoLevel_CBX remain disabled from Initialization.         if selection == "National":             QuickJump_MinorGeoLevel_CBX.enabled = False             QuickJump_MinorGeoLevel_CBX.refresh()             QuickJump_SubGeoLevel_CBX.enabled = False             QuickJump_SubGeoLevel_CBX.refresh()             # Set the MXD and DataFrame variables             mxd = arcpy.mapping.MapDocument("Current")             df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]             print "mxd and df set as Map Document and DataFrame variables"             #'Jump' to the 'National' Spatial Bookmark             for bkmk in arcpy.mapping.ListBookmarks(mxd, "National", df):                 df.extent = bkmk.extent                 print "Jumped to 'National' extent"                 df.scale *1.1                 print "Applied a 10% buffer to current extent"                 arcpy.RefreshActiveView()                 for lyr in arcpy.mapping.ListLayers (mxd):                     #Find the 'Regions_All' layer in the Layer Index                     if lyr.name == "Regions_All":                         #Clear any currently set Definition Queries from the Layer                         lyr.definitionQuery = ""                         #if the layer visibility is currently set to 'False', set it to 'True', otherwise ignore                         if lyr.visible == False:                             lyr.visible = True                             print "Set 'Regions_All' layer visibility to 'True'"                             arcpy.RefreshActiveView()                         else:                             pass          #if the current selection is 'National-Direct' , refresh the MinorGeoLevel combobox in the UI         elif selection == "National-Direct":             QuickJump_MinorGeoLevel_CBX.enabled = True             QuickJump_MinorGeoLevel_CBX.items = ND_MinorGeoList             QuickJump_MinorGeoLevel_CBX.refresh()             print "Refreshed MinorGeoLevel"             mxd = arcpy.mapping.MapDocument("Current")             print "mxd set as MapDocument variable"             df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]             print "df set as Business Analyst Map dataframe variable."             #'Jump' to the 'National-Direct' Spatial Bookmark             for bkmk in arcpy.mapping.ListBookmarks(mxd, "National-Direct", df):                 df.extent = bkmk.extent                 print "Jumped to NationalDirectBKMK extent"                 df.scale *1.1                 print "Applied a 10% buffer to current extent"                 arcpy.RefreshActiveView()                 for lyr in arcpy.mapping.ListLayers (mxd):                     #Apply a Definition Query to the 'Regions_All' layer to only display the 'National-Direct' Region                     if lyr.name == "Regions_All":                         lyr.definitionQuery = '"RGN" = 9'                         print "Applied Definition Query to 'Regions_All' layer"                         #if the layer visibility is currently set to 'False', set it to 'True', otherwise ignore                         if lyr.visible == False:                             lyr.visible = True                             print "Set 'Regions_All' layer visibility to 'True'"                             arcpy.RefreshActiveView()                         else:                             pass
0 Kudos