Synchronize with Central

Developers have often asked how to programmatically synchronise with central, which is currently not supported by the Revit API.

I discussed this issue once again recently with Erik Eriksson of

White Arkitketer AB
,
and he tested and verified that yet another risky workaround can be used to achieve this, as always

at your own peril
.

Question: I have a worksharing project in which I am trying to open a file, make changes, synchronize the changes to the central file and then close the file.
I can complete all the tasks needed except synchronization part.
Is that not possible through the API?
I haven’t found anything regarding this in the API manuals for Revit 2011 and 2012.

Is there a workaround for this?
Our project is a very complex hospital of 370 000 m2 and we have 17 different project files.
Making changes to these through the API would be a really powerful tool for us and we must be able to synchronize the changes to the central file quickly since there are 90 people working in these 17 files.

Any thoughts are welcome.
I’ve tried opening the central files, making changes, saving these and closing.
But that doesn’t relinquish the elements changed.

I looked at your two year old post on auto-confirming a save dialogue by

subscribing to the DialogboxShowingEvent
.

Could this also be used to auto-confirm the synchronize with central dialog box that I can bring up using the API?

Answer: There are several different possible ways to suppress unwanted dialogues programmatically in Revit, both using the Revit and the Windows API:

The old method that was already available in Revit 2010 was to

use the DialogBoxShowing event
, as you discovered, which can be used to dismiss a dialogue programmatically.

The Revit 2011 API also includes a comprehensive

failure processing API
which
can used to do much more than reacting to the DialogBoxShowing event.

If all else fails and you just want to get rid of the dialogue box by any means, you can also use the Windows API to detect when it is displayed and dismiss it using my

dialogue clicker application
.

In all three cases, you have to invest some research of your own to discover (in the debugger) what exact conditions you can use to reliably determine that the dialogue that is popping up really is the one you are interested in.
The approaches for that are described in the blog posts.

To optimise performance and minimise the impact and complexity, you might also want to set up your event handlers so that they are only active for a limited period of time, when you are expecting the unwanted dialogue to be displayed, and then remove them again after dismissing it.

Response: Success!
<!–

Tänkte bara uppdatera dig om mitt ärende med att utföra en “synchronize with central” via ett externt commando i APIt.

Jag äntligen lyckats! Jag snubblade på lösningen på din blogg. Även om du då beskrev hur man skulle kunna stänga det aktiva dokumenet genom att använda SendKeys-klassen i en separat tråd.

I princip så kör jag detta och lyckas trigga igång en synchronisering:

Frågan är nu bara vad du tror om det?
Eftersom man egentligen bara använder “UI-funktionalitet” så borde det väl vara ganska säkert?

Allt är väl mer eller mindre relativt osäkert när man “lurar” APIt såhär?
–>
I used your solution to close the active document by

executing a SendKeys call
in
a separate thread.

In principle I am doing the same thing and triggering the synchronisation using


SendKeys.SendWait("{F10}");
SendKeys.SendWait("3");
SendKeys.SendWait("{ENTER}");

The question is: what do you think about this?

I am only using the official UI functionality, and it should work irrespectively of whether a user or my SendKeys calls are driving it, shouldn’t it?

Answer: Well, you should definitely pay close attention to the warnings of Arnošt Löbel, voiced in various blog posts, including the

disclaimer
on
the very post you found, and yet again in all clarity in his class on this topic at Autodesk University 2011,

CP5381
,
on asynchronous interactions and managing modeless UI, which would be well worth a blog post all on its own, at least.

Maybe using

UI Automation
instead
might possibly be a slightly safer bet, since I heard rumours that the addressee of the SendKeys messages may sometimes get confused.

Response: Yes, indeed.
In order to make this as safe as possible, I execute it during an idling event to make sure that the document really is ready.
I also subscribe to the DocumentSynchronizedWithCentral to make sure that the document was synchronized.

I attended Arnošt’s class during AU so I am very cautious with non-supported API-calls.


Comments

5 responses to “Synchronize with Central”

  1. Hello, Jeremy.
    Thank you very much for useful post.
    Are you planning to add API methods to synchronize file with central programmatically in future version? I think it would be very useful.
    Thanks, Victor.

  2. Dear Victor,
    God knows whether we will see the sun tomorrow.
    All I can say is that we have an open wish list item for this functionality.
    Cheers, Jeremy.

  3. Thanks for nice answer, Jeremy.
    At this moment I don’t need this functionality. But if you open wish list case for it – it is good news already. May be when I need sync files via API you will already add it.:)
    Best Regards, Victor.

  4. Re: “Could this also be used to auto-confirm the synchronize with central dialog box that I can bring up using the API?”
    I cannot get the dialog to come up. I can open detached, save to central, and handle those dialog boxes. But closing doesn’t prompt me to save or relinquish because the file was just saved. I’ve tried reopening the file and beginning and ending a transaction, then closing to trigger the ‘save local’ and ‘relinquish’ task boxes with no luck.
    I thought this might be because the documents weren’t ever set as the active document. So i’m experimenting with the ‘OpenAndActivateDocument’ but it’s not clear if that is a solution.
    How do I trigger the ‘save local’ and ‘relinquish’ dialog boxes? Thank you!

  5. Dear Bryan,
    Sorry, I don’t really know. Good luck with your experiments and let us now what you find out.
    Cheers, Jeremy.

Leave a Reply to VictorCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading