Hi,
I am working in ArcGIS Pro 2.4. I am trying to create map layouts automatically through a Python Tool, which is located in a toolbox. I have been able to create this in Jupyter but the people that will be running the tool do not have access to the software. I have the following code at the moment:
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Map")[0]
lyt = aprx.listLayouts("Child Care Need Index")[0]
lyrfile = arcpy.mp.LayerFile(path + "/LayerFiles/Neighbourhoods.lyrx")
m.addDataFromPath(lyrfile)
It runs perfectly if I copy and paste it into the python window, but as soon as I try to run it through the toolbox I get the following error message:
Traceback (most recent call last):
File "C:\users\*****\appdata\local\temp\arcgisprotemp11624\mapping.py", line 32, in <module>
m.addDataFromPath(lyrfile)
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1531, in addDataFromPath
return convertArcObjectToPythonObject(self._arc_object.addDataFromPath(*gp_fixargs((data_path,), True)))
RuntimeError
Failed to execute (Script1).
Any ideas on what I am doing wrong?
Thanks!
Andrew