Hello,
I am trying to create a very simple Python script tool for my team to use when opening a new ArcGIS Pro project that will automatically add a pre-determined group of datasets to the map. Below is a code snippet of what I want to do. Some of the data will be shapefiles and some are feature layers within file geodatabases. (the file path in the actual code is the full directory file path, without the ellipses)
import arcpy
aprx = arcpy.mp.ArcGISProject("CURRENT")
aprxMap = aprx.listMaps()[0]
states_shp = r"...\States_NAD1983\states.shp"
aprxMap.addDataFromPath(states_shp)
aprx.save()
I get this error:
Apologies for my ignorance here, I'm hoping someone can help me out! Thank you! 🙂
-KC
I put your code in a blank ArcPro with my own shapefile and it worked fine.
Edited: add some print statements? Here is a link to someone with the same issue
Hmmm, ok. When I reference a shapefile that's stored locally on my desktop, the code worked fine. The dataset I'm referencing is on our company's data server. I'm connected to that network when I'm running the script so I didn't think it would cause issues....is there something else I need to include in the code to make it work?
@Katie_Clark why not
Project templates—ArcGIS Pro | Documentation
Ready to go
Create a project template—ArcGIS Pro | Documentation
Dan,
I looked into project templates, but was running into various issues regarding loading times, or file paths still breaking, etc. I will continue to look into that as an option though
My shapefile was located on a shared network drive, so I'd verify the file path you are using or try the project template idea.
Thanks @Kara_Shindle . I'm wondering, did you use a UNC path or a normal file path in the script?
Are you using unc paths? and how are you denoting them? I don't use them but I know r"\\ will just be interpreted as an escaped single backslash and not a double backslash, hence the "\\\\ .... one for each \ needed
r'\\\\Somepath
r'\\Somepath
Good point @DanPatterson , I had forgotten about that when using a raw string! However, unfortunately it didn't seem to make a difference in my script, so it must still be some other underlying issue.
And just for reference/follow up on this overall thread - I was still having issues packaging the project as a template (either a document or adding to our portal) so I ended up using the "Consolidate Project (Data Management)" tool to create a solution in the meantime. That fixed the issue of broken links happening when the project was copied and pasted elsewhere by creating copies of the data within the project folder itself. While I realize this wouldn't be an ideal solution for datasets that are accessed by multiple people and updated often, this works for us because the datasets are static.
I was using an UNC path.