Select to view content in your preferred language

Code - Does Feature Class have attachments

1474
11
Jump to solution
03-01-2023 05:41 AM
kapalczynski
Regular Contributor

Looking for some code that would verify if a Feature Layer has Attachments...

I can check using the describe for many things like if Tracking is Enabled but not sure for attachments I do not see that as a child of DESCRIBE

Thoughts... 

 

 

desc1 = arcpy.Describe(LayerA)
hasEditorTracking = desc1.editorTrackingEnabled
print(hasEditorTracking )

 

 

 

0 Kudos
11 Replies
kapalczynski
Regular Contributor

I just did this with a couple variables:

 

hasAttachments1 = "FALSE"
hasAttachments2 = "FALSE"

for relclass_name in desc1a["relationshipClassNames"]:
    if "ATTACHREL" in relclass_name:
        hasAttachments1 = "True - " + str(relclass_name)
        
for relclass_name in desc2a["relationshipClassNames"]:
    if "ATTACHREL" in relclass_name:
        hasAttachments2 = "True - " + str(relclass_name)

print("---Attachments: " + hasAttachments1)
print("---Attachments: " + hasAttachments2)
0 Kudos
Clubdebambos
Occasional Contributor III
import arcpy

## Path to Feature Class in SDE/GDB
fc = r"path\to\fc"

## get a describe dictionary
desc = arcpy.da.Describe(fc)

## if there are no relationships classes then no attachments
if not desc["relationshipClassNames"]:
    print("FALSE")
## if there are relationship classes
else:
    ## check if there is an ATTACHREL relationship class
    if [relclass_name for relclass_name in desc["relationshipClassNames"] if "ATTACHREL" in relclass_name]:
        print("TRUE")
    ## otherwise no attachments
    else:
        print("FALSE")
~ learn.finaldraftmapping.com
0 Kudos