How I get all names of a Style File Markersymbols with ArcPY

1183
8
Jump to solution
02-02-2017 09:09 AM
UlfSalecker
New Contributor

I build a new true Type Font and I will check the names

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

It isn't your version, I just ran the following on an ArcGIS 10.1 (build 3143) install:

>>> import os
>>> 
>>> style_dir = os.path.join(arcpy.GetInstallInfo()['InstallDir'], 'Styles')
>>> style_file = os.path.join(style_dir, 'ESRI.style')
>>> style_folder = 'Marker Symbols'
>>> 
>>> styles = arcpy.mapping.ListStyleItems(style_file, style_folder)
>>> for style in styles:
...   print style.itemName
...   
Circle 1
Square 1
Triangle 1
...
Rnd Square 6
Rnd Square 7
Dam Lock
>>> 

Please review the documentation.  The style folder name you need to pass isn't a directory on the file system, it is the name of the style folder in the style file itself that you want to get information about.  In this case, with marker symbols, it needs to be "Marker Symbols".  If you were interested in colors, it would be "Colors".

View solution in original post

8 Replies
JoshuaBixby
MVP Esteemed Contributor

Does this work for you:

style_file = # path to style file
style_folder = "Marker Symbols"

styles = arcpy.mapping.ListStyleItems(style_file, style_folder)
for style in styles:
  print style.itemName
0 Kudos
UlfSalecker
New Contributor

Thanks for your answer. I work with ArcGIS V10.1 and I created the following Python Skript: 

import arcpy
style_file = "C:\ArcGIS\Styles"
style_folder = "MVV_Netrion_Bestand_Gas.style"

styles = arcpy.mapping.ListStyleItems(style_file, style_folder)
for style in styles:
   print style.itemName

I get the following errors:

Traceback (most recent call last):
File "C:\ArcGIS\python\read_style.py", line 6, in <module>
styles = arcpy.mapping.ListStyleItems(style_file, style_folder)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line
1599, in ListStyleItems
return convertArcObjectToPythonObject(arcgisscripting._listStyleItems(*gp_fi
xargs([style_file_path, style_folder_name, wildcard], True, False)))
ValueError: StyleGalleryObject: Input value is not valid

Whats the problem?

0 Kudos
NeilAyres
MVP Frequent Contributor

This looks the wrong way round to me.

style_file = "C:\ArcGIS\Styles"
style_folder = "MVV_Netrion_Bestand_Gas.style"

0 Kudos
UlfSalecker
New Contributor

oh sorry, but it doesn work. Ich think its the wrong ArcPY Version. I work with ArcGIS V10.1.

# C:\Python27\ArcGIS10.1\python.exe C:\ArcGIS\python\read_style.py

import arcpy
style_folder = "C:\ArcGIS\Styles"
style_file = "MVV_Netrion_Bestand_Gas.style"

styles = arcpy.mapping.ListStyleItems(style_file, style_folder)
for style in styles:
   print style.itemName

C:\Users\u2267>C:\Python27\ArcGIS10.1\python.exe C:\ArcGIS\python\read_style.py
Traceback (most recent call last):
File "C:\ArcGIS\python\read_style.py", line 7, in <module>
styles = arcpy.mapping.ListStyleItems(style_file, style_folder)
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

0 Kudos
NeilAyres
MVP Frequent Contributor

style_file still needs to be a full path to the style file, including the filename itself.

ListStyleItems—Help | ArcGIS for Desktop 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

It isn't your version, I just ran the following on an ArcGIS 10.1 (build 3143) install:

>>> import os
>>> 
>>> style_dir = os.path.join(arcpy.GetInstallInfo()['InstallDir'], 'Styles')
>>> style_file = os.path.join(style_dir, 'ESRI.style')
>>> style_folder = 'Marker Symbols'
>>> 
>>> styles = arcpy.mapping.ListStyleItems(style_file, style_folder)
>>> for style in styles:
...   print style.itemName
...   
Circle 1
Square 1
Triangle 1
...
Rnd Square 6
Rnd Square 7
Dam Lock
>>> 

Please review the documentation.  The style folder name you need to pass isn't a directory on the file system, it is the name of the style folder in the style file itself that you want to get information about.  In this case, with marker symbols, it needs to be "Marker Symbols".  If you were interested in colors, it would be "Colors".

UlfSalecker
New Contributor

It's work. thanks a lot Joshua

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Glad you got it working.  In order for others to know this thread is answered, please mark a response as correct.