Python variables not working in pro sdk

460
1
Jump to solution
01-03-2019 03:12 PM
NicholasFerri
New Contributor

I am using the  CallScriptFromNet pro sdk community sample to run a python script in Pro via an addin. If i add the script through pro in a toolbox it runs fine but if i build an addin that runs it from the CallScriptFromNet example it errors on the "CURRENT" value of arcpy.mp.ArcGISProject. Is there something in the way it's being run from an addin that makes the python script run differently? Has anyone found a solution for this?

CallScriptFromNet example: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Geoprocessing/CallScriptFromNet

My Updated .py Script:

import sys

import arcpy

from arcpy import env

import arcpy.mp

import os

aprx = arcpy.mp.ArcGISProject("CURRENT")

aprxFolder = aprx.homeFolder

mname = aprx.activeMap.name

m = aprx.listMaps(mname)[0]

Error:

arcgisscripting._mapping.ArcGISProject(*gp_fixargs((aprx_path,), True))

OSError: CURRENT

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

If you are not running this script inside the Python window in ArcGIS Pro, "CURRENT" will have no meaning. You will have to specify the path to the ArcGIS Pro project for it to work outside the Python window in ArcGIS Pro.

import sys
import arcpy
from arcpy import env
import arcpy.mp
import os
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxFolder = aprx.homeFolder
mname = aprx.activeMap.name
m = aprx.listMaps(mname)[0]

m
<arcpy._mp.Map object at 0x000001DCB2994080>

mname
'Map'

aprxFolder
'C:\\Users\\xande\\OneDrive\\Documenten\\ArcGIS\\Projects\\PercentileRaster'

View solution in original post

1 Reply
XanderBakker
Esri Esteemed Contributor

If you are not running this script inside the Python window in ArcGIS Pro, "CURRENT" will have no meaning. You will have to specify the path to the ArcGIS Pro project for it to work outside the Python window in ArcGIS Pro.

import sys
import arcpy
from arcpy import env
import arcpy.mp
import os
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxFolder = aprx.homeFolder
mname = aprx.activeMap.name
m = aprx.listMaps(mname)[0]

m
<arcpy._mp.Map object at 0x000001DCB2994080>

mname
'Map'

aprxFolder
'C:\\Users\\xande\\OneDrive\\Documenten\\ArcGIS\\Projects\\PercentileRaster'