Select to view content in your preferred language

Arcpy passed map parameter not working

1111
3
Jump to solution
03-12-2021 10:17 AM
B_Brooks
Regular Contributor

Hello, I'm having some struggles with my script. In my model, I set the first parameter to be the map to convert.

import arcpy
map1 = arcpy.GetParameter(0)
arcpy.AddMessage(map1.name)
 
And I get the error: AttributeError: ValueObject: Get attribute name does not exist
 
The documentation for the map class says that "name" is a property, so why isn't it working?
 
~Brandon
0 Kudos
1 Solution

Accepted Solutions
B_Brooks
Regular Contributor

Here is the solution:

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")

mapName = arcpy.GetParameterAsText(0)

map1 = aprx.listMaps(mapName)[0]

arcpy.AddMessage(map1.name)

View solution in original post

3 Replies
B_Brooks
Regular Contributor

To be clear, the parameter data type in the tool properties is "Map"

When I just say "arcpy.AddMessage(map1)" there are no errors and the message is the name of the map.

When I try "arcpy.AddMessage(type(map1)) is says "<class 'geoprocessing value object'>"

 

0 Kudos
B_Brooks
Regular Contributor

So I have figured out that the map class in the arcpy mapping module is not the same as the map data type, but that's as far as I've been able to get with the documentation. Confirmation that my approach is wrong, but so far no idea on next steps.

B_Brooks
Regular Contributor

Here is the solution:

import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")

mapName = arcpy.GetParameterAsText(0)

map1 = aprx.listMaps(mapName)[0]

arcpy.AddMessage(map1.name)