Sequencing python nodes

Good morning,

I’m trying to make a python node run after the previous one has completed. What is the best way to accomplish this?

image

Thank you in advance!

You could connect the select model elements node to the first python node and connect the output from that node to your second python node.

Theoretically you could also just connect your first node to the second, but I think I’ve had some issues with correct sequencing in the past using that method.

2 Likes

I suppose that in your case the 2nd Python node inputs are not the outputs of the 1st, right?

Usually I use Orchid node Data.Await, for example when you have an element, you want to do something with it and then delete it. In a normal case it might be deleted before the other task is completed, causing the graph to fail.
With this node the 2nd node starts to work only when the 1st is over.

1 Like

Good idea! I think this would work in most cases.

Unfortunately, in my specific case at the moment this solution is not working. It must be the methods I am using (post command & selection.setelementids)

Do you have any experience to subscribing to Revit API events in Iron Python? I’m trying to subscribe to the Idling Event under UIApplication Class. Here is some documentation:

Iron Python - Accessing .NET events
Revit API - Idling Event

And here is my code. I’m pretty sure I’m close to the solution but can’t seem to get it figured out.

import sys
pyt_path = r'C:\Python27\Lib'
sys.path.append(pyt_path)
import clr

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *

clr.AddReference ('RevitAPIUI')
from Autodesk.Revit.UI import *

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


#Postable Command
command = PostableCommand.MergeSurfaces
merge = RevitCommandId.LookupPostableCommandId(command)

def Merge():
uiapp.PostCommand(merge)

def Idle(sender, IdlingEventsArgs):
print 'Idling'

#Post
TransactionManager.Instance.EnsureInTransaction(doc)
Merge()
TransactionManager.Instance.TransactionTaskDone()

#Subscribe Idling Event

uiapp += Idle

OUT = None

Thanks for any help in advance!

Do you think you could take a quick look at what I’m trying to accomplish above?

It seems that subscribing to an event should be a basic task, but I’m really struggling with subscribing to a .Net event in Python. I would greatly appreciate if you could give me your input since you are a much more experienced user! :slight_smile:

As a side question:
When you say you work in .Net for everything does this mean you are running your script through macros? And if so, is this a more valuable, efficient way to run scripts for Revit?

@ericabbott The answer to your question is that you cannot subscribe to the Revit events from Dynamo. Dynamo itself uses the Idling Event to submit its calls to Revit DB.

If you wish to switch tools then one possibility is a tool called pyRevit. Here’s an example of how you can subscribe to events from pyRevit: https://github.com/eirannejad/pyRevit/issues/201

You can also subscribe to them using ExternalApplication if you write Revit Addins. That would require switching from Python to C# or VB.

Cheers!

4 Likes