Weird plot execute problem with Dynamo Player v.s. Dynamo

Has anybody have experience where Dynamo Player does not behave as expected and the Dynamo environment works fine?
Or does anybody has build a plot dynamo script that plots sheets multiple (2) times, when it should plot only ones.

Some context.
After years of building and using dynamo scripts, our office decided that we wanted to rebuild and improve our first and most used script: the plot (+ export) script. The old one works fine, but could be faster and just a bit smarter.
The first version of the rebuild script gave in random occasions an unrecoverable error in Revit while making a PDF. -still not sure why just a ‘Pure Virtual Function Call’ in the log file- After some tweaking (and adding a sync in front of the script) this did not happen anymore. If it works…
But we do have a new weird problem. Some Sheets are printed twice. And only while using the Dynamo Player. While using Dynamo it works as expected.
This script is build for Revit 2020 and later.

So, what did we do.
Because this only occurs with some Sheets. And only while using the Player it is hard to find the problem.
We did generate an extensive OUT report of all the used and generated objects inside the Python script. This does not show a duplication whatsoever. There is only 1 ‘printManager.SubmitPrint()’ command given. This command resides in a definition that is only called ones.
We also can confirm that our PDFCreator actually receives 2 print jobs.

This is really weird and unwanted. And we do not have clue.
Hopefully someone can give us a direction to look.

Hi, what is the version of Revit and also Dynamo you are using ?
You said (and adding a sync in front of the script) - this means you had some code that was previously executing on a different thread than the thread script is running ? This could be a problem since you can only execute Revit API on OnIdle/External events.
One more thing, can you tell if the script actually executes twice ? Or only the PDF creator somehow receives 2 jobs ?
Since there is a Revit crash involved I would recommend submitting an error report to Revit and if it is possible maybe you can attach a Revit model along with the graph that is causing the issue.

Thank for the reply Bzz.

This script is used in Revit versions 2020, 2021 and 2022.

The script does a sync. and after that is finished it will execute the plot part, because the nodes are linked. We had crashes before but not after adding the sync nodes. We will check this again.

The Dynamo Player doesn’t show any sign that it executes twice. You can see Revit perform the printing in the statusbar. And after the second plot, Dynamo Player will report the outcomes of the script.

It does not crash anymore, thankfully. But using the plotscript with the player will give me sometimes 2x the exact same pdf. And directly using Dynamo gives me only 1 as expected.

Ok, so at least we know that the whole script is not executed twice.
One other thing that comes into my mind as a possible cause for 2x plot is a subtle difference between the way a script is executed in Dynamo vs Player : in Player a graph is always executed by re-opening the graph while in UI it is only opened once for multiple runs. That’s why when you press run in Dynamo multiple times the graph executes only once (if there are no changes to the graph). In Player the workspace is reset, graph is opened, inputs are set and then it executes. So if you press Play in Player twice it will execute the graph twice (even if you don’t change the graph in between runs ).
Something like that or it is possible that there is a Revit API bug related to plotting.
If you have time to make a Revit macro that does the same thing we can confirm that.

Hard to troubleshoot out without the graph itself. A few things that come to mind?

What node o code are you using to create the PDF? If it is custom code you could be creating a loop when you need not, it could be a lacing issue.

Is the behavior the same in all Revit versions? If not it could be associated to the Revit print changes.

Any background opening at play or is it only executing on the active document? If background it could be mismatched list inputs based on page size.

Are you generating a UI passing inputs from the player UI or is the graph ‘input less?’

Have you checked for element binding issues? Could be that an intermediate node with bound elements is triggering the data to pass twice (odd in this context, but possible).

Thanks Jacob and Bzz. I think I found the bug.

Just as in this topic Dynamo Player executing frozen nodes. Our work-in-progress script did contain older frozen versions of the plot node. (always a good idea …) After adding a watchnode after the frozen node and with output in de player, I could see that the wired and frozen version was actually working in de ‘headless’ Dynamo Player enviroment. I could reproduce this behavior in Revit2020. But not in Revit2021 and Revit2022. So I do (hope) this is fixed in newer versions.
In our office multiple (old) versions are live and for different reasons. But the fix is easy.

While working on this, I was wondering if this frozen node bug is also true for Generative Design.
And that it is fixed in Revit2021 and later versiosn.

We will continue testing this script. But I have good hope that it will work just fine.