Select to view content in your preferred language

Batch add colors to ArcGIS Pro style

262
2
08-29-2024 08:43 AM
Status: Open
Labels (1)
FourCornersMapping
Frequent Contributor

Currently I have to enter color values manually to an ArcGIS Pro Style (.stylx), which is time consuming and laborious. I suggest the ability to add colors to an ArcGIS Pro style with a batch process or as a file. I envision something similar to the process of adding swatch files (.ase) to Adobe Illustrator. Alternatively the user could prepare a .csv with HEX, RGB, CMYK values, etc., color mode, and the other field values in Catalog that must currently be entered manually. 

Screen Shot 08-29-24 at 09.37 AM.PNGScreen Shot 08-29-24 at 09.35 AM.PNGScreen Shot 08-29-24 at 09.37 AM 001.PNGScreen Shot 08-29-24 at 09.37 AM 002.PNGScreen Shot 08-29-24 at 09.38 AM.PNG

 

2 Comments
BrennanSmith1

I agree this would be very useful! I found this post a while back, it seems that this can be done with python, but I never figured it out myself.  Seeing your post inspired me to take another stab at it.  If you update the path to your stylx file and your spreadsheet, something like this should work for you.

 

import sqlite3
import pandas as pd
import json

# Connect to stylx file (tested this on a copy of favorites)
stylx_file = r"C:\Users\username\AppData\Roaming\Esri\ArcGISPro\Favorites - Copy.stylx"
conn = sqlite3.connect(stylx_file)
cursor = conn.cursor()

# Get the items table
cursor.execute("SELECT * FROM Items LIMIT 1000;")
items = cursor.fetchall()
new_id = len(items)+1

# Load in your colors, assuming you have a spreadsheet with the referenced fields
excel_file = r"C:\Users\username\AppData\Roaming\Esri\ArcGISPro\addColors.xlsx"
df = pd.read_excel(excel_file)
df.fillna('', inplace=True)

# Loop through and insert rows
for row in df.itertuples():
    content = {'type':'CIMCMYKColor','values':[row.C, row.M, row.Y, row.K,100-row.alpha]}
    new_row = (new_id,1,row.Category,row.Name,row.Tags,json.dumps(content))
    cursor.execute('INSERT INTO ITEMS(ID, CLASS, CATEGORY, NAME, TAGS, CONTENT) VALUES(?,?,?,?,?,?)', new_row)
    new_id += 1

# save and close
conn.commit()
conn.close()

 

FourCornersMapping

@BrennanSmith1 That's great! I'll check it out! Thanks.