English

How To: Identify a Vector Tile Layer in an ArcGIS Pro project file using Python

Summary

When working on a project in ArcGIS Pro, map frames and layouts can only be viewed by adding the project to ArcGIS Pro and and checking each layer one at a time. This can be time-consuming, Thus, automating the process using Python is an option.

Procedure

The following script iterates over an ArcGIS project file (.aprx) and searches for vector tile layers.

  1. Import the necessary modules.
import arcpy
  1. Specify the map project folder.
aprx = arcpy.mp.ArcGISProject(r"C:\Users\Documents\ArcGIS\MyProject\MyProject.aprx")
m = aprx.listMaps("MAP")[0]
  1. Create a loop to utilize the arcpy.da.Describe() method to iterate the list of layers available in the map document. Print "YES" for vector layers and "NO" for others, as shown in the example below:
for lyr in m.listLayers():
 desc = arcpy.da.Describe(lyr)
 if desc.get('dataType') == 'VectorLayer':
  print ("YES")
 if desc.get('dataType') != 'VectorLayer':
  print ("NO")

The following shows the full script:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Users\Documents\ArcGIS\MyProject\MyProject.aprx")
m = aprx.listMaps("Map")[0]
for lyr in m.listLayers():
    print (lyr)
    desc = arcpy.da.Describe(lyr)
    print (desc)
    if desc.get('dataType') == 'VectorLayer':
        print ("yes")
    if desc.get('dataType') != 'VectorLayer':
        print ("no")
    print ()

Related Information