<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Making a Custom Metadata Import tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/making-a-custom-metadata-import-tool/m-p/1603777#M74007</link>
    <description>&lt;P&gt;Try removing the output_location from the importMetaData() and replace it with import_type.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Apr 2025 14:48:48 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2025-04-08T14:48:48Z</dc:date>
    <item>
      <title>Making a Custom Metadata Import tool</title>
      <link>https://community.esri.com/t5/python-questions/making-a-custom-metadata-import-tool/m-p/1603665#M74002</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm troubleshooting this attempted custom metadata import tool&amp;nbsp;&lt;/P&gt;&lt;P&gt;the latest is a curious error of deleting the output location upon completion...&lt;/P&gt;&lt;P&gt;If anyone can give a clue as to why or how to fix would be much appreciated&lt;/P&gt;&lt;P&gt;here's the code:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;import arcpy&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from arcpy import metadata as md&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;class ImportMetadataTool:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;def __init__(self):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;"""Define the tool (tool name is the name of the class)."""&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;self.label = "Import Metadata Tool"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;self.description = "Imports metadata from a source to a target item in ArcGIS Pro."&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;def getParameterInfo(self):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;"""Define the tool parameters."""&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;params = [&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;arcpy.Parameter(&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;displayName="Source Metadata",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;name="source_metadata",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datatype="GPString",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;parameterType="Required",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;direction="Input"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;arcpy.Parameter(&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;displayName="Target Metadata",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;name="target_metadata",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datatype="GPString",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;parameterType="Required",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;direction="Input"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;arcpy.Parameter(&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;displayName="Enable Automatic Updates",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;name="enable_automatic_updates",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datatype="GPBoolean",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;parameterType="Optional",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;direction="Input"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;arcpy.Parameter(&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;displayName="Output Location",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;name="output_location",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;datatype="GPString",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;parameterType="Required",&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;direction="Input"&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;),&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;]&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return params&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;def isLicensed(self):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;"""Set whether the tool is licensed to execute."""&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return True&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;def updateParameters(self, parameters):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;"""Modify the values and properties of parameters before internal&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;validation is performed. This method is called whenever a parameter&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;has been changed."""&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;def updateMessages(self, parameters):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;"""Modify the messages created by internal validation for each tool&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;parameter. This method is called after internal validation."""&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;def execute(self, parameters, messages):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;"""The source code of the tool."""&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source_metadata = parameters[0].valueAsText&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;target_metadata = parameters[1].valueAsText&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;enable_automatic_updates = parameters[2].value&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;output_location = parameters[3].valueAsText&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;try:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;# Create a Metadata object for the target item&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;target_item_md = md.Metadata(target_metadata)&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;# Import metadata from the source&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;target_item_md.importMetadata(source_metadata, output_location)&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;# Set automatic updates if enabled&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;if enable_automatic_updates:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;target_item_md.metadata_sync_option = 'ALWAYS'&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;target_item_md.reload()&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;# Save the changes to the target metadata&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;target_item_md.save()&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;messages.addMessage("Metadata imported successfully.")&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;except Exception as e:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;messages.addErrorMessage(f"An error occurred: {e}")&lt;/EM&gt;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;EM&gt;#def postExecute(self, parameters):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;"""This method takes place after outputs are processed and&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;added to the display."""&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;return&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 12:21:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/making-a-custom-metadata-import-tool/m-p/1603665#M74002</guid>
      <dc:creator>CTalbot</dc:creator>
      <dc:date>2025-04-08T12:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Making a Custom Metadata Import tool</title>
      <link>https://community.esri.com/t5/python-questions/making-a-custom-metadata-import-tool/m-p/1603777#M74007</link>
      <description>&lt;P&gt;Try removing the output_location from the importMetaData() and replace it with import_type.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 14:48:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/making-a-custom-metadata-import-tool/m-p/1603777#M74007</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-04-08T14:48:48Z</dc:date>
    </item>
  </channel>
</rss>

