ArcPy Script
Generate ArcPy code tailored to the user’s active ArcGIS Pro project by using real map/layer context and ArcGIS‑specific constraints. Output should be code-only unless the user explicitly asks for explanations.
Intent
Produce scripts that work on the first run by grounding the prompt in:
- Actual map metadata and spatial reference
- Real layer names, fields, and small sample records
- Visible layer context and optional view extent
Inputs
task_description (string)
project_path (string, optional)
map_name (string, optional)
layer_names (array, optional)
selected_only (bool, optional)
max_features_per_layer (int, optional, default 50)
simplify_ratio (float, optional, default 0.01)
include_view_extent (bool, optional)
include_map_screenshot (bool, optional)
provider (string, optional: OpenAI, OpenRouter, Azure OpenAI, Claude, DeepSeek, Local LLM)
model (string, optional)
Context Capture (mirror arcgispro_ai)
Use arcgispro-cli for real project context
If available, call arcgispro-cli to fetch live project details:
arcgispro layers --json for exact layer names and types
arcgispro fields "LayerName" for real field schemas
arcgispro context for full project dump
Prefer actual layer/field names from these outputs over guesses.
When available, build a map_info JSON payload that includes:
- Map metadata: name, title, description, spatial reference, units, rotation, time-enabled
- Layer summaries: visibility, layer type, data source type, extent, spatial reference
- Feature layers: field samples + simplified geometry samples (GeoJSON‑like)
- View extent polygon (optional)
- Active view screenshot (optional, base64 PNG)
Prompt Rules (critical)
- Use
arcpy only
- Prefer
SelectLayerByAttribute for attribute filters
- If distance/near queries are requested, also use
SelectLayerByLocation
- No
ORDER BY in selection SQL
- Use
active_map.listLayers("LayerName")[0] when zooming
- Use
arcpy.AddMessage for user-facing output
- Return only a Python code block (no preamble, no trailing commentary)
Capabilities to Match
- Map/layer metadata extraction
- Visible-layer context sampling with simplified geometries
- Optional view screenshot for vision‑capable models
- Provider/model selection and key resolution
- Field‑level enrichment via AI responses (optional follow‑up tool)
Output
- A single, runnable ArcPy script
- Safe defaults and minimal assumptions
- Handles missing layers or empty selections gracefully
Examples
User: “Select the 3 counties with lowest population density and zoom to them.”
Agent output: Python only, using SelectLayerByAttribute, SearchCursor, and active_view.camera.setExtent(...).
Outputs
Return a concise, usable result with the key artifacts or recommendations.
Safety
Do not invent data, credentials, or system context. Flag uncertainty and risky operations clearly.
1---2name: arcpy-script3description: Generate ArcPy scripts for ArcGIS Pro using live map context, layer sampling, and ArcGIS‑aware prompt rules4---56# ArcPy Script78Generate ArcPy code tailored to the user’s active ArcGIS Pro project by using real map/layer context and ArcGIS‑specific constraints. Output should be **code-only** unless the user explicitly asks for explanations.910## Intent1112Produce scripts that work on the first run by grounding the prompt in:13- Actual map metadata and spatial reference14- Real layer names, fields, and small sample records15- Visible layer context and optional view extent1617## Inputs1819- `task_description` (string)20- `project_path` (string, optional)21- `map_name` (string, optional)22- `layer_names` (array, optional)23- `selected_only` (bool, optional)24- `max_features_per_layer` (int, optional, default 50)25- `simplify_ratio` (float, optional, default 0.01)26- `include_view_extent` (bool, optional)27- `include_map_screenshot` (bool, optional)28- `provider` (string, optional: OpenAI, OpenRouter, Azure OpenAI, Claude, DeepSeek, Local LLM)29- `model` (string, optional)3031## Context Capture (mirror arcgispro_ai)3233### Use arcgispro-cli for real project context3435If available, call `arcgispro-cli` to fetch live project details:36- `arcgispro layers --json` for exact layer names and types37- `arcgispro fields "LayerName"` for real field schemas38- `arcgispro context` for full project dump3940Prefer actual layer/field names from these outputs over guesses.4142When available, build a `map_info` JSON payload that includes:43- Map metadata: name, title, description, spatial reference, units, rotation, time-enabled44- Layer summaries: visibility, layer type, data source type, extent, spatial reference45- Feature layers: field samples + simplified geometry samples (GeoJSON‑like)46- View extent polygon (optional)47- Active view screenshot (optional, base64 PNG)4849## Prompt Rules (critical)5051- Use `arcpy` only52- Prefer `SelectLayerByAttribute` for attribute filters53- If distance/near queries are requested, also use `SelectLayerByLocation`54- No `ORDER BY` in selection SQL55- Use `active_map.listLayers("LayerName")[0]` when zooming56- Use `arcpy.AddMessage` for user-facing output57- Return **only** a Python code block (no preamble, no trailing commentary)5859## Capabilities to Match6061- Map/layer metadata extraction62- Visible-layer context sampling with simplified geometries63- Optional view screenshot for vision‑capable models64- Provider/model selection and key resolution65- Field‑level enrichment via AI responses (optional follow‑up tool)6667## Output6869- A single, runnable ArcPy script70- Safe defaults and minimal assumptions71- Handles missing layers or empty selections gracefully7273## Examples7475**User:** “Select the 3 counties with lowest population density and zoom to them.”7677**Agent output:** Python only, using `SelectLayerByAttribute`, `SearchCursor`, and `active_view.camera.setExtent(...)`.7879## Outputs8081Return a concise, usable result with the key artifacts or recommendations.8283## Safety8485Do not invent data, credentials, or system context. Flag uncertainty and risky operations clearly.86