<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcpy Dataframe in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596057#M46644</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok I now have a working script that does everything I wanted to do. Some things i've noticed while running this is hat calculate fields is particularly slow, is there a way to speed it up or another function I can use instead? I took a few things from corea's script, thank you btw it was a great help. I have thought about using the rows part but i'm unsure how to use that exactly. This whole thing has been a wonderful learning process for me and i'm happy I was able to get to where i'm at now, thank you everyone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my script in its current form.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Dataframe To Feature Class tool.
# Pulls the extent of the active dataframe in an mxd, and fills out fields based on input values
# from the user.
# Author:&amp;nbsp; LCpl Patrick Fischer
# Riff.Ibanezius@gmail.com
# 3D Topo Plt, 3D Intel BN, Camp Hansen Okinawa, Japan

import arcpy, os, sys

# Deletes feature class from previous time the script was ran.
arcpy.Delete_management(r"Z:\Training\Python\test_scripts\Extent_map.gdb\polygon")

# Collect Parameters from User input

mxdin = arcpy.GetParameterAsText(0)

mxd = arcpy.mapping.MapDocument(mxdin)

df = arcpy.mapping.ListDataFrames(mxd, "La*") [0] # select main dataframe not location diagram


ext = df.extent
array = arcpy.Array()

array.add(ext.lowerLeft)
array.add(ext.lowerRight)
array.add(ext.upperRight)
array.add(ext.upperLeft)
array.add(ext.lowerLeft)

polygon = arcpy.Polygon(array, df.spatialReference)

arcpy.AddMessage("Extent has successfully been converted to a polygon")


#Checks spatial reference from the dataframe to see if it needs to be transformed into another projection.

if df.spatialReference == "WGS 1984":
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Project_management(polygon, r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon", "C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj")

else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(polygon, r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Already projected into WGS 1984' #change to message box

arcpy.AddMessage("Successfuly projected into WGS 1984")
polypro = r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon"

#add fields to new feature class

arcpy.AddField_management(polypro, "PRODUCT_ID", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PRODUCT_DATE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "SCALE", "FLOAT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "EDITION", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "CLASSIFICATION", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "TYPE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PRODUCER", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "COUNTRY_CODE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "NOTES", "TEXT", "", "", 250, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PDF_PATH", "TEXT", "", "", 250, "", "NULLABLE", "REQUIRED")

#Set parameters for user input

PROID = arcpy.GetParameterAsText(1)
PRODA = arcpy.GetParameterAsText(2)
ED = arcpy.GetParameterAsText(3)
CLA = arcpy.GetParameterAsText(4)
TYP = arcpy.GetParameterAsText(5)
PROD = arcpy.GetParameterAsText(6)
CC = arcpy.GetParameterAsText(7)
NOTES = arcpy.GetParameterAsText(8)
PDF = arcpy.GetParameterAsText(9)

arcpy.AddMessage("Calculating fields based on input values")

#Calculate Fields based on user input
for el in arcpy.mapping.ListLayoutElements(mxd, "DATAFRAME_ELEMENT"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; SCALE = el.scale
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCT_ID", PROID, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCT_DATE", PRODA, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "SCALE", SCALE, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "EDITION", ED, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "CLASSIFICATION", CLA, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "TYPE", TYP, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCER", PROD, "", "") 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "COUNTRY_CODE", CC, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "NOTES", NOTES, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PDF_PATH", PDF, "", "")

arcpy.AddMessage("Succesfully calculated fields, appending to Topo Products feature class.")

Feature = arcpy.GetParameterAsText(10)

arcpy.Append_management(polypro, Feature ", "NO_TEST", "", "")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also sometimes i'll get an error about list is out of range, on one mxd it was due to what I think was to many data frames (around 50), but it happened again on another with just 2 data frames. I've ran this successfully with mxds with up to 5 data frames with no issues. Is this an anomaly or is something seriously wrong?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:35:34 GMT</pubDate>
    <dc:creator>PatrickFischer1</dc:creator>
    <dc:date>2021-12-12T01:35:34Z</dc:date>
    <item>
      <title>Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596052#M46639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi everyone, i'm trying to make a script that does the following&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pulls the coordinates from the active dataframe and inputs them into a polygon for a preselected feature class. In addition populates certain attribute fields from data saved in the MXD such as scale and creation date. Also there are some other particulars in the fields that I want calculate such as Producer, Notes, Product Type, Country Code. I've taken a look at Dataframe Extent under Arcpy and was wondering if it was possible to pull the current extent from the active dataframe. Looking at the example code I made a theory of using the "Current" command to pull the coordinates.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin = -180.0, -90.0
newExtent.XMax, newExtent.YMax = 180.0, 90.0
df.extent = newExtent
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's the example code I found located at &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/DataFrame/00s300000003000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/DataFrame/00s300000003000000/&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp; Any help and advice and help is greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:35:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596052#M46639</guid>
      <dc:creator>PatrickFischer1</dc:creator>
      <dc:date>2021-12-12T01:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596053#M46640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Creating a polygon is fairly simple.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]

extent = df.extent
array = arcpy.Array()

array.add(extent.lowerLeft)
array.add(extent.lowerRight)
array.add(extent.upperRight)
array.add(extent.upperLeft)
array.add(extent.lowerLeft)
 
polygon = arcpy.Polygon(array)
arcpy.CopyFeatures_management(polygon, r"C:\GIS\Default.gdb\polytest")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After that adding fields and inputting some map document properties shouldn't be hard, but I don't have an example of it handy. See &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/MapDocument/00s30000000n000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/MapDocument/00s30000000n000000/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:35:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596053#M46640</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T01:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596054#M46641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a mostly-completed project that makes polygons of the main dataframe of each MXD in a given folder and saves the MXD properties and layer information in a file geodatabase. You can take a look at my code at &lt;/SPAN&gt;&lt;A href="https://bitbucket.org/npeihl/mapindextoolv2/overview"&gt;https://bitbucket.org/npeihl/mapindextoolv2/overview&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I apologize for lack of documentation. I haven't put it into production yet.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2011 14:53:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596054#M46641</guid>
      <dc:creator>deleted-user-1T_bOHag6M8d</dc:creator>
      <dc:date>2011-09-12T14:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596055#M46642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've created a script to do what you need and it's attached. Using the same code structure you should be able to populate the extra fields that you want.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you have any issues please tell me as I would like to improve the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;best,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Sep 2011 21:43:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596055#M46642</guid>
      <dc:creator>George_ChandeepCorea</dc:creator>
      <dc:date>2011-09-12T21:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596056#M46643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I actually was able to work through most of this. I was going to do the fields later as i'm taking this one step at a time. Right now the newest thing I am trying to implement is being able to select which dataframe from the mxd you want to use. The reason for this is that the amount of mxd's i'm looking at 500+ have different dataframe names. Now i'm using arcpy.GetParameter(0) as i'm running this through ArcGIS and not from python so that it is more user friendly to people who do not know python coding. basically rough gist of script so far is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os, sys

mxdin = acrpy.GetParameter(0)


mxd = arcpy.mapping.MapDocument(mxdin)
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]

extent = df.extent
array = arcpy.Array()

array.add(extent.lowerLeft)
array.add(extent.lowerRight)
array.add(extent.upperRight)
array.add(extent.upperLeft)
array.add(extent.lowerLeft)
 
try:

&amp;nbsp; polygon = arcpy.Polygon(array)
&amp;nbsp; arcpy.CopyFeatures_management(polygon, r"C:\GIS\Default.gdb\polytest"

except:
&amp;nbsp; print "Failed to create polygon"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've thought of a couple ways to do it, I haven't tried anything yet though. Some of my ideas were to put the list of dataframes into an array and have a parameter that lets the user select from a drop down list which dataframe to use. Ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:35:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596056#M46643</guid>
      <dc:creator>PatrickFischer1</dc:creator>
      <dc:date>2021-12-12T01:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596057#M46644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok I now have a working script that does everything I wanted to do. Some things i've noticed while running this is hat calculate fields is particularly slow, is there a way to speed it up or another function I can use instead? I took a few things from corea's script, thank you btw it was a great help. I have thought about using the rows part but i'm unsure how to use that exactly. This whole thing has been a wonderful learning process for me and i'm happy I was able to get to where i'm at now, thank you everyone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my script in its current form.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Dataframe To Feature Class tool.
# Pulls the extent of the active dataframe in an mxd, and fills out fields based on input values
# from the user.
# Author:&amp;nbsp; LCpl Patrick Fischer
# Riff.Ibanezius@gmail.com
# 3D Topo Plt, 3D Intel BN, Camp Hansen Okinawa, Japan

import arcpy, os, sys

# Deletes feature class from previous time the script was ran.
arcpy.Delete_management(r"Z:\Training\Python\test_scripts\Extent_map.gdb\polygon")

# Collect Parameters from User input

mxdin = arcpy.GetParameterAsText(0)

mxd = arcpy.mapping.MapDocument(mxdin)

df = arcpy.mapping.ListDataFrames(mxd, "La*") [0] # select main dataframe not location diagram


ext = df.extent
array = arcpy.Array()

array.add(ext.lowerLeft)
array.add(ext.lowerRight)
array.add(ext.upperRight)
array.add(ext.upperLeft)
array.add(ext.lowerLeft)

polygon = arcpy.Polygon(array, df.spatialReference)

arcpy.AddMessage("Extent has successfully been converted to a polygon")


#Checks spatial reference from the dataframe to see if it needs to be transformed into another projection.

if df.spatialReference == "WGS 1984":
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Project_management(polygon, r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon", "C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj")

else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(polygon, r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Already projected into WGS 1984' #change to message box

arcpy.AddMessage("Successfuly projected into WGS 1984")
polypro = r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon"

#add fields to new feature class

arcpy.AddField_management(polypro, "PRODUCT_ID", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PRODUCT_DATE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "SCALE", "FLOAT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "EDITION", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "CLASSIFICATION", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "TYPE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PRODUCER", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "COUNTRY_CODE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "NOTES", "TEXT", "", "", 250, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PDF_PATH", "TEXT", "", "", 250, "", "NULLABLE", "REQUIRED")

#Set parameters for user input

PROID = arcpy.GetParameterAsText(1)
PRODA = arcpy.GetParameterAsText(2)
ED = arcpy.GetParameterAsText(3)
CLA = arcpy.GetParameterAsText(4)
TYP = arcpy.GetParameterAsText(5)
PROD = arcpy.GetParameterAsText(6)
CC = arcpy.GetParameterAsText(7)
NOTES = arcpy.GetParameterAsText(8)
PDF = arcpy.GetParameterAsText(9)

arcpy.AddMessage("Calculating fields based on input values")

#Calculate Fields based on user input
for el in arcpy.mapping.ListLayoutElements(mxd, "DATAFRAME_ELEMENT"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; SCALE = el.scale
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCT_ID", PROID, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCT_DATE", PRODA, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "SCALE", SCALE, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "EDITION", ED, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "CLASSIFICATION", CLA, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "TYPE", TYP, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCER", PROD, "", "") 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "COUNTRY_CODE", CC, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "NOTES", NOTES, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PDF_PATH", PDF, "", "")

arcpy.AddMessage("Succesfully calculated fields, appending to Topo Products feature class.")

Feature = arcpy.GetParameterAsText(10)

arcpy.Append_management(polypro, Feature ", "NO_TEST", "", "")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also sometimes i'll get an error about list is out of range, on one mxd it was due to what I think was to many data frames (around 50), but it happened again on another with just 2 data frames. I've ran this successfully with mxds with up to 5 data frames with no issues. Is this an anomaly or is something seriously wrong?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:35:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596057#M46644</guid>
      <dc:creator>PatrickFischer1</dc:creator>
      <dc:date>2021-12-12T01:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596058#M46645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I find update cursor to be faster than calculate field in most operations.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
rows = arcpy.UpdateCursor(layer)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.values = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For more detail see&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003m000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003m000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:35:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596058#M46645</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T01:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596059#M46646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Ok I now have a working script that does everything I wanted to do. Some things i've noticed while running this is hat calculate fields is particularly slow, is there a way to speed it up or another function I can use instead? I took a few things from corea's script, thank you btw it was a great help. I have thought about using the rows part but i'm unsure how to use that exactly. This whole thing has been a wonderful learning process for me and i'm happy I was able to get to where i'm at now, thank you everyone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Here is my script in its current form.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Dataframe To Feature Class tool.
# Pulls the extent of the active dataframe in an mxd, and fills out fields based on input values
# from the user.
# Author:&amp;nbsp; LCpl Patrick Fischer
# Riff.Ibanezius@gmail.com
# 3D Topo Plt, 3D Intel BN, Camp Hansen Okinawa, Japan

import arcpy, os, sys

# Deletes feature class from previous time the script was ran.
arcpy.Delete_management(r"Z:\Training\Python\test_scripts\Extent_map.gdb\polygon")

# Collect Parameters from User input

mxdin = arcpy.GetParameterAsText(0)

mxd = arcpy.mapping.MapDocument(mxdin)

df = arcpy.mapping.ListDataFrames(mxd, "La*") [0] # select main dataframe not location diagram


ext = df.extent
array = arcpy.Array()

array.add(ext.lowerLeft)
array.add(ext.lowerRight)
array.add(ext.upperRight)
array.add(ext.upperLeft)
array.add(ext.lowerLeft)

polygon = arcpy.Polygon(array, df.spatialReference)

arcpy.AddMessage("Extent has successfully been converted to a polygon")


#Checks spatial reference from the dataframe to see if it needs to be transformed into another projection.

if df.spatialReference == "WGS 1984":
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Project_management(polygon, r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon", "C:\Program Files\ArcGIS\Desktop10.0\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj")

else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(polygon, r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Already projected into WGS 1984' #change to message box

arcpy.AddMessage("Successfuly projected into WGS 1984")
polypro = r"Z:\Training\Python\test_scripts\Extent_Map.gdb\polygon"

#add fields to new feature class

arcpy.AddField_management(polypro, "PRODUCT_ID", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PRODUCT_DATE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "SCALE", "FLOAT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "EDITION", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "CLASSIFICATION", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "TYPE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PRODUCER", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "COUNTRY_CODE", "TEXT", "", "", 50, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "NOTES", "TEXT", "", "", 250, "", "NULLABLE", "REQUIRED")
arcpy.AddField_management(polypro, "PDF_PATH", "TEXT", "", "", 250, "", "NULLABLE", "REQUIRED")

#Set parameters for user input

PROID = arcpy.GetParameterAsText(1)
PRODA = arcpy.GetParameterAsText(2)
ED = arcpy.GetParameterAsText(3)
CLA = arcpy.GetParameterAsText(4)
TYP = arcpy.GetParameterAsText(5)
PROD = arcpy.GetParameterAsText(6)
CC = arcpy.GetParameterAsText(7)
NOTES = arcpy.GetParameterAsText(8)
PDF = arcpy.GetParameterAsText(9)

arcpy.AddMessage("Calculating fields based on input values")

#Calculate Fields based on user input
for el in arcpy.mapping.ListLayoutElements(mxd, "DATAFRAME_ELEMENT"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; SCALE = el.scale
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCT_ID", PROID, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCT_DATE", PRODA, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "SCALE", SCALE, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "EDITION", ED, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "CLASSIFICATION", CLA, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "TYPE", TYP, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PRODUCER", PROD, "", "") 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "COUNTRY_CODE", CC, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "NOTES", NOTES, "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(polypro, "PDF_PATH", PDF, "", "")

arcpy.AddMessage("Succesfully calculated fields, appending to Topo Products feature class.")

Feature = arcpy.GetParameterAsText(10)

arcpy.Append_management(polypro, Feature ", "NO_TEST", "", "")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Also sometimes i'll get an error about list is out of range, on one mxd it was due to what I think was to many data frames (around 50), but it happened again on another with just 2 data frames. I've ran this successfully with mxds with up to 5 data frames with no issues. Is this an anomaly or is something seriously wrong?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I agree with Matthew that you should use a cursor instead of Calculating Fields. An Insert Cursor should work nicely for you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, the "list out of range" error may be due to no Dataframes in the MXD that start with "La" as you specify when you are creating the "df" variable. If ArcPy can't find any dataframes in the MXD that start with "La" then it creates an empty list. Calling the first index "[0]" on an empty list returns the out of range error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596059#M46646</guid>
      <dc:creator>deleted-user-1T_bOHag6M8d</dc:creator>
      <dc:date>2021-12-12T01:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596060#M46647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I agree with Matthew that you should use a cursor instead of Calculating Fields. An Insert Cursor should work nicely for you.&lt;BR /&gt;&lt;BR /&gt;Also, the "list out of range" error may be due to no Dataframes in the MXD that start with "La" as you specify when you are creating the "df" variable. If ArcPy can't find any dataframes in the MXD that start with "La" then it creates an empty list. Calling the first index "[0]" on an empty list returns the out of range error.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So i used cursor and rows and found it much more to my advantage. Works quite nicely. Still want to know how to put the list of dataframes into a list you can select from in arcCatalog.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Sep 2011 06:19:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596060#M46647</guid>
      <dc:creator>PatrickFischer1</dc:creator>
      <dc:date>2011-09-21T06:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596061#M46648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Still want to know how to put the list of dataframes into a list you can select from in arcCatalog.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure I quite understand what you are looking for. You mean just a table of the data frame names?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Sep 2011 13:09:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596061#M46648</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2011-09-21T13:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596062#M46649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Not sure I quite understand what you are looking for. You mean just a table of the data frame names?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That's pretty much what i'm looking for. A table that you can select which data frame you want to take the extent from.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Sep 2011 21:05:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596062#M46649</guid>
      <dc:creator>PatrickFischer1</dc:creator>
      <dc:date>2011-09-21T21:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Dataframe</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596063#M46650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That's pretty much what i'm looking for. A table that you can select which data frame you want to take the extent from.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You could retrieve the dataframes, print them as a list of options for the user and then get the user's response via "raw_input". However, I don't know if this will work when the script is used in an ArcToolbox.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I envision it something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Get a list of dataframes in the mxd and assign the list to df
dataFrames = arcpy.ListDataframes(mxd)

# Give each dataframe in the df list a number starting with 1 using enumerate and make it a dictionary
options = dict(enumerate(dataFrames, 1))

# Show options and let the user select which dataframe
response = int(raw_input("Select the number of the dataframe you want: %s \n" % options.items()))

# Assign df to the user's choice
df = options[response]

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you use that code you may want to build in some try:except clauses to send user-friendly error messages if bad info is entered.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:35:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-dataframe/m-p/596063#M46650</guid>
      <dc:creator>deleted-user-1T_bOHag6M8d</dc:creator>
      <dc:date>2021-12-12T01:35:42Z</dc:date>
    </item>
  </channel>
</rss>

