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 )
Solved! Go to Solution.
You can also use ArcPy
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 is an ATTACHREL relationship class print the name of it.
## this would hint that attachments are enabled
for relclass_name in desc["relationshipClassNames"]:
if "ATTACHREL" in relclass_name:
print(relclass_name)
See commented code below for checking if a layer has attachments enabled for a Feature Layer.
from arcgis.gis import GIS
## connect to AGOL
agol = GIS("home")
## access Feature Service Item using Item ID
item = agol.content.get("INSERT_ITEM_ID")
## iterate through layers and print name and if hasAttachments (True or False)
for lyr in item.layers:
print(lyr.properties.name)
print(lyr.properties.hasAttachments)
OK I should have been a bit more specific... this data resides on our oracle server and is publish to portal. I would assume that it would change the syntax a bit?
Where this is referencing AGOL
item = agol.content.get("INSERT_ITEM_ID")
Same principal applies for AGOL/Portal, you can get the feature service item id from the URL when you click into the service item in Portal. Just copy the id into the script.
GIS("home") will access AGOL or Portal depending on which one you are logged into last in ArcGIS Pro.
You could change this to use full parameters
agol = GIS("PORTAL_URL", "PORTAL_USERNAME", "PORTAL_PASSWORD")
You can also use ArcPy
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 is an ATTACHREL relationship class print the name of it.
## this would hint that attachments are enabled
for relclass_name in desc["relationshipClassNames"]:
if "ATTACHREL" in relclass_name:
print(relclass_name)
Thats what I was looking for @Clubdebambos
I wont know the ID unless I look for it... need this to be within Python....
THANK YOU BOTH for your thoughts...
I do get this error though:
Traceback (most recent call last):
File "C:/Users/Ja/Desktop/GIS_projects/Land Use Project Folder/PythonScripts/LUPS_Data_TEST_to_UAT_DESCRIBE.py", line 47, in <module>
for relclass_name in desc1["relationshipClassNames"]:
TypeError: 'geoprocessing describe data object' object is not subscriptable
LayerA_Tst = "Database Connections\\TEST@gis_data.sde\\GIS_DATA.SDE_TEST"
desc1 = arcpy.Describe(LayerA_Tst)
for relclass_name in desc1["relationshipClassNames"]:
if "ATTACHREL" in relclass_name:
print(relclass_name)
I'm using the data access module in mine to access describe as a dictionary rather than a describe object. Change to this line below.
desc1 = arcpy.da.Describe(LayerA_Tst)
Thanks again... missed that...
question: If there are no Attachments there it does nothing... I cant seem to trap if they are there if they are not...
If there are NO attachments I don't get True OR False
for relclass_name in desc1a["relationshipClassNames"]:
if "ATTACHREL" in relclass_name:
print("True")
else:
print("False")
EDIT: I guess I can just play with a variable and change it from True to false and report on that.... I think I can get it to work.... albeit clumsy..