Last active
November 5, 2025 11:46
-
-
Save eirannejad/4e275166bf2015f4f844bb1d087ca4d6 to your computer and use it in GitHub Desktop.
RevitPythonShell init
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # these commands get executed in the current scope | |
| # of each new shell (but not for canned commands) | |
| #pylint: disable=all | |
| import clr | |
| clr.AddReferenceByPartialName('PresentationCore') | |
| clr.AddReferenceByPartialName('AdWindows') | |
| clr.AddReferenceByPartialName("PresentationFramework") | |
| clr.AddReferenceByPartialName('System') | |
| clr.AddReferenceByPartialName('System.Windows.Forms') | |
| from Autodesk.Revit import DB | |
| from Autodesk.Revit import UI | |
| import Autodesk.Windows as aw | |
| # creates variables for selected elements in global scope | |
| # e1, e2, ... | |
| max_elements = 5 | |
| gdict = globals() | |
| uiapp = __revit__ | |
| uidoc = uiapp.ActiveUIDocument | |
| if uidoc: | |
| doc = uiapp.ActiveUIDocument.Document | |
| selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()] | |
| for idx, el in enumerate(selection): | |
| if idx < max_elements: | |
| gdict['e{}'.format(idx+1)] = el | |
| else: | |
| break | |
| # alert function | |
| def alert(msg): | |
| TaskDialog.Show('RPS', msg) | |
| # quit function | |
| def quit(): | |
| __window__.Close() |
i ask the chatgpt, and the i pastet the code"# -- coding: utf-8 --
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
doc = revit.ActiveUIDocument.Document
uidoc = revit.ActiveUIDocument" on the top, and i solve the problem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Paste this on top of your script
Your code is using a variable called 'doc' but it was not defined before.
Go through this site https://dynamopythonprimer.gitbook.io/dynamo-python-primer/getting-started/boilerplate-setup-code
it will go over some basics on getting started