Opening Dynamo Player

Hi guys,

my second day with pyRevit and my first post here.

I hope you can help me!

I wanna create a tab that opens dynamo player. [My goal is to select an element which has stored a specific parameter value and with clicking on “my button” the right dynamo player script will open.] But first i need to find the right way to open dynamo player

This works with notepad.exe, excel and other programms but unfortunately not with the dynamoplayer.exe file.

Help is much appreciated. I love the AEC industry bc everyone working with BIM is passionate and willing to help!!!

Following this train of thought:

with the spy command ‘list elements’ in pyRevit you can list the postable commands

Dynamo player is a postable command as it runs within Revit, and not outside of it, that is the reason why you cannot call it withe os.system

From the spy tool:

Playlist ID_PLAYLIST_DYNAMO 57282

a quick and very dirty implementation:

import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
import Autodesk
from Autodesk.Revit.UI import RevitCommandId
from Autodesk.Revit.UI import UIApplication
from Autodesk.Revit.UI import ExternalCommandData
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager


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

CmndID = RevitCommandId.LookupCommandId('ID_PLAYLIST_DYNAMO')
CmId = CmndID.Id
uiapp.PostCommand(CmndID)

2020-12-14_11-34-32

3 Likes

Awesome @Jean-Marc!!

it works for pyRevit. It works as i wanted :smiley:

2 Likes

Hi @Jean-Marc again,

what type is “ID_PLAYLIST_DYNAMO” and where in the api docs can i find a list of all commands?

this is a postable command as mentionned above.
you can list them with pyrevit:

with the spy command ‘list elements’ in pyRevit you can list the postable commands

also

Hi @Jean-Marc,

once again i tried it myself but don’t get anywhere.

How can i direct to a file inside of Dynamo Player?

So instead of only opening Dynamo Player, opening Dynamo Player with a .dyn file already

Thanks alot. I think this workflow could help alot of Dynamo users out there!

Happy holidays!

I don’t think this is possible simply through python itself. Waybe with the help of a journal file.
I went through the journal file right after running a dyn file from the player and could not find something significatly helpful.

you could use https://github.com/eirannejad/Revit-Journal-Maker

and make it happen I guess.

Happy holidays

@laurindominik How about using the pyRevit dynamo bundles? :point_right: Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.

Hi Jean-Marc, do you know why this won’t work in a hook? It works perfectly in pushbuttons, but then the same code won’t work in a doc-changed.py hook saying the uiapp loading is the issue. I’d post the code, but it’s essentially this…

first I would not use the doc-changed hook as you would launch your script every time a tiny thing changes in your model.
the hook I use to show warnings when doc-opened looks like this:

import sys

from pyrevit import HOST_APP, framework
from pyrevit import DB, revit
from pyrevit import forms

# from pyrevit import script
# from os import path


doc = __eventargs__.Document
if not doc.IsFamilyDocument:

I think the trouble is the “eventargs” missing in your hook
I am not 100% hook literate ;p

1 Like

an bit of an example

from Autodesk.Revit.UI import UIApplication, RevitCommandId, PostableCommand

Command_ID=RevitCommandId.LookupPostableCommandId(PostableCommand.Undo)
uiapp = UIApplication(doc.Application)
uiapp.PostCommand(Command_ID)

Great thanks for the quick response! I’ve been bashing around using eventargs but haven’t quite figured out the subtleties between them and hooks yet… Seems I’ve been going about getting doc wrong for a start!

PS it’d be a disaster if the script ran constantly so I’ve an external txt file to check at intervals so the script ignores the intended action unless required.

what action are you monitoring exactly?
not sure about the approach

have you checked if one of those does not the job better? https://www.notion.so/Extension-Hooks-b771ecf65f6a45fe87ae12beab2a73a6

I’m trying to use doc-changed. Unfortunately that won’t load the document:

AttributeError: ‘DocumentChangedEventArgs’ object has no attribute ‘Document’

I tried the code below with doc-changed and could not get it to work, did the same with doc-saving and it worked. I am guessing it has to do with the hook context. one is capable of postablecommand, the other is not in the UIApplication context

from pyrevit import forms
from pyrevit import EXEC_PARAMS
from pyrevit import HOST_APP

import Autodesk
from Autodesk.Revit.UI import RevitCommandId


uiApp=HOST_APP.uiapp
CmndID = RevitCommandId.LookupCommandId('ID_PLAYLIST_DYNAMO')
print(CmndID)
CmId = CmndID.Id
print(CmId)
uiApp.PostCommand(CmId)
1 Like

you should create another thread @eprunty

Thanks for your help Jean-Marc, I’ve done the same and it works fine with view-activated also. I’ll create a new thread if I continue to have issues! Cheers

1 Like