<?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 Troubleshoot custom Metadata Import tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1603687#M74003</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 *in attached file:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcpy import metadata as md

class ImportMetadataTool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Import Metadata Tool"
        self.description = "Imports metadata from a source to a target item in ArcGIS Pro."

    def getParameterInfo(self):
        """Define the tool parameters."""
        params = [
            arcpy.Parameter(
                displayName="Source Metadata",
                name="source_metadata",
                datatype="GPString",
                parameterType="Required",
                direction="Input"
            ),
            arcpy.Parameter(
                displayName="Target Metadata",
                name="target_metadata",
                datatype="GPString",
                parameterType="Required",
                direction="Input"
            ),
            arcpy.Parameter(
                displayName="Enable Automatic Updates",
                name="enable_automatic_updates",
                datatype="GPBoolean",
                parameterType="Optional",
                direction="Input"
            ),
            arcpy.Parameter(
                displayName="Output Location",
                name="output_location",
                datatype="GPString",
                parameterType="Required",
                direction="Input"
            ),
        ]
        return params

    def isLicensed(self):
        """Set whether the tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed. This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter. This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        source_metadata = parameters[0].valueAsText
        target_metadata = parameters[1].valueAsText
        enable_automatic_updates = parameters[2].value
        output_location = parameters[3].valueAsText

        try:
            # Create a Metadata object for the target item
            target_item_md = md.Metadata(target_metadata)
            
            # Import metadata from the source
            target_item_md.importMetadata(source_metadata, output_location)

            # Set automatic updates if enabled
            if enable_automatic_updates:
                target_item_md.metadata_sync_option = 'ALWAYS'
                target_item_md.reload()
            
            # Save the changes to the target metadata
            target_item_md.save()
            messages.addMessage("Metadata imported successfully.")
        
        except Exception as e:
            messages.addErrorMessage(f"An error occurred: {e}")

    #def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return&lt;/LI-CODE&gt;&lt;P&gt;*edit* code added- appreciate the heads up as pasted in fisrt post and got flagged for spam&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Apr 2025 16:37:59 GMT</pubDate>
    <dc:creator>CTalbot</dc:creator>
    <dc:date>2025-04-08T16:37:59Z</dc:date>
    <item>
      <title>Troubleshoot custom Metadata Import tool</title>
      <link>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1603687#M74003</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 *in attached file:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcpy import metadata as md

class ImportMetadataTool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Import Metadata Tool"
        self.description = "Imports metadata from a source to a target item in ArcGIS Pro."

    def getParameterInfo(self):
        """Define the tool parameters."""
        params = [
            arcpy.Parameter(
                displayName="Source Metadata",
                name="source_metadata",
                datatype="GPString",
                parameterType="Required",
                direction="Input"
            ),
            arcpy.Parameter(
                displayName="Target Metadata",
                name="target_metadata",
                datatype="GPString",
                parameterType="Required",
                direction="Input"
            ),
            arcpy.Parameter(
                displayName="Enable Automatic Updates",
                name="enable_automatic_updates",
                datatype="GPBoolean",
                parameterType="Optional",
                direction="Input"
            ),
            arcpy.Parameter(
                displayName="Output Location",
                name="output_location",
                datatype="GPString",
                parameterType="Required",
                direction="Input"
            ),
        ]
        return params

    def isLicensed(self):
        """Set whether the tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed. This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter. This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        source_metadata = parameters[0].valueAsText
        target_metadata = parameters[1].valueAsText
        enable_automatic_updates = parameters[2].value
        output_location = parameters[3].valueAsText

        try:
            # Create a Metadata object for the target item
            target_item_md = md.Metadata(target_metadata)
            
            # Import metadata from the source
            target_item_md.importMetadata(source_metadata, output_location)

            # Set automatic updates if enabled
            if enable_automatic_updates:
                target_item_md.metadata_sync_option = 'ALWAYS'
                target_item_md.reload()
            
            # Save the changes to the target metadata
            target_item_md.save()
            messages.addMessage("Metadata imported successfully.")
        
        except Exception as e:
            messages.addErrorMessage(f"An error occurred: {e}")

    #def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return&lt;/LI-CODE&gt;&lt;P&gt;*edit* code added- appreciate the heads up as pasted in fisrt post and got flagged for spam&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 16:37:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1603687#M74003</guid>
      <dc:creator>CTalbot</dc:creator>
      <dc:date>2025-04-08T16:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshoot custom Metadata Import tool</title>
      <link>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1603763#M74005</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It makes it easier than flippin back and forth between the image and your question&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 14:27:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1603763#M74005</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-04-08T14:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshoot custom Metadata Import tool</title>
      <link>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1603764#M74006</link>
      <description>&lt;P&gt;First thing is, arcpy.conversion.ImportMetadata doesn't have an output path as the second argument, the second argument is Import_Type, and target_md.importMetadata(source_metadata)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;try:
        target_item_md = md.Metadata(target_metadata)

        # Import metadata 
        target_item_md.importMetadata(source_metadata)

        if enable_automatic_updates:
            target_item_md.metadata_sync_option = 'ALWAYS'
            target_item_md.reload()

        target_item_md.save()
        messages.addMessage("Metadata imported successfully.")

        # output location
        if output_location:
            target_item_md.exportMetadata(output_location, "FGDC")
            messages.addMessage(f"Metadata also exported to {output_location}")

    except Exception as e:
        messages.addErrorMessage(f"An error occurred: {e}")&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 08 Apr 2025 14:43:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1603764#M74006</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-04-08T14:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshoot custom Metadata Import tool</title>
      <link>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1604124#M74008</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp;Thank you seems a step in the right direction. the output gdb did not disappear after running this time. although there is no output feature in there though.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:19:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1604124#M74008</guid>
      <dc:creator>CTalbot</dc:creator>
      <dc:date>2025-04-09T11:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshoot custom Metadata Import tool</title>
      <link>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1604233#M74013</link>
      <description>&lt;P&gt;Make sure the output is an .xml file.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if output_location:  
    # Ensure output_location is a folder (not GDB)
    output_xml = os.path.join(output_location, "exported_metadata.xml")  
    target_item_md.exportMetadata(output_xml, "FGDC")  
    messages.addMessage(f"Metadata exported to {output_xml}")  &lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 09 Apr 2025 16:07:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1604233#M74013</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-04-09T16:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Troubleshoot custom Metadata Import tool</title>
      <link>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1659075#M74782</link>
      <description>&lt;P&gt;Now that, at ArcPro 3.5 and AGE 11.5, the metadata tooling is the same across the platform, is it possible to copy XML metadata from a GDB FeatureClass to an AGO/AGE Item without going through an export/import from a particular style sheet?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Oct 2025 16:43:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/troubleshoot-custom-metadata-import-tool/m-p/1659075#M74782</guid>
      <dc:creator>DebbieBull</dc:creator>
      <dc:date>2025-10-20T16:43:30Z</dc:date>
    </item>
  </channel>
</rss>

