Dynamic Labels

59
3
Jump to solution
yesterday
DanCrawford
Occasional Contributor

Hello, is there a method to grab a dynamic label from a layout for use in python?
This is the layout dynamic label:
<dyn type="project" property="name"/>

I'm building a little script to export my map to PDF and would like it to use the map name as the filename.

Thanks.

0 Kudos
1 Solution

Accepted Solutions
DanCrawford
Occasional Contributor

I found a way using the properties of the filepath rather than the dynamic label:

import arcpy
import os
# Get the current project
aprx = arcpy.mp.ArcGISProject("CURRENT")
# Access the full file path of the project
project_path = aprx.filePath
# Extract the project name from the file path
project_name = os.path.basename(project_path)
print("Project Name:", project_name)

 

View solution in original post

3 Replies
DanCrawford
Occasional Contributor

I found a way using the properties of the filepath rather than the dynamic label:

import arcpy
import os
# Get the current project
aprx = arcpy.mp.ArcGISProject("CURRENT")
# Access the full file path of the project
project_path = aprx.filePath
# Extract the project name from the file path
project_name = os.path.basename(project_path)
print("Project Name:", project_name)

 

BlakeTerhune
MVP Regular Contributor

There's a TextElement object you can access from the Layout object in the Arcpy.mp Python submodule. Is that what you're looking for?

0 Kudos
DanCrawford
Occasional Contributor

I'll have a look, thanks.  Also thanks for moving this post.  I couldn't find this forum thread originally.

0 Kudos