I figured out the problem with the expression -- extra quotes are needed around the curly braces. Line 28 (or 35 in your snippet) should therefore read:
expression = arcpy.AddFieldDelimiters(fc, fldOID) + " = '{0}'".format(relOID)
Yeah that makes sense. Glad you figured it out.
Hi Xander!
I know this thread is quite old, but I thought I'd give it a try anyway. I'm trying to implement your "QueryRelated Data" function in 10.3 and I'm getting the runtime errors below.
Runtime error
Traceback (most recent call last):
File "<string>", line 36, in <module>
File "<string>", line 17, in main
RuntimeError: cannot open 'C:\PhotoLog\AGO\gdb\GPO_PhotoLog.gdb\Photo_Video_Documentation_ATTACH'
Has anything changed with 10.3 that would cause these errors? I've provided my code as well. Any help would be greatly appreciated!
def main():
global arcpy
import arcpy, os
# fixed settings
fldBLOB = 'DATA'
fldAttName = 'ATT_NAME'
fldRelGID = 'REL_GLOBALID'
# your settings (edit these)
## related feature class
fc = r"C:\PhotoLog\AGO\gdb\GPO_PhotoLog.gdb\Photo_Video_Documentation"
## attachment table
tbl = r"C:\PhotoLog\AGO\gdb\GPO_PhotoLog.gdb\Photo_Video_Documentation_ATTACH"
fldRelatedInfo = 'CreationDate' # should be valid column in FC
with arcpy.da.SearchCursor(tbl,[fldBLOB,fldAttName,fldRelGID]) as cursor:
for row in cursor:
binaryRep = row[0]
fileName = row[1]
relGID = row[2]
# access related information
myRelatedInfo = QueryRelatedData(fc, fldRelatedInfo, relGID)
print myRelatedInfo
def QueryRelatedData(fc, fldRelatedInfo, relGID):
fldGID = 'GlobalID'
expression = arcpy.AddFieldDelimiters(fc, fldGID) + " = '{0}'".format(relGID)
with arcpy.da.SearchCursor(fc, (fldGID, fldRelatedInfo), where_clause=expression) as cursor:
for row in cursor:
return row[1]
break
del row
if __name__ == '__main__':
main()
Hi William Spiking ,
Just did a test with 10.3 and the code (stil) works. I do notice that in the name of the attachment table you have a single underscore:
'C:\PhotoLog\AGO\gdb\GPO_PhotoLog.gdb\Photo_Video_Documentation_ATTACH'
This should be a double underscore __ATTACH:
'C:\PhotoLog\AGO\gdb\GPO_PhotoLog.gdb\Photo_Video_Documentation__ATTACH'
Please try again with that little correction.
That did the trick! Can't believe I missed that!
Thank you!
It is a common mistake as it happened to me too. Due to this kind of errors, I normally tend to copy the path from the source tab of the layer or table to be sure to have the right path and name of the object class,
Would you be able to extend your code in python to be able to access images already stored as a BLOB field in SQL Server 2012 (non-GIS) as attachments without having to copy the images into ESRI feature classes thus eliminating data duplication of attachment files?