<?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 Re: Creating/Editing Feature Templates via arcpy? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1498767#M70931</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/187023"&gt;@GB_MattPanunto_GISS&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/118951"&gt;@AntEsk&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/118951"&gt;@AntEsk&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wondering if any if you guys have any updates since the last post.&lt;/P&gt;&lt;P&gt;I am trying to do pretty much the exact same thing, create a feature template for points with pre defined set attributes for each point that I have already loaded into the appropriate domain/field group/contingent values. Since there is a lot of points and fields it is a tedious process but doesn't seem like as straight forward as I would have hoped.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jun 2024 23:11:54 GMT</pubDate>
    <dc:creator>wchowster</dc:creator>
    <dc:date>2024-06-27T23:11:54Z</dc:date>
    <item>
      <title>Creating/Editing Feature Templates via arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1315285#M68350</link>
      <description>&lt;P&gt;Part of my workflow is to create feature templates, which can be a tedious process. Is it possible to create/edit templates via arcpy? Having a hard time finding any resources on how to do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GB_MattPanunto_GISS_0-1691093980101.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/77252iE3F3F241225FC2AD/image-size/large?v=v2&amp;amp;px=999" role="button" title="GB_MattPanunto_GISS_0-1691093980101.png" alt="GB_MattPanunto_GISS_0-1691093980101.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 20:57:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1315285#M68350</guid>
      <dc:creator>GB_MattPanunto_GISS</dc:creator>
      <dc:date>2023-08-03T20:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating/Editing Feature Templates via arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1315410#M68353</link>
      <description>&lt;P&gt;I am trying to do this as well, also cannot find any documentation.&lt;/P&gt;&lt;P&gt;i have found that the lyrx file is a json file and there is a featureTemplates section which seems to define default values&lt;/P&gt;&lt;P&gt;so we should be able to modify it,&lt;/P&gt;&lt;P&gt;i just had a go but it didn't work, (i couldn't complete the sketch when editing so i did something wrong)&amp;nbsp;&lt;/P&gt;&lt;P&gt;its Friday arvo, sounds like a job for next week&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 06:51:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1315410#M68353</guid>
      <dc:creator>AntEsk</dc:creator>
      <dc:date>2023-08-04T06:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creating/Editing Feature Templates via arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1318075#M68387</link>
      <description>&lt;P&gt;Editing the "x" files directly is possible but very fragile, there's nothing stopping ESRI from redefining how these files are laid out and breaking your code. The preferred method is to go through the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm" target="_self"&gt;CIM Interfaces&lt;/A&gt; as they have explicit versions that are guaranteed to remain stable across Pro versions. Note that CIM editing is&amp;nbsp;&lt;EM&gt;very&lt;/EM&gt; different from your usual arcpy workflows, you have to work with the various types as they're defined and instantiate new instances using the provided factory functions.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 22:32:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1318075#M68387</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2023-08-11T22:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating/Editing Feature Templates via arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1318204#M68393</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;yes it certainly is a dirty method, i will look into the CIM.&lt;/P&gt;&lt;P&gt;for now, i made a lyrx file with a feature template / symbology using the two fields i wanted, populating one with a temp string, then i just do i bulk replace of the temp string in the lyrx using json&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 00:03:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1318204#M68393</guid>
      <dc:creator>AntEsk</dc:creator>
      <dc:date>2023-08-14T00:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating/Editing Feature Templates via arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1339995#M69005</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm looking into generating Feature Templates with a specific field value for users/editors to access when generating features in feature classes of a geodatabase. I&amp;nbsp;need to be able to set various fields to a specific configuration of&amp;nbsp; values that will change periodically, so I want to script the update in Python.&lt;BR /&gt;&lt;BR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/118951"&gt;@AntEsk&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there documentation that can help me reproduce your .lyrx update via JSON method where you alter the&amp;nbsp;&lt;SPAN&gt;featureTemplates section in the JSON?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/4413"&gt;@DavidSolari&lt;/a&gt;&amp;nbsp;,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;For the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm" target="_self" rel="nofollow noopener noreferrer"&gt;CIM Interfaces&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;method of achieving what I described above the most related documentation I've found are:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/cim-spec/blob/main/docs/v3/CIMVectorLayers.md#cimfeaturelayerdefinition-3" target="_blank" rel="noopener"&gt;CIM FeatureLayerDefinition-3&lt;/A&gt;&amp;nbsp; then &lt;A href="https://github.com/Esri/cim-spec/blob/main/docs/v3/Types.md#editingtemplate" target="_blank" rel="noopener"&gt;EditingTemplate&lt;/A&gt;&amp;nbsp; then it is not clear what I need to work with to edit a field value for a feature template. I'm thinking it may be the&amp;nbsp;&lt;A href="https://github.com/Esri/cim-spec/blob/main/docs/v3/CIMVectorLayers.md#cimrowtemplate" target="_blank" rel="noopener"&gt;CIMBasicRowTemplate&lt;/A&gt; but their isn't much detail describing what impact changes to the properties of this will have or what JSON format to use to alter the defaultValues property.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="108.969px" height="25px"&gt;defaultValues&lt;/TD&gt;&lt;TD width="117.25px" height="25px"&gt;{JSON_object}&lt;/TD&gt;&lt;TD width="146.016px" height="25px"&gt;The default values.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated!!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 13:44:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1339995#M69005</guid>
      <dc:creator>BenCapellGGT</dc:creator>
      <dc:date>2023-10-20T13:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating/Editing Feature Templates via arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1340353#M69016</link>
      <description>&lt;P&gt;to do a global replace on the lyrx file, replacing ##TEMPLATE## with the required values after manually creating a template lyrx file whihc alredy has a feature template using two fields, i am only updating my second field which has a temp value of ##TEMPLATE##&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;with &lt;/SPAN&gt;&lt;SPAN&gt;open&lt;/SPAN&gt;(lyrx_file_pth&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'r+'&lt;/SPAN&gt;) &lt;SPAN&gt;as &lt;/SPAN&gt;f:&lt;BR /&gt;    data = json.load(f)&lt;BR /&gt;    &lt;SPAN&gt;# replace placeholder with op code&lt;BR /&gt;&lt;/SPAN&gt;    d = json.loads(json.dumps(data).replace(&lt;SPAN&gt;'##TEMPLATE##'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;f'&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;op_code&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;))&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN&gt;# back to top of file&lt;BR /&gt;&lt;/SPAN&gt;    f.seek(&lt;SPAN&gt;0&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;# write new file&lt;BR /&gt;&lt;/SPAN&gt;    f.write(json.dumps(d&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;indent&lt;/SPAN&gt;=&lt;SPAN&gt;4&lt;/SPAN&gt;))&lt;BR /&gt;    f.truncate()&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;i have since gone down the lyr_cim method, getting the featureTemplates as an attribute of the lyr_cim object, the featureTemplate&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;lyr_cim = lyr.getDefinition(&lt;SPAN&gt;'V3'&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;ft &lt;SPAN&gt;in &lt;/SPAN&gt;lyr_cim.featureTemplates:&lt;BR /&gt;# do stuff&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 22 Oct 2023 21:47:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1340353#M69016</guid>
      <dc:creator>AntEsk</dc:creator>
      <dc:date>2023-10-22T21:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating/Editing Feature Templates via arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1498767#M70931</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/187023"&gt;@GB_MattPanunto_GISS&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/118951"&gt;@AntEsk&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/118951"&gt;@AntEsk&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wondering if any if you guys have any updates since the last post.&lt;/P&gt;&lt;P&gt;I am trying to do pretty much the exact same thing, create a feature template for points with pre defined set attributes for each point that I have already loaded into the appropriate domain/field group/contingent values. Since there is a lot of points and fields it is a tedious process but doesn't seem like as straight forward as I would have hoped.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2024 23:11:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1498767#M70931</guid>
      <dc:creator>wchowster</dc:creator>
      <dc:date>2024-06-27T23:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating/Editing Feature Templates via arcpy?</title>
      <link>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1498781#M70932</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/802778"&gt;@wchowster&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i had a project code field (&lt;EM&gt;project_code_fld&lt;/EM&gt;) and a project code (&lt;EM&gt;project_code&lt;/EM&gt;)&amp;nbsp; i wanted to populate it with&lt;/P&gt;&lt;P&gt;from memory i had to update lyrx file in three places, the display field, the feature template and the renderer field.&amp;nbsp; below is cobbled together from parts of a larger function, hope if helps&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    for lyr_file_name in layer_lst:
        lyr_pth = os.path.join(temp_lyr_fldr, lyr_file_name)
        lyr_file = arcpy.mp.LayerFile(lyr_pth)
        for lyr in lyr_file.listLayers():
            # Return the layer's CIM definition
            lyr_cim = lyr.getDefinition('V3')

            # update the display field
            try:
                lyr_cim.featureTable.displayField = lyr_cim.renderer.fields[0]
            except:
                lyr_cim.featureTable.displayField = project_code_fld

            # # update the feature template
            for ft in lyr_cim.featureTemplates:
                # assign default value
                ft_default_vals = ft.defaultValues["propertySetItems"]
                ft_default_vals.extend([project_code_fld, project_code])

            # # update the feature renderer field values
            for grp in lyr_cim.renderer.groups:

                for grp_class in grp.classes:
                    # update the second field value to be the project code
                    try:
                        grp_class.values[0].fieldValues.append(project_code)
                    except:
                        msgs.addMessage(f'\t!! cannot update grp_class values for - {lyr.name}')

                # Push the changes back to the layer object
            lyr.setDefinition(lyr_cim)
        lyr_file.save()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2024 23:59:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-editing-feature-templates-via-arcpy/m-p/1498781#M70932</guid>
      <dc:creator>AntDevEsk</dc:creator>
      <dc:date>2024-06-27T23:59:34Z</dc:date>
    </item>
  </channel>
</rss>

