<?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 Can't change CIM settings from tool box script in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/can-t-change-cim-settings-from-tool-box-script/m-p/1405925#M81472</link>
    <description>&lt;P&gt;I wrote a script that changes the field visibility settings through the CIM. The version I wrote as a script you paste into the Python window in Pro works fine. But the version I wrote to run from a tool box does not, and I'm positive that the settings in the CIM are correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The weird thing is, I have written scripts that change CIM settings from a toolbox script before, and they worked. However, they were changing the symbology, rather than field visibility. Not sure if that would cause the bug. The only other thing I can think of is that the layer I'm changing is the input layer, whereas my other scripts added a new layer and changed that CIM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone else have any ideas? Does this have anything to do with derived output parameters? I still don't understand what those are, even after reading about them multiple times.&lt;BR /&gt;&lt;BR /&gt;Script and settings file screenshot included for good measure...&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scosh_1-1712253006431.png" style="width: 802px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/100094i033F9AC1CB16BD59/image-dimensions/802x677?v=v2" width="802" height="677" role="button" title="Scosh_1-1712253006431.png" alt="Scosh_1-1712253006431.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scosh_2-1712253043503.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/100095i8E5030875BC3DD5D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Scosh_2-1712253043503.png" alt="Scosh_2-1712253043503.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import pandas as pd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;layer = arcpy.GetParameter(0)&lt;BR /&gt;view_type = arcpy.GetParameter(1)&lt;BR /&gt;field_settings_path = arcpy.GetParameterAsText(2)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;settings = {}&lt;/P&gt;&lt;P&gt;settings['All Fields'] = []&lt;BR /&gt;settings_df = pd.read_excel(field_settings_path, view_type)&lt;BR /&gt;for visibility_setting in ['Visible Fields', 'Invisible Fields']:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fields_df = settings_df.loc[settings_df[visibility_setting].notnull(), [visibility_setting]]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_list = list(fields_df[visibility_setting])&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; settings[visibility_setting] = field_list&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; settings['All Fields'] += field_list&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fields = arcpy.ListFields(layer)&lt;BR /&gt;fields = [x.name for x in fields]&lt;BR /&gt;missing_fields = set(fields).difference(set(settings['All Fields']))&lt;BR /&gt;if len(missing_fields) &amp;gt; 0:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddError("!!!You are missing these fields from your {} settings:\n{}".format(SETTING_TYPE, '\n'.join(missing_fields)))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;any_field = arcpy.ListFields(layer)[0]&lt;BR /&gt;arcpy.management.AlterField(layer, any_field.name) # populates CIM with all field objects&lt;BR /&gt;cim = layer.getDefinition('v3')&lt;BR /&gt;fieldDescriptions = cim.featureTable.fieldDescriptions&lt;/P&gt;&lt;P&gt;my_fields = {}&lt;BR /&gt;for field in fieldDescriptions:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; my_fields[field.fieldName] = field&lt;/P&gt;&lt;P&gt;new_field_list = []&lt;/P&gt;&lt;P&gt;for name in settings['Visible Fields']:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_object = my_fields[name]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_object.visible = 'true'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new_field_list.append(field_object)&lt;/P&gt;&lt;P&gt;for name in settings['Invisible Fields']:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_object = my_fields[name]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_object.visible = 'false'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new_field_list.append(field_object)&lt;/P&gt;&lt;P&gt;### this printout confirms that I have the correct settings on the fields&lt;BR /&gt;for x in new_field_list:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddMessage("{}: {}".format(str(x.fieldName), str(x.visible)))&lt;/P&gt;&lt;P&gt;cim.featureTable.fieldDescriptions = new_field_list&lt;BR /&gt;layer.setDefinition(cim)&lt;/P&gt;&lt;P&gt;arcpy.AddMessage('All Done!')&lt;/P&gt;</description>
    <pubDate>Thu, 04 Apr 2024 18:22:22 GMT</pubDate>
    <dc:creator>Scosh</dc:creator>
    <dc:date>2024-04-04T18:22:22Z</dc:date>
    <item>
      <title>Can't change CIM settings from tool box script</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/can-t-change-cim-settings-from-tool-box-script/m-p/1405925#M81472</link>
      <description>&lt;P&gt;I wrote a script that changes the field visibility settings through the CIM. The version I wrote as a script you paste into the Python window in Pro works fine. But the version I wrote to run from a tool box does not, and I'm positive that the settings in the CIM are correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The weird thing is, I have written scripts that change CIM settings from a toolbox script before, and they worked. However, they were changing the symbology, rather than field visibility. Not sure if that would cause the bug. The only other thing I can think of is that the layer I'm changing is the input layer, whereas my other scripts added a new layer and changed that CIM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone else have any ideas? Does this have anything to do with derived output parameters? I still don't understand what those are, even after reading about them multiple times.&lt;BR /&gt;&lt;BR /&gt;Script and settings file screenshot included for good measure...&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scosh_1-1712253006431.png" style="width: 802px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/100094i033F9AC1CB16BD59/image-dimensions/802x677?v=v2" width="802" height="677" role="button" title="Scosh_1-1712253006431.png" alt="Scosh_1-1712253006431.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scosh_2-1712253043503.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/100095i8E5030875BC3DD5D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Scosh_2-1712253043503.png" alt="Scosh_2-1712253043503.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import pandas as pd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;layer = arcpy.GetParameter(0)&lt;BR /&gt;view_type = arcpy.GetParameter(1)&lt;BR /&gt;field_settings_path = arcpy.GetParameterAsText(2)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;settings = {}&lt;/P&gt;&lt;P&gt;settings['All Fields'] = []&lt;BR /&gt;settings_df = pd.read_excel(field_settings_path, view_type)&lt;BR /&gt;for visibility_setting in ['Visible Fields', 'Invisible Fields']:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fields_df = settings_df.loc[settings_df[visibility_setting].notnull(), [visibility_setting]]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_list = list(fields_df[visibility_setting])&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; settings[visibility_setting] = field_list&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; settings['All Fields'] += field_list&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fields = arcpy.ListFields(layer)&lt;BR /&gt;fields = [x.name for x in fields]&lt;BR /&gt;missing_fields = set(fields).difference(set(settings['All Fields']))&lt;BR /&gt;if len(missing_fields) &amp;gt; 0:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddError("!!!You are missing these fields from your {} settings:\n{}".format(SETTING_TYPE, '\n'.join(missing_fields)))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;any_field = arcpy.ListFields(layer)[0]&lt;BR /&gt;arcpy.management.AlterField(layer, any_field.name) # populates CIM with all field objects&lt;BR /&gt;cim = layer.getDefinition('v3')&lt;BR /&gt;fieldDescriptions = cim.featureTable.fieldDescriptions&lt;/P&gt;&lt;P&gt;my_fields = {}&lt;BR /&gt;for field in fieldDescriptions:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; my_fields[field.fieldName] = field&lt;/P&gt;&lt;P&gt;new_field_list = []&lt;/P&gt;&lt;P&gt;for name in settings['Visible Fields']:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_object = my_fields[name]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_object.visible = 'true'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new_field_list.append(field_object)&lt;/P&gt;&lt;P&gt;for name in settings['Invisible Fields']:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_object = my_fields[name]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field_object.visible = 'false'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; new_field_list.append(field_object)&lt;/P&gt;&lt;P&gt;### this printout confirms that I have the correct settings on the fields&lt;BR /&gt;for x in new_field_list:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; arcpy.AddMessage("{}: {}".format(str(x.fieldName), str(x.visible)))&lt;/P&gt;&lt;P&gt;cim.featureTable.fieldDescriptions = new_field_list&lt;BR /&gt;layer.setDefinition(cim)&lt;/P&gt;&lt;P&gt;arcpy.AddMessage('All Done!')&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2024 18:22:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/can-t-change-cim-settings-from-tool-box-script/m-p/1405925#M81472</guid>
      <dc:creator>Scosh</dc:creator>
      <dc:date>2024-04-04T18:22:22Z</dc:date>
    </item>
  </channel>
</rss>

