ImportMetadata_conversion using variables

563
5
07-21-2011 12:25 PM
MikeMacRae
Occasional Contributor III
Hello,

I am trying to loop through a series of feature classes and a series of XML files. I want the loops to match up a feature class with it's associated XML document, and then import the XML into the feature class as metadata.

My script works up to the point that I want to import my metadata using "arcpy.ImportMetadata_conversion" All the print lines work fine and give me the result I am looking for, but I think when I plug some variables into the arcpy.ImportMetadata_conversion syntax, I get this error:


Failed to execute. Parameters are not valid.
ERROR 000816: The tool is not valid.
Failed to execute (ImportMetadata).


I looked up the error online and the solutions don't seem to fit my issue. Can anyone suggest what I may be missing?

    folderPath2 = r"Z:\Metadata\edited"
   
    # loop through folderpath2 and find all files with extension ".XML"
    for filename3 in glob.glob(os.path.join(folderPath2, "*.xml")):

        fullpath2 = os.path.join(folderPath2, filename3)

        # Split file name from full path name to isolate .XML file names
        if os.path.isfile(fullpath2):
            basename2, filename4 = os.path.split(fullpath2)
           #print filename4

            # List feature classes in workspace
            fcList = arcpy.ListFeatureClasses()
            
            # Loop through each deature class in workspace
            for fc in fcList:
                #print fc

                # if fc is equal a certain name and XML file name contains a certain string, then import the XML into the feature class for metadata
                if fc == "DEVELOPMENTAREA_R" and "DEVELOPMENTAREA" in filename3:
                    #print filename4
                    #print fc
                    #print "Match"

                    #this is where script crashes on import
                    arcpy.ImportMetadata_conversion(fc, "FROM_FGDC", shortname)

Tags (2)
0 Kudos
5 Replies
BradPosthumus
Occasional Contributor II
In this line:

arcpy.ImportMetadata_conversion(fc, "FROM_FGDC", shortname)

.. what is "shortname"? It isn't defined anywhere in the code you posted.
0 Kudos
MikeMacRae
Occasional Contributor III
Thanks for pointing that out. That was my old variable. I added in here by mistake. It should have been filename4. Edited script below.


    folderPath2 = r"Z:\Metadata\edited"
   
    # loop through folderpath2 and find all files with extension ".XML"
    for filename3 in glob.glob(os.path.join(folderPath2, "*.xml")):

        fullpath2 = os.path.join(folderPath2, filename3)

        # Split file name from full path name to isolate .XML file names
        if os.path.isfile(fullpath2):
            basename2, filename4 = os.path.split(fullpath2)
           #print filename4

            # List feature classes in workspace
            fcList = arcpy.ListFeatureClasses()
            
            # Loop through each deature class in workspace
            for fc in fcList:
                #print fc

                # if fc is equal a certain name and XML file name contains a certain string, then import the XML into the feature class for metadata
                if fc == "DEVELOPMENTAREA_R" and "DEVELOPMENTAREA" in filename4:
                    #print filename4
                    #print fc
                    #print "Match"

                    #this is where script crashes on import
                    arcpy.ImportMetadata_conversion(fc, "FROM_FGDC", filename4)
0 Kudos
BradPosthumus
Occasional Contributor II
I can't test this out myself but if you need to import the metadata FROM an XML document INTO a feature class, you need to reverse your arguments. The SOURCE of the metadata should be first (i.e. the XML ) and the TARGET should be last (the feature class).

arcpy.ImportMetadata_conversion(filename4, "FROM_FGDC", fc)

My guess is you'll need the full path to your XML, so this may work better:

arcpy.ImportMetadata_conversion(fullpath2, "FROM_FGDC", filename4)
0 Kudos
MikeMacRae
Occasional Contributor III
Brad, thanks for the suggestions. I had a look at the syntax for the import tool and I corrected it as you instructed. I tried to use the fullpath and ran the script and I am getting the same error returned. i think you're on the right track though. I think it has something to do with how the tool is reading the inputs. I just can't figure out what it might be.


    folderPath2 = r"Z:\Metadata\edited"
   
    # loop through folderpath2 and find all files with extension ".XML"
    for filename3 in glob.glob(os.path.join(folderPath2, "*.xml")):

        fullpath2 = os.path.join(folderPath2, filename3)

        # Split file name from full path name to isolate .XML file names
        if os.path.isfile(fullpath2):
            basename2, filename4 = os.path.split(fullpath2)
           #print filename4

            # List feature classes in workspace
            fcList = arcpy.ListFeatureClasses()
            
            # Loop through each feature class in workspace
            for fc in fcList:
                #print fc

                # if fc is equal a certain name and XML file name contains a certain string, then import the XML into the feature class for metadata
                if fc == "DEVELOPMENTAREA_R" and "DEVELOPMENTAREA" in filename4:
                    #print fullpath2
                    #print fc
                    #print "Match"

                    #this is where script crashes on import
                    arcpy.ImportMetadata_conversion(fullpath2, "FROM_FGDC", fc)
0 Kudos
MikeMacRae
Occasional Contributor III
Apparently this is a bug. I had updated the assembly cache a while ago , but my computer was recently upgraded to windows 7, which prompted me to have to reinstall ArcGIS. if anyone is having the same issues, please read this.

Thanks,
Mike
0 Kudos