1

Here's the documentation for the relevant API material

enter image description here

What I'm trying to do is be able to call postable commands from Dynamo (in this case, I cannot even debug because the import clause fails for Autodesk.Revit.UI). I got the number 10:05:57.614 from the journal file, but it does not mean much to me if I can't import the correct namespace. If I do not import, then the Evaluator tells me that the function calls I want to make are undefined. Please help.

Does this have something to do with the State of the Revit session as it executes a Dynamo script?

And the associated error message:

Error msg

for copy+paste..

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *


import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import System
dataEnteringNode = IN



elemType = UnwrapElement(IN[0])

cmdID = System.Enum.Parse(RevitCommandId, "10:05:57.614")


TransactionManager.Instance.EnsureInTransaction(doc)

uiapp.PostCommand("10:05:57.614")

OUT = uSelect
doc.Regenerate()
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
Gabe Nones
  • 193
  • 2
  • 11

1 Answers1

1

This should resolve the issue of being unable to import RevitAPIUI.dll:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

clr.ClearProfilerData()
uiPath = r'C:\Program Files\Autodesk\Revit 2016\RevitAPIUI.dll'
clr.AddReferenceToFileAndPath(uiPath)

from Autodesk.Revit.UI import *

def pickSomething():
    from Autodesk.Revit.UI.Selection import ObjectType
    picked = uiapp.ActiveUIDocument.Selection.PickObject(ObjectType.Element)
    return picked

#Assign your output to the OUT variable.
OUT = pickSomething()
konrad
  • 3,544
  • 4
  • 36
  • 75