Arcpy zoom to selected features. Here's what I've got so far.

Arcpy zoom to selected features GetParameterAsText(0) userParcel = arcpy. CopyFeatures_management (selected_features, pipes) #Now do all Aug 24, 2022 · It helps viewers understand where each feature is located as they pan and zoom to various extents. Jun 21, 2024 · I am trying to go through the features of a feature class one by one, selecting one feature class and zooming to it. zoomToSelectedFeatures() zooms to features that are selected inside the dataframe. I simplified the code right now until i can move on to something more complex involving labeling multiple features, selecting multiple features, and looping through the select, zoom and export of maps. management. However the selecting features and zooming in on selected features does not work. ListDataFrames(MXD, "Web Mercator")[0] dataframe. ListDataFrames(MXD, "Layers")[0] dataframe. MapDocument('current') dataframe = arcpy. Jun 14, 2024 · The ArcMap script using dataframe. mp. SearchCursor(messageSorted, ["TRM", "Downloaded"]) as getDefinition (cim_version) Returns a map frame element's CIM definition. I have copied the code below. stackexchange. If you want access to the feature, use a data access cursor. MapDocument ("CURRENT") # df is the dataframe, Layers is used to run through all the layers within the mxd. mapping. Apperantely, in V 10. 3570. aprx= arcpy. com/roelvandepaarWith thanks & praise to God, and wi Nov 23, 2020 · How to zoom to selected feature in ArcGIS Pro SDK Framework. import arcpy mxd = arcpy. Feb 18, 2013 · I've solved it! I deleted the df. I chose a Python Toolbox tool so I get to know this new 10. View solution in original post Sep 18, 2024 · In this blog post we will assess using ArcPy to zoom to a layer or a selection for. getLayerExtent (layer, {selection_only}, {symbolized_extent}) Returns a layer's extent for all features or only the selected features in a layer. Is it possible to get a list of all selected features by using Python? It would be fine if there is a way to get one special (or all) attribute(s) of the selected features stored in a list that can be written into a txt file. zoomToAllLayers(True) You are working with a MapView object which has a zoomToAllLayers() method. activeView returns None because th Select from the current map document, a feature in a layer and zoom to the specified feature. ArcGISProject(aprx) l = aprx. Is it possible to do this in ArcGIS for Nov 26, 2021 · For example, in the screenshot below, I wanted to zoom to the selected feature such that the feature gets at the center of the screen but to have the scale kept the same (12,000) As for the default behavior, when zooming to a selected feature, it gets centered at the middle of the screen with having it fully extended on the screen and thus the Nov 16, 2018 · My code runs with no errors. Click Save. env. From this ArcGISProject object we can access the Map Layout as a Layout object, and from our Layout object we an access a MapFrame object which has a Map object as a property and from that Map object we can access our Layer object for which we want to zoom to. But when I run the following arcpy script, it stays very zoomed out. SelectLayerByAttribute_management ("Road", "NEW_SEL. e manual zooming is required to get to a level where the selected feature is distinguishable. SelectLayerByLocation_management, but you cannot do selection directly from feature, you should create a temporary layer using arcpy. MapDocument('CURRENT') df = arcpy. MapDocument("Current") dataFrame = arcpy. I attempted to locate your submitted Idea but the link is broken. RefreshActiveView() Lets say, I have mapindex shapefile which has a 10 record in the attribute table. MakeFeatureLayer_management (fc, a) ‍ ‍ Make feature layer does not create a temporary feature class. Jump to solution. Learn five ways to zoom to selected features in ArcGIS Pro. import arcpy MXD=arcpy. This zooms to selected feature. I'm relatively new to ArcPy so I'm learning as I'm going. May 2, 2017 · Select to view content in your preferred language. MakeFeatureLayer_management before doing a selection. gdb\\TWP_Messages_Sort" #select the first row of the feature that has not been downloaded previously i = 0 with arcpy. mapping. com/roelvandepaarWith thanks & praise to God, and Jan 15, 2024 · I am using notebooks and arc py to do a definition query, after the def query is done I want to zoom to the layer. # Import modules, setup overwrite in environments import arcpy, os arcpy. Frequent Contributor ‎11-23 May 2, 2017 · Wondering if the zoom to selected feature in ArcPy on the Map View versus the Map Frame has been resolved? I am trying to do a select feature by attribute in Model Builder (ARCPRO) and zoom to the selected features. 4. When a feature is selected in the tree view, the map scale changes to fit the full extent of the selected feature. GIS: Arcpy zoom to selected features not workingHelpful? Please support me on Patreon: https://www. "Layers")[0] for lyr in arcpy. Mar 11, 2014 · Hi, I am trying to write a simple Python add-in that provides a combo box allowing the user to enter a project number. We need to use ArcPy to create an ArcGISProject object which gives us access to the open APRX. I have read online that you can't use 'current' in a geoprocessing service, that's fine. Here is snippet code from the above help: If a layer with a selection is used for the Input Features parameter value and an Expression parameter value is specified, the expression will only be run on the selected features, and the expression-based subset of the selected set will be written to the output feature class. Set the value for the In Beyond option of the scale range on the General tab of the Layer Properties dialog of the point layer, then use the Select by Attributes tool, then use the Zoom to Selected Features option. If you really want a temporary feature class, you should use Copy Features, Feature Class to Feature Class, or one of the other several tools for copying feature classes data. searchcursor() make a python list of those selected features; Iterate through your python list using a unique ID to create and use an SQL expression letting you Select By Attribute, then zoom to selected features. activeView mv. An organization can configure many basemaps to use in web maps. Zoom to selected features. 2], developers can only use arcpy. Feb 9, 2017 · Working on being able to zoom to the extent of features in a search row to produce individual maps for row (like data driven pages but for individual rows on the dataset). To see which basemaps are available for use with the map widget, use the Map's basemap property to initialize a BasemapManager, and then use the basemaps property to return a list of What is arcpy. I'm hoping there is some kind of code that would zoom to the bookmark and then I could tell it to zoom in or out a certain amount from there. zoomToSelectedFeatures() arcpy. ListDataFrames(mxd, "Layers") [0] df. Apr 21, 2010 · Try it again. zoomToSelectedFeatures()方法会缩放至所有图层的全部范围(相当于全图显示)。 Jan 3, 2013 · I trying to create an arcpy script that will run only if there are selected features in a layer, however I can't figure out how to get arcpy to test for selected features. Keep the following in mind when using the FeatureSet object:. Jul 6, 2010 · I got this to work for me, fill in your dataframe name and shapefile name where indicated. Jan 17, 2012 · Everything runs as expected, but the PDF created at the end of the script doesn't represent the data frame of the selected feature. ListDataFrames(doc)[0] # the first data frame MapLayers = arcpy. Each feature in this class is a polygon. The code I've got so far zooms to a global level to fit the entire projection map (MTM7), and doesn't contain the other element in the pre-made layout Oct 10, 2012 · I have the following script to be used inside ArcMap 10. We are using ArcGIS Pro 3. UC2015 - Technical Workshop - Python Map Automation: Introduction to arcpy. But I couldn't even get it to select a feature correctly. mp to change the map extent in the Map Frame but not in the Map itself. People who are not interested about 'zoom to selected' will not check this thread out and will not see your question. Pan/Zoom to selected features in Python Add-in --GeoNet The Esri Community. Jul 31, 2019 · I selected data by using select layer by attribute, then I need to only select these selection and zoom in to the selection. I want to zoom to a selected feature with a python script in ArcPro but I've been looking throughout the arcpy module with no luck. Jan 30, 2020 · I am trying to get the extent of the selected features in arcpy to pass into CreateFishnet. May 2, 2017 · 在本质上,这个方法执行的操作与在ArcMap的菜单栏上单击“Selection | Zoom to Selected Features”所执行的操作是一样的。 其中一个区别是,如果没有选中的要素,DataFrame. Describe(layer). Refer to How To: Automatically zoom in to the selected features from the List widget in ArcGIS Experience Builder for instructions. I want to then zoom to the buffer file. May 3, 2022 · This only gives you a list of objectId values for the selected features, not the actual feature. Jun 15, 2024 · We have an old python script that zooms to the extent of the layers selected in the dataframe. Layer("NP_Allowances") makes a new layer object in memory. Dec 9, 2011 · I was trying to use python for select by attribute using variables from user input. Run. 1 there is an automatic zoom to the selected features, so no command is actually needed, only setting the scale after selection, and deselecting the feature. Subscribe. Or, if you want to run a tool on the selected feature, you can usually just use the layer with the selection as the input and it will only run on the selection. The boolean True argument says we want to use the selection of our layers. camera ext = arcpy. 11-23-2020 01:05 PM. If I right-click on this new layer and click 'Zoom to layer', the tool works fine. 2. mp to change the map extent in ArcGIS Pro:. mapping? • Zoom to selected features Demonstration. The Navigate and Selection groups on the Map tab contain a set of navigation tools that apply to selected features, or you can right-click a layer in the Contents pane to access these commands. zoomToSelectedFeatures() Oct 8, 2019 · #Create temp fc copy b = arcpy. Sep 18, 2024 · The Python Interpreter window will open. Apr 19, 2017 · The problem: When I select a single point feature in a point layer (usually with a large number of features covering a large area) and then do a zoom-to-selected, either via arcpy code or manually in Arcmap, the zoom doesn't zoom in to a sensible scale I. Using Arcpy to zoom to selected feature?-gis. by Amadeus111. I'm very new to scripting and trying to write a simple script that will zoom to a selected feature. 4, I need to create a PDF page of a map layout where the map frame is zoomed to each row in a feature class. extent cam. my code is this, it can zoom in base on the scale I set, but I see other Zoom to selected feature won't work. listElements('MAPFRAME_ELEMENT','Map Frame')[0] #make feature layer or points f2 = fc #make feature layer fl = arcpy. Does anyone know a way to do this? Apr 17, 2024 · proj = arcpy. activeView. For this example, we have one layer called Ireland & UK, a layout named Map Layout, with a MapFrame named Main MapFrame, and our Map view is also named Ireland & UK. 3 I am creating a script to screeshots I'm using df. ArcGISProject("CURRENT") mv = proj. This thread is about 'zoom to selected feature' issue. Jan 14, 2015 · I am trying to use this code but this one requires that a row is selected. Currently I have it working so it will only create a fishnet for the last selected feature because it is just looping through the rows of the features. It does add a new layer to my map, but that layer has 100% of the data from the source feature layer rather than only the ones I had selected (though it is kind of cute that it still has the selection applied so it does copy the knowledge of the selection into the new feature layer). The function in your original question will zoom to the extent of multiple features in multiple layers (which is also what my answer does, which is why it's code is more Aug 10, 2015 · Excuse me for my bad english I'm using ArcGIS 10. Select the Map widget. Apr 27, 2022 · What I'd like to do is set up a script so that, when the user inputs a "block" (integer) and a map layout (the map will eventually contain several layouts), the script will use the main layer's definition query to display only that, and this will then be exported to PDF using the layout. Currently in the latest version of [2. 2. It prompts the user for a shape file, creates a 2 mile buffer around it and then puts the buffered shapefile into a layer group. I just can't seem to get it to zoom to extent? I have looked around but can't find what I need in the syntax help guide. zoomToSelectedFeatures line from the script. 1. The Select Features tool on the Tools toolbar ; The Edit tool on the Production Editing toolbar; Right-click a selected feature in the tree view on the Update tab on the Manage Features window and click Zoom To. setExtent(ext) c_project. ListLayers(mxd, "BLOCK", df): # the "BLOCK Dec 26, 2012 · Assumed I have one layer in ArcMap and I have selected two of five features. 解决方案. Related topics May 2, 2025 · Zoom the view to the extent of the selected features in the map or scene. ListLayers(doc,"LayerName",dataFrame) Layer = MapLayers[0] Layer I'm having a hard time developing a python script tool to automate exportation of layout PDFs while having the map frame zoom into a specific selection of entities depending on the user's input. We are trying to update it for Pro and was hoping someone could point us in the right direction. Jul 14, 2017 · You can incorporate your code as above to include the following: Use arcpy. This code queries a layer for a feature with a specific ID, then zooms the mapframe to the extent of the Apr 12, 2021 · I am attempting to zoom to layer on the map view NOT the layout view. RefreshActiveView() When I publish my service, the zoom feature no longer works. So far I've been messing with arcpy. ListDataFrames(mxd,"put name of top dataframe here")[0] Apr 3, 2019 · #import arcpy module import arcpy arcpy. workspace = "in_memory" selected_features = "The Feature Class with the selection. I cannot seem to find documentation on how to do this, I have figured out the definition query and it works well as seen below- import arcpy # Set the project path to "CURRENT" to use the currently open project project_path = "CURRENT" Apr 6, 2023 · Ugh, yeah, I ran into the same thing w/ MakeFeatureLayer failing to honor the selection. zoomToSelectedFeatures is not layer specific so all selected features across all layers determine the extent, which is the same as zoomToAllLayers. Using the FeatureSet object as input to a tool or function that modifies the input, such as Calculate Field or UpdateCursor, will modify the original feature class. 一、将矢量文件加载到ArcGIS中,并保存为一个MXD地图文件。MXD文件名不要为中文。 Nov 19, 2021 · GIS: Using ArcPy to zoom to selected feature?Helpful? Please support me on Patreon: https://www. Or better option is to create a map series using each polygon as the index and it’ll just do that for you. They can then click buttons to 'draw' (i. Leave Layers as is df = arcpy. Close the Dynamic content panel. save() My issue is that c_project. Below is my code. The zoom would apply to all selected features in all layers in a data frame (but only the first data frame found if the The definition query of the layer and zooming to is the easy part: import arcpy # Assuming that Value is set by the form, there is only one data frame # and the layer name is LayerName doc = arcpy. mapping Nov 27, 2012 · I get lots of these really simple maps, which take 10 minutes to make with a template, but the boss wants them in one minute! So I was told to write a tool to do this. workspace = "D:\\Trimble. However, if someone asks me to create the maps again but zoomed in or out more than that creates a problem because then I have to change all the bookmarks. Configure the List widget to automatically zoom to the selected map feature. GetParameterAsText(1) Dec 14, 2015 · There is an ArcGIS Idea to Allow arcpy. Formerly a Mapping Center Ask a Cartographer Q & A. """ # select by attributes enforcing new selection method to clear any previous selections: SelectLayerByAttribute_management(in_layer_or_view=layer, selection_type='NEW_SELECTION', where_clause=sql) # identify the current map document: mxd = arcpy With this ArcGIS Pro tip I will show you how to quickly zoom to your selected features without having to switch panes or move your mouse all the way to the t I have a layer called carereport, which I then make a feature layer of by providing a gid value. Your code does select the feature, bu Apr 21, 2019 · import arcpy from arcpy import env arcpy. Here's what I've got so far. Script below Jul 31, 2019 · Here is the code that I have: import arcpy # uses the mxd that is running this code mxd = arcpy. patreon. I've read posts about using GetCount, however this seems to only work if there is a difference in the number of selected features to the full feature count of the layer. e. It's as if some other features are selected, but I can't see where. gdb" #create variable of the sorted message and township feature class messageSorted = "D:\\Trimble. overwriteOutput = True # User input variables mapTitle = arcpy. MakeFeatureLayer(f2,f2) # Aug 26, 2011 · Thanks! That mostly works better than what I had written. I am aware that I can zoom to a layer using the code below cam = c_project. zoomToSelectedFeatures () arcpy. I thought that since my "layer" that I'm selecting on is actually a feature class that I had to change it into a layer using MakeFeatureLayer. SearchCursor, to iterate the selection of the features. You have introduced a very different question in it. Make sure map is open and a feature is selected. I tried to use pan to selected but since since I do not really have the Nov 8, 2024 · In this example, 'Restaurant' is selected. Once you have the layer object, use select layer by attributes and assign the result to a variable then use zoom to layer. But if NP_Allowances is also a feature class or layer file in your current workspace, lyr = arcpy. shp" pipes = "the new feature class to convert to a layer" #this will create a new feature class from the selected features but will do it In Memory arcpy. _____Follow us on Social Media! Twitter: https://twitter. 1 feature, and practice my Python a bit, at which I am a beginner--at bes Looks like you are trying to select and zoom to only 1 single feature in 1 single layer (which you did not specify in your original question). Thanks! Dec 7, 2012 · Hi all, I have been told that in ArcGIS 10 we can now script display behaviors. SelectLayerByAttribute_management and location using arcpy. Any help would be great. Panning to specific feature using ArcPy?-gis. select all the pipe features in that project), pan to (select the pipes in the project, then pan to them, keeping the current scale) or Discussion. com/Esri Jul 15, 2019 · In ArcGIS Pro 2. That makes things a bit easier. If the selected features do not contain any features that match the Sep 6, 2017 · I'm not sure why it works once, but I think the problem has something to do with that df. Ask Question Asked 7 years, 4 months ago. Regarding your if/else structure, Jul 12, 2016 · Yo can do selection by both attribute using arcpy. Use QueuedTask. da. This method must be called on the MCT. Here is the code I have currently: Yeah. listLayouts("Layout")[0] mf = l. htxif dsdf itdpf rfyaz hcllfs hii mjvm bivsu drfthwjx saphw