Tired of transferring domains one by one using Domain to Table and Table to Domain? I created a Python script to automate the process! This script transfers all domains (or specific ones) between geodatabases in one go, saving time and effort. Perfect for file geodatabases, enterprise geodatabases, and ArcSDE connections.
How it works:
Provide the source and target geodatabase paths.
Run the script.
All domains are transferred automatically!
This looks great! I did something vaguely similar for our team that created batch procedures to convert Domains to/from Excel files, because it's much faster to reorder and change individual domain entries in Excel than it is using the built-in Domain editor.
A few points on your script that I noticed while reading over it:
Thank you for the detailed feedback and suggestions! I really appreciate your insights. Here’s my response to your points:
arcpy.ValidateTableName: You're absolutely right that arcpy.ValidateTableName exists and could be used here. I wrote the sanitize_table_name function as a learning exercise and to have more control over the sanitization process (e.g., ensuring the name starts with a letter and truncating to 30 characters). However, using arcpy.ValidateTableName would indeed make the code more concise and aligned with ArcPy's built-in functionality. I'll consider refactoring it in the next version!
GDB Inputs as Tool Inputs: Great suggestion! Converting the GDB paths into tool inputs would make the script more user-friendly, especially for colleagues who might not be comfortable editing the script directly. I'll explore wrapping this script into a custom ArcGIS geoprocessing tool with input parameters for the source and target geodatabases.
Combining f-strings and Raw Strings: Glad you found the f-string and raw string combination amusing! It’s one of those Python features that feels like a hidden gem once you realize how well they work together. I use it often for file paths to avoid escaping backslashes while still leveraging the power of f-strings.
Append vs. Replace Domains: Thanks for the detailed suggestions on handling 'APPEND' vs. 'REPLACE'! I agree that this would add valuable flexibility. Here’s how I’m thinking of implementing it:
Add a global input variable to let users choose between 'APPEND' and 'REPLACE' for all domains.
For more granular control, I could create a table or dictionary to specify the behavior for each domain individually.
If I turn this into a geoprocessing tool, I’ll explore using the Validation section to pre-populate a table of domains with default options, as you suggested.
I’ll start with the global input variable and work my way up to the more advanced options.
Unicode Character Compatibility: That’s a great catch! I didn’t consider ArcMap/Python 2 compatibility when using the ✅ emoji. To ensure broader compatibility, I’ll replace it with a basic ASCII character like a checkmark (√) or simply use 'DONE' or 'SUCCESS'. Thanks for pointing that out!
Code Formatting on Forums: Thanks for the tip about using the </> button to format the script on forums! I’ll make sure to do that in future posts to improve readability.
-------------------------
Thank you again for your insightful feedback and for sharing that wonderful quote by Robert A. Heinlein. It’s a great reminder that while we can’t control every outcome, maintaining an optimistic outlook makes the journey more enjoyable—and often more productive! I’ll definitely keep that in mind as I continue refining this script and exploring new ways to improve it.
Looking forward to more discussions like this in the future!
Best regards,
JIMMY