Select to view content in your preferred language

arcpy.mp.ArcGISProject("current") - not working in python toolbox?

325
6
Jump to solution
08-13-2024 04:49 AM
nadja
by
Frequent Contributor

Hi 

I used this code with ArcGIS Pro 2.x without any problems from my .pyt-toolbox. Now (3.3.1) I always get "OSError: CURRENT". It still works when I call it from a python notebook, which I have opened in my ArcGIS Pro project. But I need to get it to work again in this setup:

I'm creating a Dockpane using the ArcGIS Pro SDK. On that dockpane is a button, when clicked, this happens:

 

 

string installPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string toolboxPath = System.IO.Path.Combine(installPath, "Data.pyt\\Repair");
await Geoprocessing.ExecuteToolAsync(toolboxPath, null, null, null, null, GPExecuteToolFlags.None); 

 

 

this executes my tool and this works.

The Repair method is now reduced to : 

 

 

p = arcpy.mp.ArcGISProject('CURRENT')
m = p.listMaps()[0]
l = m.listLayers()[0]
pprint.pprint(l.connectionProperties)

 

 

this does work in my notebook but from my pyt-toolbox I get "OSError: CURRENT".

I already tried to run the Tool from within an ArcGIS Pro project, but it doesn't work either, when there is an active map. however, if there is no active map, I get "index out of range". 

any ideas would be appreciated 🙂

0 Kudos
1 Solution

Accepted Solutions
MErikReedAugusta
Frequent Contributor

I'm not as familiar with Python Toolboxes, as I am with regular Toolboxes, but by my understanding Right-Click>>Edit and then click Run would NOT be running it in the project.

That's going to run it in whichever IDE you have set up.

 

Try double-clicking it in the catalog, rather than Right-click>>Edit.  Does that work as expected?

View solution in original post

6 Replies
DanPatterson
MVP Esteemed Contributor

If the project is closed, then try using the full path to the aprx


... sort of retired...
0 Kudos
nadja
by
Frequent Contributor

the project is open, running properly. there is also an active map and active layers.

0 Kudos
DanPatterson
MVP Esteemed Contributor

notebooks know the existence of 'current' are you running the toolbox from within Pro as well?


... sort of retired...
0 Kudos
nadja
by
Frequent Contributor

yes. i browsed through the catalog to the toolbox, right-click >> Edit. in the editor I clicked Run. that should be from within?

0 Kudos
MErikReedAugusta
Frequent Contributor

I'm not as familiar with Python Toolboxes, as I am with regular Toolboxes, but by my understanding Right-Click>>Edit and then click Run would NOT be running it in the project.

That's going to run it in whichever IDE you have set up.

 

Try double-clicking it in the catalog, rather than Right-click>>Edit.  Does that work as expected?

nadja
by
Frequent Contributor

thanks, yes now it's working. thanks 🙂