-
-
Save eirannejad/4e275166bf2015f4f844bb1d087ca4d6 to your computer and use it in GitHub Desktop.
# 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 get this error too ...im gonna find a way to fix that ...maybe we miss something in our imports ...
found the solution ... @IsaacTcl
u should first import clr
and then write clr.AddReference('RevitAPI')
to add RevitAPI.dll to ur environment then u can import from Autodesk.Revit.*
if len(selection) > 0:
el = selection[0]
should be
if len(selection) > 0:
el = selection
am I correct?
just change
from Autodesk.Revit import DB
from Autodesk.Revit import UI
to:
from Autodesk.Revit.DB import
from Autodesk.Revit.UI import
I am getting this error when following tutorial and clicking button.
IronPython.Runtime.UnboundNameException: name 'window' is not defined
i've had to copy the init script into the button.py file in order to get this far. it seems that the button doesnt look in the init.py script at all when running.
Has anyone else had this issue?
Hi! I am also following your amazing video: https://www.youtube.com/watch?v=PfCn7OrY_-A&list=PLc_1PNcpnV5742XyF8z7xyL9OF8XJNYnv&index=3
But I got stuck at the first line: 'cl = FilteredElementCollector()'
As I keep getting the message 'Exception : IronPython.Runtime.UnboundNameException: name 'FilteredElementCollector' is not defined'
It works though, if I switch the startup script to init.py and simply add 'doc = revit.ActiveUIDocument.Document' as the first line of the code. It seems like there is something wrong with the code posted here. I would be glad if you could help
Hi! I am also following your amazing video: https://www.youtube.com/watch?v=PfCn7OrY_-A&list=PLc_1PNcpnV5742XyF8z7xyL9OF8XJNYnv&index=3
But I got stuck at the first line: 'cl = FilteredElementCollector()'
As I keep getting the message 'Exception : IronPython.Runtime.UnboundNameException: name 'FilteredElementCollector' is not defined'It works though, if I switch the startup script to init.py and simply add 'doc = revit.ActiveUIDocument.Document' as the first line of the code. It seems like there is something wrong with the code posted here. I would be glad if you could help
I had the same issue and it worked for me when I selected the elements in Revit and then opened the RevitPythonShell.
@DanailMomchilov
I also solved the 'Exception : IronPython.Runtime.UnboundNameException: name 'FilteredElementCollector' is not defined' error by changing the import lines to:
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
add the following lines starting from line11
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *
Don't do this
from Autodesk.Revit.DB import *
It's bad practice. Always use the namespace to point to the type you want e.g. DB.FilteredElementCollector
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
Hi Ehran,
I have tried running the code as per your youtube video https://www.youtube.com/watch?v=PfCn7OrY_-A but somehow or rather, I keep getting this error code 👍
Exception : IronPython.Runtime.Exceptions.ImportException: No module named Autdodesk.Revit.DB
Hope you can shed some light.
Looking forward to your reply.
Cheers