revit-scripting
FreeNo executable scriptsNot checkedCore Revit API scripting rules for the pyRevit agent runtime. Read before every query, dry run, or model change.
by pyrevitlabs★ 2,094 GitHub starsAbout this skill
Revit scripting through pyRevit
Read the pyrevit-library skill first and use lookup_pyrevit_api to find a maintained pyrevitlib or rpw function before writing raw Revit API code. Get context first, inspect the Revit API when uncertain, then run a focused script.
Workflow
- Call
get_contextbefore writing a script. It reports the active document, view, selection, Revit version, policy, and Python engine. - Use
inspect_elementsandlookup_revit_apito verify types, members, and element ids. - Use
run_queryto inspect data. Userun_modifywithdry_run=truebefore an actual change. - Use
get_runwhen the immediate response is truncated or reports a persistence warning.
Runtime contract
- Import APIs with
from pyrevit.api import DB, UI. - Only the raw Revit API is available. pyRevit's convenience methods on API types are not applied: use
list(collector)not.ToList(),get_Parameter(...)andParameter.Set(...)notSetParameterValue, and a collector rather thandoc.Walls.__revit__is a plainUIApplication. - Scripts receive
uiapp,app,uidoc, anddoc. A modifying run requires an activedoc. run_queryand dry runs roll model changes back. A modify run commits only after its configured policy permits it.- The rollback covers the active project and documents that were already open. A document the script creates, such as
app.NewFamilyDocument(...), or a family fromEditFamilyis outside it: changes there are not rolled back, do not fail arun_query, and are discarded if the document is closed without saving.changes.other_documentsreports them with ascopeinstead ofrolled_back. The host attempts to close new background documents without saving when the run ends. Checkclosed_documents,unclosed_documents, and warnings before assuming a document was closed. - Open a Revit transaction for every model edit, then commit or roll it back before the script ends.
- The active run blocks save, save-as and synchronize-with-central, and cancels
Document.ExportandDocument.ExportImagetargets outsideexport_dir, a temporary folder the host creates for the run. Export there in any mode; the response lists the files inexports. Other APIs that write files, such asViewSchedule.Export, are not checked, so point them atexport_dirtoo. Do not rely on the other operations. A script that hits one gets Revit's generic exception, for example "Saving failed", and the response adds anoperation_blockedwarning naming the cancelled operation. An operation Revit does not let the guard cancel is neither blocked nor reported. - The runtime uses the Windows user's permissions. Revit rollback does not undo Python or .NET file, network, or process side effects.
- Timeouts are cooperative. Avoid unbounded loops and blocking calls. When
get_contextshowsagent.reckless: truethere is no timeout at all, and a script that never ends hangs Revit.
Query example
from pyrevit.api import DB
walls = DB.FilteredElementCollector(doc)
walls = walls.OfCategory(DB.BuiltInCategory.OST_Walls)
walls = walls.WhereElementIsNotElementType()
result = {"wall_count": walls.GetElementCount()}
Modify example
from pyrevit.api import DB
transaction = DB.Transaction(doc, "Set wall comments")
transaction.Start()
for element_id in uidoc.Selection.GetElementIds():
wall = doc.GetElement(element_id)
if wall and wall.Category.Id == DB.ElementId(DB.BuiltInCategory.OST_Walls):
wall.get_Parameter(DB.BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set("Checked")
transaction.Commit()
Results and errors
- Set
resultto JSON-compatible data for structured query output. - Print concise diagnostics. Large results are truncated in the immediate response.
- Fix
revit_busy,document_read_only,no_active_document,query_modified_model,transaction_left_open, andother_document_modifiedbefore retrying. transaction_rollback_failedmeans Revit didn't finish rolling back a transaction the script left open. Readdecision: onrollback_incomplete, ask the user to undo in Revit or close without saving before running again.revit_busymeans the request was not run and will not run later: it is safe to send again once Revit is idle (a modal dialog such as the save reminder blocks every request until the user answers it). The error'soutcomesays what is known. When it isunknown(the connection broke after the request was sent), read the run withget_runusing the error'srequest_idbefore sending it again.run_hungmeans the script is stuck past itstimeout_sin a call the timeout can't interrupt (a long Revit API call,Thread.Sleep, a printer or window waiting for input). Revit stays busy until that call returns. Ask the user to check Revit, then read the run withget_runbefore sending anything that changes the model again.
Install revit-scripting in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the revit-scripting skill do?
Core Revit API scripting rules for the pyRevit agent runtime. Read before every query, dry run, or model change.
How do I install the revit-scripting skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the revit-scripting skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic