How to refresh a database/map with python in ArcGIS Pro

1748
4
01-15-2019 11:11 AM
MatthewDriscoll
MVP Regular Contributor

Is there a way to refresh a database in a python script in Pro?  I have a script where I create a new feature class in the default database and want to add that data to the map at the end of the script.   It seems it does not recognize this new feature class until after the script is complete.  I am wanting to use addDataFromPath. 

0 Kudos
4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

That is the case. you used to call an arcpy function to refreshActiveView when you were running scripts with the "CURRENT" project (ie a project that was open when the script was running) So you could do this mid stream.  When the script completes now, the active view is updated (and that has been my experience too)

RefreshActiveView—Help | ArcGIS Desktop ArcMap

Migrating from arcpy.mapping to ArcGIS Pro—ArcPy | ArcGIS Desktop 

Alphabetical list of ArcPy functions—ArcPy Functions | ArcGIS Desktop  in ArcGISPro

show the list of currently available functions alphabetically

MatthewDriscoll
MVP Regular Contributor

So are you saying that this is not possible in Pro with python?  I tried to test it keeping it simple of using the CURRENT, creating a feature class in the default database and then try adding it.  It always fails with the message being that the new feature class does not exists.   If I do the exact same lines one by one in Pro python window it will work fine.   But doing this in a script or a python toolbox script tool it fails.   So this is just not possible in Pro?  This is a straight forward work flow, and it is not an option?

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

The Pro python window is a different beast.

Anyway I am on Pro beta 2, and ArcGIS Pro 2.3 is coming  on Jan 18... 

I think add results to "display"/"map"/"Whatever" was just added back in

So I can't confirm your problem, since it doesn't exist for me now.

There is a recent video showing "What's new in Pro 2.3" that shows some of the other cool stuff.

So you can wait and test then... or keep trying to find a workaround that doesn't entail creating a featureclass, then a featurelayer on disc

MatthewDriscoll
MVP Regular Contributor

Thanks Dan.   I think I will try to create a add-in to run the script tool, then add the layer using the add-in (if possible) after the scripts runs as a workaround.

Edit:   Using an add-in ended up being a satisfactory work around for me.

0 Kudos