Select to view content in your preferred language

IOError when calling Style File

990
3
06-14-2013 06:05 AM
JiaxinYu
Deactivated User
Hello,

I've started to experiment with batch creating large number of mxd recently. I have been running into an IOError when calling the .style file, and hoping someone can shred some light on the issue.

Here is the code: I'm trying to call a legend item from the user's style file through "arcpy.mapping.ListStyleItems".

import arcpy, os, sys, os.path


##ExportLyr = arcpy.GetParameterAsText(0)
##DummieMXD = arcpy.GetParameterAsText(1)
##MXDforExport = arcpy.GetParameterAsText(2)
##JPEG = arcpy.GetParameterAsText(3)

#EnvironmentalSetting

styleFile = r"C:\Temp\I68078.style"

##styleFile = r'C:\Users\i68078\AppData\Roaming\ESRI\Desktop10.1\ArcMap\I68078.style'
print os.path.isfile(styleFile)

mxd = arcpy.mapping.MapDocument(DummieMXD)
mxd.activeView = 'PAGE_LAYOUT'
df = arcpy.mapping.ListDataFrames(mxd)[0]


styleItem = arcpy.mapping.ListStyleItems(styleFile, "Legend Items", "*")


for l in arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT"):       
        l.autoAdd=True        
        l.elementPositionX = 0.94
        l.elementPositionY = 8.9        
        l.elementHeight = 0.25
        l.elementWidth = 0.25
        l.title = "Legend"
        addLayer = arcpy.mapping.Layer(ExportLyr)
        arcpy.mapping.AddLayer(df, addLayer,"TOP")
        for lyr in arcpy.mapping.ListLayers(mxd):
                lyr.showLabels = True
                if lyr.supports("LABELCLASSES"):
                        print lyr.name
                        for lblClass in lyr.labelClasses:
                                if lblClass.showClassLabels:
                                        print lblClass.className
                                        l.updateItem(lyr, styleItem)
                                
styleItem = arcpy.mapping.ListStyleItems(customStylePath, "Legend Items", "ESRI_Style")



df.extent = lyr.getSelectedExtent(True)
df.scale = 6000000
df = 'PAGE_lAYOUT'
arcpy.RefreshActiveView()
mxd.saveACopy(MXDforExport)
arcpy.mapping.ExportToJPEG(mxd, JPEG, df, df_export_width=3000, df_export_height=2200, resolution=150)

print "done"
del arcpy, mxd, addLayer, lyr, df




every time when the code is run, even though os.path.isfile(styleFile) is output as "True". I would get following IOError:

True

Traceback (most recent call last):
  File "C:\Work\Py_Tests\ExportMXD_working.py", line 28, in <module>
    styleItem = arcpy.mapping.ListStyleItems(styleFile, "Legend Items", "*")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 1599, in ListStyleItems
    return convertArcObjectToPythonObject(arcgisscripting._listStyleItems(*gp_fixargs([style_file_path, style_folder_name, wildcard], True, False)))
IOError: Cannot find style called 'C:\Temp\I68078.style'. Make sure the style file exists.




Thank you for all your help!
J-
Tags (2)
0 Kudos
3 Replies
JasonScheirer
Esri Alum
Are you using server or 64 bit geoprocessing? .style files are only supported on Desktop, you may need to switch to .serverstyle files.
0 Kudos
JiaxinYu
Deactivated User
Thank you! The IOError is now gone, but the question that I have now is how do you save a customized style as .ServerStyle file? I haven't been able to find much documentation on it except some sample code that were used for style file ot serverstyle conversion 9.3 and 9.2 ArcGIS.

Thank you for your help,
J-
0 Kudos
JasonScheirer
Esri Alum
Convert your .style files to .serverstyle using MakeServerStyleSet.exe, found in C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\MakeServerStyleSet.exe
0 Kudos