<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ArcGIS Pro Python Notebook - Download Images From Feature Service Layer &amp;amp; Related Tables in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-python-notebook-download-images-from/m-p/1368630#M77236</link>
    <description>&lt;P&gt;I am running ArcGIS Pro 3.1 and have a working Python notebook that bulk downloads images from a Survey 123 feature layer hosted in an Enterprise Portal. The Survey includes repeats and I want the bulk download to include images associated with these repeats. I have tried everything:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ListRelatedTables and GetRelatedTables have thrown a number of errors that those modules don't exist&lt;/LI&gt;&lt;LI&gt;My current, closest to success result is identifying a relationship class, but the name is not one I can make sense of it and it too is throwing error messages.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;For more context, the feature layer is named WHEG_Old_Field, the related table is displayed as oldfield_repeat_f1:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="notebook_table_name.JPG" style="width: 164px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/91134iBFCAF3CD48C469D8/image-size/large?v=v2&amp;amp;px=999" role="button" title="notebook_table_name.JPG" alt="notebook_table_name.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I look at the table added from S123 I see it named as:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="notebook_table_name_s123.JPG" style="width: 462px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/91135iA487B663B747A1B5/image-size/large?v=v2&amp;amp;px=999" role="button" title="notebook_table_name_s123.JPG" alt="notebook_table_name_s123.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have almost had success with the following, but I'm still getting an error and the output name doesn't make sense to me or where the extra characters are coming from.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Define Download Attachments From Related Table
def download_attachments_from_related_table(related_table_name, global_id, local_directory):
    rel_attach_table = f"{related_table_name}__ATTACH"
    rel_pic_fields = ["ATTACHMENTID", "GLOBALID", "ATT_NAME", "DATA"]

    with arcpy.da.SearchCursor(rel_attach_table, rel_pic_fields, f"GLOBALID = '{global_id}'") as cursor:
        for row in cursor:
            pic_path = os.path.join(local_directory, f"{str(row[0])} {str(row[2])}")
            pic_blob = row[3]
            open(pic_path, 'wb').write(pic_blob.tobytes())
            if exportCSV:
                if not global_id in picDict:
                    picDict[global_id] = [pic_path]
                else:
                    picDict[global_id].append(pic_path)

# Get Related Tables From Selected Feature Layer
def get_related_tables(feature_layer):
    related_tables = []
    for relClass in arcpy.Describe(feature_layer).relationshipClassNames:
        print(f"Found relationship class: {relClass}")  # Print for debugging
        try:
            relClassObj = arcpy.Describe(relClass)
            if relClassObj.isAttachmentRelationship:
                continue  # Skip attachment relationships
            if feature_layer in [relClassObj.originClassNames, relClassObj.destinationClassNames]:
                related_table = relClassObj.originClassNames if feature_layer != relClassObj.originClassNames else relClassObj.destinationClassNames
                related_tables.extend(related_table)
        except Exception as e:
            print(f"Error describing {relClass}: {e}")
    return related_tables&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the output from my debugging, it make no sense. It found a relationship class but it doesn't exist?!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="notebook_table_errors.JPG" style="width: 636px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/91133iC16D50530570C241/image-size/large?v=v2&amp;amp;px=999" role="button" title="notebook_table_errors.JPG" alt="notebook_table_errors.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I can post the whole code if that will help debug, but I'm mostly curious if anyone has any success downloaded image from a primary feature layer AND from all related tables? Any suggestions or examples to share? I have looked extensively and haven't had any luck.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jan 2024 21:13:11 GMT</pubDate>
    <dc:creator>JohnVan_Hoesen1</dc:creator>
    <dc:date>2024-01-10T21:13:11Z</dc:date>
    <item>
      <title>ArcGIS Pro Python Notebook - Download Images From Feature Service Layer &amp; Related Tables</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-python-notebook-download-images-from/m-p/1368630#M77236</link>
      <description>&lt;P&gt;I am running ArcGIS Pro 3.1 and have a working Python notebook that bulk downloads images from a Survey 123 feature layer hosted in an Enterprise Portal. The Survey includes repeats and I want the bulk download to include images associated with these repeats. I have tried everything:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ListRelatedTables and GetRelatedTables have thrown a number of errors that those modules don't exist&lt;/LI&gt;&lt;LI&gt;My current, closest to success result is identifying a relationship class, but the name is not one I can make sense of it and it too is throwing error messages.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;For more context, the feature layer is named WHEG_Old_Field, the related table is displayed as oldfield_repeat_f1:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="notebook_table_name.JPG" style="width: 164px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/91134iBFCAF3CD48C469D8/image-size/large?v=v2&amp;amp;px=999" role="button" title="notebook_table_name.JPG" alt="notebook_table_name.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I look at the table added from S123 I see it named as:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="notebook_table_name_s123.JPG" style="width: 462px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/91135iA487B663B747A1B5/image-size/large?v=v2&amp;amp;px=999" role="button" title="notebook_table_name_s123.JPG" alt="notebook_table_name_s123.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have almost had success with the following, but I'm still getting an error and the output name doesn't make sense to me or where the extra characters are coming from.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Define Download Attachments From Related Table
def download_attachments_from_related_table(related_table_name, global_id, local_directory):
    rel_attach_table = f"{related_table_name}__ATTACH"
    rel_pic_fields = ["ATTACHMENTID", "GLOBALID", "ATT_NAME", "DATA"]

    with arcpy.da.SearchCursor(rel_attach_table, rel_pic_fields, f"GLOBALID = '{global_id}'") as cursor:
        for row in cursor:
            pic_path = os.path.join(local_directory, f"{str(row[0])} {str(row[2])}")
            pic_blob = row[3]
            open(pic_path, 'wb').write(pic_blob.tobytes())
            if exportCSV:
                if not global_id in picDict:
                    picDict[global_id] = [pic_path]
                else:
                    picDict[global_id].append(pic_path)

# Get Related Tables From Selected Feature Layer
def get_related_tables(feature_layer):
    related_tables = []
    for relClass in arcpy.Describe(feature_layer).relationshipClassNames:
        print(f"Found relationship class: {relClass}")  # Print for debugging
        try:
            relClassObj = arcpy.Describe(relClass)
            if relClassObj.isAttachmentRelationship:
                continue  # Skip attachment relationships
            if feature_layer in [relClassObj.originClassNames, relClassObj.destinationClassNames]:
                related_table = relClassObj.originClassNames if feature_layer != relClassObj.originClassNames else relClassObj.destinationClassNames
                related_tables.extend(related_table)
        except Exception as e:
            print(f"Error describing {relClass}: {e}")
    return related_tables&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the output from my debugging, it make no sense. It found a relationship class but it doesn't exist?!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="notebook_table_errors.JPG" style="width: 636px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/91133iC16D50530570C241/image-size/large?v=v2&amp;amp;px=999" role="button" title="notebook_table_errors.JPG" alt="notebook_table_errors.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I can post the whole code if that will help debug, but I'm mostly curious if anyone has any success downloaded image from a primary feature layer AND from all related tables? Any suggestions or examples to share? I have looked extensively and haven't had any luck.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 21:13:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-python-notebook-download-images-from/m-p/1368630#M77236</guid>
      <dc:creator>JohnVan_Hoesen1</dc:creator>
      <dc:date>2024-01-10T21:13:11Z</dc:date>
    </item>
  </channel>
</rss>

