Closed samisnunu closed 8 years ago
This looks like you were using the old API calls. Not the new once.
As I said, we updated the repo yesterday with a new version. API calls have changed now. They are documented in the readme.
You don't need the .set(), .get(), or .append() methods anymore.
You can write directly to the property. Properties are type sensitive and raise an error if you use the wrong data type.
In you case you would call
metadata.title = "The new title" metadata.abstract = "This is the abstract" metadata.tags = ["foo","bar"] metadata.finish()
What I did is I downloaded the latest arcpy_metadata forlder listed in the repo, -though it shows it was updated 2 months ago, then saved it on "C:\Python27\ArcGIS10.2\Lib\site-packages\".
Then , run a testing script after modifying the methods as to what you described above, and it worked for some metadata elements but not for others.. for example:
metadata.point_of_contact.email = "firstname@address.com" metadata.point_of_contact.role = "Point of Contact" metadata.update_frequency = "As Needed" metadata.update_frequency_description= "As Needed"
None of them has set the values.. I mean no errors encountered but nothing is listed on the Description window in ArcCatalog, regarding of these elements.
Another issue - I have to re-create the feature class before running the script again (in case of editing the metadata values) against the same feature class or I got a runtime error:
<module> C:\Temp\arcpy_metadata-master\testing.py 10
__init__ C:\Python27\ArcGIS10.2\lib\site-packages\arcpy_metadata\metadata_editor.py 121
__init__ C:\Python27\ArcGIS10.2\lib\site-packages\arcpy_metadata\metadata_items.py 27
__init__ C:\Python27\ArcGIS10.2\lib\site-packages\arcpy_metadata\metadata_constructors.py 118
__init__ C:\Python27\ArcGIS10.2\lib\site-packages\arcpy_metadata\metadata_constructors.py 25
value C:\Python27\ArcGIS10.2\lib\site-packages\arcpy_metadata\metadata_constructors.py 142
RuntimeWarning: Input value must be a List or None
I tested it against File GDB and SDE feature classes, with same results.
Hi Sami,
Did you call metadata.finish() when you were done editing? The editing process has a lot of overhead, so it doesn't write the changes back to the feature class until you call the finish method. If you didn't call finish, then ArcCatalog would still show metadata as blank, as you reported.
Could you clarify or rephrase the second issue? I'm not sure if I understand what you mean about needing to recreate it before you run the script again. Could you attach the whole testing.py script? Thanks
Thanks for your prompt response! Yes Nick, the metadata.finish() is in my script,.. I meant not all of the elements that I set in the script have been exported into the destination feature class metadata. Attached is the script that I'm using: testing.zip
For the second issue I need to delete the feature class, and re-create it again (to ensure blank brand new metadata to be filled) then I can run the script to populate it again. I guess it should allow editing the already existing metadata in the feature class. I thought it would be feature class locking issue from ArcCatalog, but after I verified I found that no it's not.
There was a bug on my side. I just pushed an update.
The error you got RuntimeWarning: Input value must be a List or None
should no longer appear
Emails were written to the wrong path. This is also fixed. Update frequency description works fine for me.
Contact role and update frequency are actually drop down list and I haven't implemented this yet. They shouldn't have been listed in the documentation. I deactivated them for now.
@samisnunu please fetch latest code and check again if this works for you
Thanks Thomas, I confirm that fixed the issue according to your comment above, I also I fixed a typo in the element.py script for contact's address city xpath. I also tried to organize the elements for readability according to main sections, and enriched the elements in elements.py (attached),.. please have a look and test it with my updated Testing.py testing.zip
Thanks Sami. I will include your suggestions in the next update.
Closing this ticket
Hi,
During running the following simple test below, I ran into the following errors:
import arcpy_metadata as md import datetime import unittest import os import shutil import arcpy import gc
feaure_class =r"C:\Temp\arcpy_metadata-master\tests\test_data_temp_folder\test.gdb\root_poly" metadata = md.MetadataEditor(feaure_class) metadata.title.set("The metadata title!")
generated_time = "This layer was generated on {0:s}".format(datetime.datetime.now().strftime("%m/%d/%Y %I:%M %p"))
metadata.purpose.set = ("Layer represents locations of the rare Snipe.")
metadata.abstract.append("generated by ___ software") metadata.abstract.append(generated_time) metadata.tags.add(["foo", "bar", "baz"])
metadata.finish() # save the metadata back to the original source feature class and cleanup gc.collect()
At: metadata.title.set(..) metadata.purpose.set (..)
Error encountered: AttributeError: 'str' object has no attribute 'set'
also for: metadata.abstract.append(..)
Error encountered: AttributeError: 'str' object has no attribute 'append'
Also for: metadata.tags.add([..])
Error encountered: AttributeError: 'list' object has no attribute 'add'
I'm using: python 2.7.5 ArcGIS 10.2.2
Please advise, Thanks,