Revit failed to execute macro without Dynamo opened in a background

Hello everybody,
this is my problem: “Revit failed to execute TESTSMACRO” - it appears when I try to launch python macro by Macro Manager, but only if Dynamo isn’t opened in a background window. When Dynamo is opened at the same time as I use Macro Manger it’s all OK. How could I make this work without launching Dynamo in a background?

This is the macro from SharpDevelop:

import clr
import System
clr.AddReferenceByName(“RevitAPI.dll”);
clr.AddReferenceByName(“RevitAPIUI.dll”);

from Autodesk.Revit import *
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Macros import *
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import *
from System.Collections.Generic import *
from System.Collections import *
from System import *
from math import *

def TESTMACRO(self)
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
…doc = DocumentManager.Instance.CurrentDBDocument
…collector
= FilteredElementCollector (doc) collector.OfCategory (BuiltInCategory.OST_DuctCurves).WhereElementIsNotElementType ().ToElements()
# starting transaction:
…t = Transaction(doc, “DuctNaming”)
…t.Start()

[doing some stuff with ducts here]

…t.Commit()

And this is some text from a failure window:
"Revit failed to execute TESTMACRO
A problem has been detected.
Autodesk.Revit.Exceptionms.ArgumentNullException: The input argument “document” of function ‘anonumous-namespace’::FilteredElementCollector_constructor or one item in the collection is null at line 326 of file
d:: …bla-bla-bla…"

Help please, can’t really understand what the hell is that. Thank you!

you’re importing dynamo’s libraries and trying to use them without dynamo open. You’ll have to load them yourself using reflection… You can probably just add the real path to the dlls you want to load instead of using their names.

Michael,
thanks a lot for the help. You took my attention to the fact that RevitServices.dll is a Dynamo’s library, and there is no point to use dynamo’s libraries in RevitPythonShell. After a couple of days of exploring the problem, I’ve finally found the solution. Actually, you shouldn’t load any .dlls to make a transaction from RPS, because what we call DocumentManager and TransactionManager in Dynamo are native RevitAPIUI’s functions (or methods? don’t know exactly). Any way, the code now looks like:

import clr
import System
clr.AddReferenceByName (“RevitAPI.dll”)
clr.AddReferenceByName (“RevitAPIUI.dll”)
from Autodesk.Revit import *
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Macros import *
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import *
from System.Collections.Generic import *
from System.Collections import *
from System import *
from math import *

def TESTMACRO(self)
app = self.Application
doc = self.ActiveUIDocument.Document
t = Transaction(doc, “DuctNaming”)
t.Start()

t.Commit()

DocumentManager and TransactionManager are Dynamo wrappers on the revit api types.