Select to view content in your preferred language

Setting Active Data Frame

7127
5
01-03-2011 06:00 AM
JohnStephens
Regular Contributor
I am writing several python scripts for a map automation and export tool.  One of the functions of the tool is to take csv files from a provided path and Make a XY Event layers.  The problem is that I have several data frames and I want to distribute the XY Event layers properly among those data frames.

I have searched the resource center and I have not found anything about activating a specific data frame using python script.  Is there a way to do that?  Or can I tell arcpy.MakeXYEventLayer_management to put the event layer in a specific data frame?

I would appreciate any ideas on the matter.  Thanks!
0 Kudos
5 Replies
JasonScheirer
Esri Alum
0 Kudos
JeffBarrette
Esri Regular Contributor
John,

The first code sample in the MapDocument Class help shows how to do this.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/MapDocument/00s30000000n000000/

Jeff
0 Kudos
JohnStephens
Regular Contributor
Thanks.  I saw that yesterday, but I was trying to do dFrame = mxd.activeView instead of vice versa.  I appreciate it.
0 Kudos
RandyMcGregor
Deactivated User
Thanks.  I saw that yesterday, but I was trying to do dFrame = mxd.activeView instead of vice versa.  I appreciate it.


You have to do a loop and isolate the active data frame. The script below will get the active view (active data frame....) only if you are in Data View and not in Layout View. It might not be the best way. I'm open to better ways....

If you are in Layout View, the returned value for "currentmxd.activeView" is, rather unhelpfully, "PAGE_LAYOUT"

An "activeDataFrame" property for mapdocument that didn't care whether you were in Data View or Layout View would be extremely handy.

I don't at this time know how to get the Active View if you are in Page Layout. If anyone does, I'd love to hear about it.



currmxd = arcpy.mapping.MapDocument("CURRENT")

    dflist = arcpy.mapping.ListDataFrames(currmxd,"*")

    for df in dflist:
     
      if df.name == currmxd.activeView:
        activedf = df
        break
0 Kudos
JeffBarrette
Esri Regular Contributor
We have added a r/o MapDocument.activeDataFrame property to the 10.1 release.
0 Kudos