Get workspace from mxd

4710
2
Jump to solution
11-27-2013 03:42 AM
M_DJohnson
Occasional Contributor
Hi All,

I have written script to update data from excel to pgdb for ArcGIS 10 and it is working fine. We have upgraded to 10.1 recently and the script is not working. The ListWorkspaces() give the excel path as well as current workspace pgdb path but in 10.1 it is not written.

import os import arcpy import xlrd  arcpy.env.overwriteOutput = True  inWS = r'C:\SampleData\XXXX\Excels' arcpy.env.workspace = inWS mxd = arcpy.mapping.MapDocument("Current")  workspaces = arcpy.ListWorkspaces() for ws in workspaces:     arcpy.AddMessage(ws)   del mxd, workspaces


The FeatureClasses get from arcpy.mapping.ListLayers(mxd) but to open table the below code is using and update the attributes.

arcpy.env.workspace = ws tableList = arcpy.ListTables()


Please guide me how to get workspace, tablelist by using mxd in ArcGIS 10.1

Regards
Johnson
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
M_DJohnson
Occasional Contributor
The available all files are showing from the specified folder while testing in 10.1 our pgdb kept in another folder hence it is not in the list. However ListLayers return a layer and it has a property workspacepath.

View solution in original post

0 Kudos
2 Replies
M_DJohnson
Occasional Contributor
The listworkspace gives all the available files in the specified folder so all inputs and pgdb are in same folder hence it return mdb file.

Now I need to get list of tables from current mxd. Is it possible ?

Regards
Johnson

Hi All,

I have written script to update data from excel to pgdb for ArcGIS 10 and it is working fine. We have upgraded to 10.1 recently and the script is not working. The ListWorkspaces() give the excel path as well as current workspace pgdb path but in 10.1 it is not written.

import os
import arcpy
import xlrd

arcpy.env.overwriteOutput = True

inWS = r'C:\SampleData\XXXX\Excels'
arcpy.env.workspace = inWS
mxd = arcpy.mapping.MapDocument("Current")

workspaces = arcpy.ListWorkspaces()
for ws in workspaces:
    arcpy.AddMessage(ws)


del mxd, workspaces


The FeatureClasses get from arcpy.mapping.ListLayers(mxd) but to open table the below code is using and update the attributes.

arcpy.env.workspace = ws
tableList = arcpy.ListTables()


Please guide me how to get workspace, tablelist by using mxd in ArcGIS 10.1

Regards
Johnson
0 Kudos
M_DJohnson
Occasional Contributor
The available all files are showing from the specified folder while testing in 10.1 our pgdb kept in another folder hence it is not in the list. However ListLayers return a layer and it has a property workspacepath.
0 Kudos