Generate Python Code
Draft ArcPy snippets tailored to your active map by describing the task you want automated. Optionally include layer samples so the AI can see schemas and representative data.
Usage
- Add the toolbox to ArcGIS Pro.
- Open Generate Python Code.
- Pick a provider/model, set context layers, and describe the script you need.
- Run the tool and copy the generated code from the messages pane.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| Source | String (Choice) | Yes | AI provider (OpenRouter, OpenAI, Azure OpenAI, Claude, DeepSeek, Local LLM). |
| Model | String | No | Specific model to use. |
| Endpoint | String | No | Custom endpoint for Azure or local deployments. |
| Deployment Name | String | No | Azure OpenAI deployment ID. |
| Layers for Context | Feature Layer (MultiValue) | No | Optional layers to share schema and the first five records with the AI. |
| Prompt | String | Yes | Describe the script you need. Specific inputs and outputs improve quality. |
| Context | String | No | Automatically generated map summary, similar to the Get Map Info output. |
Tips
- State the desired tool flow or geoprocessing chain explicitly.
- Provide sample layer names/fields so the code references real objects.
- Try a few models—some are better at structured scripting than others.
Data privacy
Important: Any layers you include for context (schema plus sample rows) get sent to the provider you choose. Make sure this is allowed for your dataset, or stick to local models.