Last active
January 12, 2024 19:21
-
-
Save eirannejad/4e275166bf2015f4f844bb1d087ca4d6 to your computer and use it in GitHub Desktop.
RevitPythonShell init
This file contains 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() |
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
#######OK NOW YOU CAN CODE########
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i faced an issue, can you help me in this.