This should be a really simple process but I am having issues. I want to search a workspace for all files with a certain string and then add them to the current workspace with a selected symbology.
Issues:
- Error [[: Object: CreateObject cannot open map document]] I have to set the map doc to be the current workspace
- When run in the python window the symbology is not updated.
- It should only update the map frame/toc once everything is added
Code:
import os, arcpy, arcpy.mapping
from arcpy import env
GDB = arcpy.GetParameterAsText(0)
Text = arcpy.GetParameterAsText(1)
symbologyLayer = arcpy.GetParameterAsText(2)
#OutputGDB = arcpy.GetParameterAsText(3)
arcpy.env.workspace=GDB
mxd=arcpy.mapping.MapDocument("CURRENT")
list=arcpy.ListFeatureClasses('*'+Text+'*')
for layer in list:
dataFrame = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
addLayer = arcpy.mapping.Layer(layer)
arcpy.mapping.AddLayer(dataFrame, addLayer, "BOTTOM")
arcpy.ApplySymbologyFromLayer_management (addLayer, symbologyLayer)
# Clean up the MapDocument object by deleting it
#del mxd
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
ERROR DETAILS
Messages
Executing: ProcessDatasets22 P:\2012\Job_044_DM_Radio_Propogation\Working\FinalPropogation\cb_BEL07\working\bel07.gdb _dow P:\2012\Job_044_DM_Radio_Propogation\Working\signal_strength_poly.lyr Start Time: Mon Mar 19 14:11:27 2012 Running script ProcessDatasets22... : Object: CreateObject cannot open map document Failed to execute (ProcessDatasets22). Failed at Mon Mar 19 14:11:27 2012 (Elapsed Time: 0.00 seconds)
Answer
found the answer -it has to run in the foreground and can not be in the background or from a catalog session.
No comments:
Post a Comment