I am encountering an issue when using a charts module script in conjunction with a model builder tool. The script tool functions perfectly when used outside model builder and can find the input layer in the contents and add the created chart to it, however, once this same script tool is put into model builder it throws an index error and cannot find the layer being created within the model. The odd thing is, if the script is run after the fact on the same output layer from the model, it works perfectly, and if it is run in a separate model with just the output feature layer (as a variable) then the chart tool also runs perfectly. Only when both the layer creation and chart creation are being done in the same model does it throw the index error.
I have tried:
- checking add to display in model builder for the layer and setting it as a parameter.
- various iterators, logic stops, export features, and save to layerfile, none of which worked.
- unchecked the project properties setting for model builder that automatically outputs into a group.
Chart Tool Code Example: (Can provide params if needed)
import arcpy
Input_Layer = arcpy.GetParameter(0)
ChartInfo_Title = arcpy.GetParameterAsText(2)
ChartInfo_xField = arcpy.GetParameterAsText(3)
ChartInfo_binCount = arcpy.GetParameter(4)
ChartInfo_xTitle = arcpy.GetParameterAsText(5)
ChartInfo_yTitle = arcpy.GetParameterAsText(6)
ChartInfo_TransformType = arcpy.GetParameterAsText(7)
aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps("Map")[0]
lyr = map.listLayers(Input_Layer)[0]
arcpy.env.addOutputsToMap = True
arcpy.AddMessage(lyr)
c = arcpy.charts.Histogram(ChartInfo_xField, title=ChartInfo_Title, binCount=ChartInfo_binCount, xTitle=ChartInfo_xTitle, yTitle=ChartInfo_yTitle, dataTransformationType=ChartInfo_TransformType, dataSource=lyr)
c.addToLayer(lyr)
Failing Model example (simplified):

Any advice or tips are appreciated. Thank you in advance!