Trouble accessing .lyrx in ArcGIS Pro Package commondata folder from script

393
0
05-01-2020 01:14 PM
ZacharyNeumann1
New Contributor III

I am building a Task Workflow to automate deployment of Crowdsource Polling. I have a task for creating a feature layer from a spreadsheet that sets up a relationship class between the feature layer and related commenting table. Once this is finished I need to symbolize the layer based on a field in the comment layer. I have created a layer file to accomplish this need by symbolizing based on layer file. I have got this to work before packaging the project but need it to work from within a packaged project. When I use the Package Project tool I have saved a the layer file (.lyrx) using the "additonal files" input:

This adds the .lyrx into the commondata folder of the package. 

My issue is that when I get the path for the .lyrx and plug it into my code I am getting a ValueError. When I do this before packaging the project I do not get a ValueError. I have also tried running the code from the package after I use the extract package tool and get the same error.

Here is my code:

p = os.path.dirname(arcpy.mp.ArcGISProject("CURRENT").defaultGeodatabase)
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Map")[0]
default_gdb = arcpy.mp.ArcGISProject("CURRENT").defaultGeodatabase
rec_sites = os.path.join(default_gdb, "RecSitesXY")

# local layer file path before packaging project
#lf = arcpy.mp.LayerFile(os.path.join(p, "FeeToolRecSiteSymbols.lyrx"))
# pro package layer file


# layer filepath after packaging project
lf = os.path.join(os.path.dirname(p), 'commondata', 'pro-recfeetool-deployment-task-workflow', 'FeeToolRecSiteSymbols.lyrx')

# add coment layer and symbolize using layer file
m.addDataFromPath(rec_sites)

# Using insert layer instead of arcpy.ApplySymbologyFromLayer_management because 
# there is a known bug that this will not work from within a script
m.insertLayer(m.listLayers()[0],lf)

# clean up
m.removeLayer(m.listLayers()[1])
aprx.save()

I have also tried to search for the layer file this way and have tried using the output path with the same error 


The value error happens at this point in the code:

m.insertLayer(m.listLayers()[0],lf)

Any help would be much appreciated.

0 Kudos
0 Replies