<?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: arcpy.charts fails using MakeFeatureLayer in standalone script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-charts-fails-using-makefeaturelayer-in/m-p/1266221#M67049</link>
    <description>&lt;P&gt;Outside of Pro, the script knows nothing about the Project&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Valid data sources include paths to datasets, including local datasets, UNC paths, and service URLs, and arcpy.mp Layer objects.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;From the help topic on line charts, you might want to try saving your layer as a *.lyrx and use the full path to it as the datasource&lt;/P&gt;</description>
    <pubDate>Thu, 09 Mar 2023 21:39:06 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2023-03-09T21:39:06Z</dc:date>
    <item>
      <title>arcpy.charts fails using MakeFeatureLayer in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-charts-fails-using-makefeaturelayer-in/m-p/1266142#M67048</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;Got an odd one with the charts module and MakeFeatureLayer.&amp;nbsp; Code will work fine if you run it inside the ArcPro py window but if it's outside ArcPro as standalone script or run from inside a GP toolbox script, the result is a catastrophic app crash with the 'please report crash dialog' showing up &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;basic code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os
source_fc = "chart-issues.gdb\\pts"
profile_name = "AB"
query_def = "Name='{}'".format(profile_name)
print(query_def)
r_chart_layer = arcpy.management.MakeFeatureLayer(source_fc, "chart_layer", query_def, None, None)
profile_chart = arcpy.charts.Line(
                x="M",
                y=["Z"],
                dataSource = r_chart_layer.getOutput(0), 
                title="Elevation Over Distance: {}".format(profile_name),
                xTitle = "Distance (Feet)",
                yTitle = "Elevation (Feet)"
            )
print("chart initialized")
chart_path = arcpy.CreateUniqueName(os.path.join("{}.svg".format(profile_name)), arcpy.env.scratchFolder)
print(chart_path)
profile_chart.exportToSVG(chart_path, 500, 500)
print("qed")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried a ton of variations and found a few extra nuggets.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I know the feature class and feature layer are correct.&amp;nbsp; If I set the dataSource = source_fc, chart generates without error but i don't get the filter applied so it's not 'path to data kind of issue'&lt;/LI&gt;&lt;LI&gt;If I export the layer to a table or lyrx it will also work but 'why do i have to add an extra step to write data back to disk'?&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;If I add: print(r_chart_layer.getOutput(0).dataSource)&lt;UL&gt;&lt;LI&gt;It will print out the expected path to the feature class&lt;/LI&gt;&lt;LI&gt;Oddly, this changes the failure, it's no longer an app crash but generates this error message:&lt;UL&gt;&lt;LI&gt;Traceback (most recent call last):&lt;BR /&gt;File "D:\support\arcgis\chart-issues\create-chart.py", line 39, in &amp;lt;module&amp;gt;&lt;BR /&gt;profile_chart.exportToSVG(chart_path, 500, 500)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\charts.py", line 449, in exportToSVG&lt;BR /&gt;svgRes = self.getSVG(width if width != None else self.displaySize[0],&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\charts.py", line 445, in getSVG&lt;BR /&gt;return _convertArcObjectToPythonObject(self._arc_object.getSVG(width, height))&lt;BR /&gt;RuntimeError: Invalid dataset: CIMPATH=internal_map/pts.json&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are work arounds but seems like you should be able to MakeFeatureLayer() and assign it as a chart data source without any extra steps.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 19:47:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-charts-fails-using-makefeaturelayer-in/m-p/1266142#M67048</guid>
      <dc:creator>FredSpataro</dc:creator>
      <dc:date>2023-03-09T19:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.charts fails using MakeFeatureLayer in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-charts-fails-using-makefeaturelayer-in/m-p/1266221#M67049</link>
      <description>&lt;P&gt;Outside of Pro, the script knows nothing about the Project&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Valid data sources include paths to datasets, including local datasets, UNC paths, and service URLs, and arcpy.mp Layer objects.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;From the help topic on line charts, you might want to try saving your layer as a *.lyrx and use the full path to it as the datasource&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 21:39:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-charts-fails-using-makefeaturelayer-in/m-p/1266221#M67049</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-03-09T21:39:06Z</dc:date>
    </item>
  </channel>
</rss>

