You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

ArcGIS Pro动态文本框自动更新版本号与日期的技术需求

Dynamic Text Auto-Update in ArcGIS Pro (V1_XX_YYYYMMDD Format)

Got it, let's work through how to get that dynamic text updating exactly as you need. We'll split this into two core tasks: incrementing the version number on demand, and auto-updating the date every 7 days. ArcGIS Pro's dynamic text supports Python expressions, which we'll use heavily here, plus a small script to handle the version increment trigger.

1. Auto-Update the Date Every 7 Days

For the date portion that refreshes every 7 days (based on your starting date 20170226), we can calculate the most recent valid 7-day interval using a Python expression directly in the dynamic text box. Here's how:

  • Open your dynamic text properties in ArcGIS Pro.
  • Switch to the Python Expression tab.
  • Use this code to compute the date (we'll pair it with the version logic next):
from datetime import datetime, timedelta

def get_7day_date():
    # Your original starting date
    start_date = datetime.strptime("20170226", "%Y%m%d")
    today = datetime.today()
    # Calculate how many full 7-day cycles have passed since the start
    weeks_passed = (today - start_date).days // 7
    # Compute the target date (aligned to 7-day intervals)
    target_date = start_date + timedelta(weeks=weeks_passed)
    return target_date.strftime("%Y%m%d")

2. Increment the Version Number (XX)

Since the version number needs to jump by 1 only when you trigger an update (not every time the project opens), we need a persistent way to store the current version value. Below are two straightforward options:

Option A: Use a Local Text File for Version Tracking

This is the simplest approach if you don't want to mess with project properties:

  1. Create a plain text file (e.g., version_counter.txt) in your project folder, and add the starting number 60 inside it.
  2. Make a Python script tool (or run it manually) to increment the version when needed:
# Script to increment version number
version_file = r"C:\YourProjectPath\version_counter.txt"

# Read current version
with open(version_file, "r") as f:
    current_version = int(f.read().strip())

# Increment by 1
new_version = current_version + 1

# Save the new version back to the file
with open(version_file, "w") as f:
    f.write(str(new_version))
  1. Update your dynamic text's Python expression to pull the version from the file and assemble the final string:
from datetime import datetime, timedelta

def get_current_version():
    version_file = r"C:\YourProjectPath\version_counter.txt"
    with open(version_file, "r") as f:
        return f.read().strip()

def get_7day_date():
    start_date = datetime.strptime("20170226", "%Y%m%d")
    today = datetime.today()
    weeks_passed = (today - start_date).days // 7
    target_date = start_date + timedelta(weeks=weeks_passed)
    return target_date.strftime("%Y%m%d")

# Assemble the final dynamic text string
f"Official Licensed Data: V1_{get_current_version()}_{get_7day_date()}"

Option B: Use ArcGIS Pro Project Custom Properties

If you prefer to keep everything within your project file:

  1. Open your ArcGIS Pro project, go to Project > Properties > Custom tab.
  2. Add a new property named DataVersion with the value 60.
  3. Use this expression in your dynamic text to read the property:
from datetime import datetime, timedelta
import arcpy

def get_current_version():
    aprx = arcpy.mp.ArcGISProject("CURRENT")
    return aprx.customProperties["DataVersion"]

def get_7day_date():
    start_date = datetime.strptime("20170226", "%Y%m%d")
    today = datetime.today()
    weeks_passed = (today - start_date).days // 7
    target_date = start_date + timedelta(weeks=weeks_passed)
    return target_date.strftime("%Y%m%d")

f"Official Licensed Data: V1_{get_current_version()}_{get_7day_date()}"
  1. Use this script to increment the version when you're ready to update:
import arcpy

aprx = arcpy.mp.ArcGISProject("CURRENT")
current_version = int(aprx.customProperties["DataVersion"])
aprx.customProperties["DataVersion"] = str(current_version + 1)
aprx.save()

Quick Setup Tips

  • To make version increments even easier, add the increment script as a custom button in ArcGIS Pro's ribbon—just click it when you need to bump the version number.
  • The date will automatically refresh every time the dynamic text updates (e.g., when you open the project, refresh the layout, or export a map) since the Python expression runs on refresh.

内容的提问来源于stack exchange,提问作者Theo F

火山引擎 最新活动