corea

"CURRENT" mxd issues when called from a tool

Discussion created by corea on Mar 19, 2012
Latest reply on Mar 20, 2012 by jbarrette-esristaff
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. When the mxd name is hardcoded the code works fine but I need it to update the currently open map. It works fine with mapdocument("current") when run in the python window from arcmap but I need it to work as a tool.

Issues
1. Error [[: Object: CreateObject cannot open map document]] I have to set the map doc to be the current workspace
2. When run in the python window the symbology is not updated.
3. It should only update the map frame/toc once everything is added

Thanks,


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)

Outcomes