SynchronizeWithCentral() Exception

SynchronizeWithCentral() Exception

tamas.deri
Advocate Advocate
2,837 Views
33 Replies
Message 1 of 34

SynchronizeWithCentral() Exception

tamas.deri
Advocate
Advocate

Using

doc.SynchronizeWithCentral(transOpts, syncOpts)

 sometimes throws an exception saying 'An internal error has occured.' which is not documented on revitapidocs, only a similar exception that is 'An internal error happened on the central model, please contact the server administrator.' which seems slightly different to me. However, it is still possible to sync the model with the OOTB Sync button on the UI. A more verbose explanation would be very handy, because it's quite difficult to handle this exception with so little knowledge.

0 Likes
2,838 Views
33 Replies
Replies (33)
Message 2 of 34

jeremy_tammik
Alumni
Alumni

Yes, indeed. Many API exceptions are less informative than the corresponding error messages presented by the end user interface. Therefore, it is almost always useful to try to reproduce any API error you encounter in the user interface to better understand what is going on and what the problem might be.

 

You could submit a wish for better API exception descriptions to the Revit Idea Station.

 

Whenever you require new or enhanced functionality, the Revit Idea Station is the place to go.

 

Please search there for a corresponding wish list entry for the suggested functionality and add your comments to it, or create a new one, if none already exists:

 

https://forums.autodesk.com/t5/revit-ideas/idb-p/302

 

Tag it as an API wish:

 

https://forums.autodesk.com/t5/revit-ideas/idb-p/302/tab/most-recent/label-name/api

 

Ensure it gets as many votes as possible to underline its importance to you and the rest of the developer community.

 

The Revit Idea Station is currently one of the main driving input forces for Revit API enhancements.

 

The Revit development team look there. Your comment here in the discussion forum might be overlooked.

 

Thank you!

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 34

tamas.deri
Advocate
Advocate

Hi Jeremy!

 

I've tried to reproduce the error via the user interface before, but it wasn't possible, because there were no issues using the original sync button. It did accomplish the sync operation without errors. In fact thats why I asked it here, if anybody has some explanation.  I'm surely will create an API wish, anyway. Thanks!

0 Likes
Message 4 of 34

RPTHOMAS108
Mentor
Mentor

Probably you have to give more details about the context you are calling that function in and the options being used with it (if any):

TransactWithCentralOptions

SynchronizeWithCentralOptions

 

Is it cloud model etc.

 

You should probably not get that exception noted but that is often a symptom of doing something unanticipated. Without the above clarifications would be hard for anyone to determine the cause of that exception especially because you should not ordinarily get it i.e. anything slipping through other more specific exception checks (not failing those criteria) could lead to it. The obvious needs to be ruled out.

 

If it is a periodic thing it could be due to transient central file lock and if any call back is being set up in relation to that. It is just guessing without more details really though.

0 Likes
Message 5 of 34

tamas.deri
Advocate
Advocate

You are right, my question was quite generic, but the use case is also. The reason I didn't go into details is that it happens quite rarely. Most of the time it succeeds without errors. The part of the code that does the sync is that simple:

    twc_opts = TransactWithCentralOptions()
    swc_opts = SynchronizeWithCentralOptions()
    swc_opts.Comment = 'Whatever!'

    doc.SynchronizeWithCentral(twc_opts, swc_opts)

The error only happened in non-cloud models so far.

0 Likes
Message 6 of 34

RPTHOMAS108
Mentor
Mentor

From what context is it called:

e.g. IExternalCommand, IExternalEventHandler, IUpdeter?

 

The occasional problems are the hardest to resolve. Probably you have to put some logging system in place to monitor what the users experiencing the problems are doing at the time and if they are interacting with one another on same central model.

 

It's the kettle boiling issue e.g. everyone does the same thing just before lunch or at end of day etc. From logging you see the patterns, otherwise very hard.

Message 7 of 34

tamas.deri
Advocate
Advocate

It is a simple pyRevit command, so it is IExternalCommand. 

I had more verbose logging as a plan B, I just hoped that someone already had this issue, and went down the same road. I'll let you know once I figured this out.

0 Likes
Message 8 of 34

franciscopossetto
Advocate
Advocate

Hey,

 

Have you implemented the ICentralLockedCallback interface? I remember have had a similar problem a couple of years ago, and I solved it using this interface.  

 

In case you are not using it, you can see a sample here:

https://www.revitapidocs.com/2016/7de73a7b-68f0-87f2-f6a9-97d824024877.htm

 

I hope it helps,

Kind regards.

Github:
https://github.com/franpossetto
0 Likes
Message 9 of 34

tamas.deri
Advocate
Advocate

I've used it before in a different tool. AFAIK it is not required, thus it only overrides the default behaviour of waiting for the central model to be unlocked. I might try it, but how can I know, if Revit gaves up on trying to sync, if it finds a locked central model? I understand that `SynchronizeWithCentral()` has no return values, so I have to investigate this a bit further.

0 Likes
Message 10 of 34

tamas.deri
Advocate
Advocate

Just a short follow-up: I've implemented the ICentralLockedCallback interface as suggested without any luck. The exception is still happening once in a while. I've tried more verbose logging, but couldn't get any further. There wasn't any similarity between the cases. API docs says at the InternalException class that one should contact Autodesk Developer Support if it occures, because: The exception that is thrown when an issue in the Revit code resulted in an unexpected error. Unfortunately I'm not a member of ADN I don't know how to proceed.

0 Likes
Message 11 of 34

jeremy_tammik
Alumni
Alumni

If you could provide a minimal reproducible case, the developer team would be glad to analyse that:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

  

Obviously, if the problematic behaviour is only intermittent, it might be hard to reproduce reliably.

 

Anyway, sharing a minimal non-confidential and complete add-in code would be a good starting point.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 12 of 34

tamas.deri
Advocate
Advocate

It is indeed intermittent, the exception only occurs in 1-2% of the executions, so it is really difficult to reproduce on purpose. I've read the instructions for the minimal reprodicable case, but I have to ask timidly if it is okay if I submit the python version of the code, that could be run via pyrevit or RPS, with rpw?

0 Likes
Message 13 of 34

jeremy_tammik
Alumni
Alumni

Yes, sure. I will be glad to take a look at the code in any shape or form. Possibly, it can be turned into a Python Revit macro, can't it? Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 14 of 34

tamas.deri
Advocate
Advocate

Jeremy, I've tried to reach you via PM, but in case you missed it let me post it here as well, so please find the message below:

 

Dear Jeremy!
I'm contacting you regarding the InternalException we were discussing in the following topic: https://forums.autodesk.com/t5/revit-api-forum/synchronizewithcentral-exception/m-p/10462111#M57124
Just to wrap things up: sometimes the SynchronizeWithCentral() function throws an InternalException, with the message: An Internal Error is occured. It only happens in like 1-2% of the executions, so it is quite rare, and I can't tie it to anything, and also I wasn't able to reproduce it, I'm only able to see the exception in other users logs, and it is confirmed that it fails to synchronize the model for them. If it occurs, any repeated executions will throw the same exception, but it is possible to synchronize the model with the built-in sync button, and later the python version will work again.

I've stripped the code to the minimum, and it can be used as a python macro. Unfortunately I can't include a test project, because the command needs a workshared model, obviously, but this way it can be run on any workshared model as a macro command. The code is:

 

 

 def Sync(self):
        uidoc = self.ActiveUIDocument
        doc = uidoc.Document
       
        def SetActiveView(view):
            if not isinstance(view, View):
                raise TypeError(
	               'Element [{}] is not a View!'.format(view.Id.IntegerValue)
	            )
            name = view.Name
            if view.ViewType != ViewType.Internal and \
                    view.ViewType != ViewType.ProjectBrowser:
                uidoc.ActiveView = view
                return name
            else:
                return 'INTERNAL / PB: ' + name
        
        sv_settings = FilteredElementCollector(doc) \
        				.OfClass(StartingViewSettings) \
        				.ToElements()[0]
        
        starting_view_id = sv_settings.ViewId
        presync_view_id = uidoc.ActiveGraphicalView.Id
        if starting_view_id != ElementId.InvalidElementId:
            sync_view_id = starting_view_id
        else:
            sync_view_id = presync_view_id
        
        sync_view = doc.GetElement(sync_view_id)
        
        uiviews = uidoc.GetOpenUIViews()
        uiview_ids = map(lambda x: x.ViewId, uiviews)
        
        closed_views = []
        
        try:
            uidoc.ActiveView = doc.GetElement(sync_view_id)
            for uiview in uiviews:
                view_id = uiview.ViewId
                if isinstance(sync_view, ViewSheet):
                    view = doc.GetElement(view_id)
                    snum = view.get_Parameter(
                    	BuiltInParameter.VIEWER_SHEET_NUMBER
                    ).AsString()
                    if snum == sync_view.SheetNumber:
                        continue
                if view_id.IntegerValue != sync_view_id.IntegerValue :
                    uiview.Close()
                    view_name = doc.GetElement(view_id).Name
                    closed_views.append(view_name)
        
            twc_opts = TransactWithCentralOptions()
            swc_opts = SynchronizeWithCentralOptions()
            swc_opts.SetRelinquishOptions(RelinquishOptions(True))
            swc_opts.Comment = 'SuperSync!'
        
            doc.SynchronizeWithCentral(twc_opts, swc_opts)
        except Exception as e:
        	TaskDialog.Show('Exception', e.ToString())
        
        opened_views = []
        for view_id in uiview_ids:
            view = doc.GetElement(view_id)
            if isinstance(view, View):
                try:
                    opened_views.append(SetActiveView(view))
                except Exception as e:
        			TaskDialog.Show('Exception', e.ToString())
        try:
            presync_view = doc.GetElement(presync_view_id)
            if presync_view:
                SetActiveView(presync_view)
        except Exception as e:
        	TaskDialog.Show('Exception', e.ToString())
        
        if starting_view_id not in uiview_ids:
            uiviews = uidoc.GetOpenUIViews()
            for uiview in uiviews:
                if uiview.ViewId.IntegerValue == starting_view_id.IntegerValue:
                    try:
                        uiview.Close()
                    except Exception as e:
        				TaskDialog.Show('Exception', e.ToString())
                    break
		
#		message = '\n'.join(['Closed Views:'] + closed_views + ['\nOpened Views:'] + opened_views)
#		TaskDialog.Show('Report', message)

 

 

I've commented out the reporting because for some unknown reason the TaskDialog is shown n times where n is the number of the closed views, like it was in a for loop, but it is not.

 

Thanks in advance for your help, and please keep me updated if any progress is made on the issue!

Best Regards,

Tamás

0 Likes
Message 15 of 34

tamas.deri
Advocate
Advocate

I have managed to introduce the error on purpose:

Creating an eventhandler for DocumentSynchronizingWithCentral event, cancelling it, and calling

doc.SynchronizeWithCentral() will throw the above mentioned internal error.
I was calling the custom sync function with a specific comment, that is checked in the event handler, so an infinite loop couldn't happen.
0 Likes
Message 16 of 34

jeremy_tammik
Alumni
Alumni

Being able to produce the error at will is very good news. Can you provide a complete minimal reproducible case demonstrating the internal error exception being consistently thrown? Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 17 of 34

jeremy_tammik
Alumni
Alumni

Dear Tamás,

 

Thank you for your report and extensive research on this.

 

I logged the issue REVIT-211052 [SynchronizeWithCentral throws internal error exception] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is crucial. Our engineering team has limited resources and must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 18 of 34

Messi_Hu
Autodesk
Autodesk

@tamas.deri , thank for your questions, can you upload the journal if it is not confidential when you observe the issue happen again? For this not easy reproducible issue, we need journal to help undestand the senario.

0 Likes
Message 19 of 34

tamas.deri
Advocate
Advocate

Here is the relevant section of the journal file:

 'E 23-Aug-2023 12:23:37.879;   0:< 
  Jrn.MouseMove    0 ,    184 ,     11
  'E 23-Aug-2023 12:23:37.879;   0:< 
  ' [Jrn.Tooltip] Rvt.Attr.Tooltip.CommandID: ID_FILE_SAVE_TO_CENTRAL Rvt.Attr.Tooltip.ElapsedTime: 0,9023354 Rvt.Attr.Tooltip.Enabled: True Rvt.Attr.Tooltip.IsFirst: True Rvt.Attr.Tooltip.Key: ID_FILE_SAVE_TO_CENTRAL Rvt.Attr.Tooltip.Progressive: True Rvt.Attr.Tooltip.Progressive.Delay: 2 
  'E 23-Aug-2023 12:23:37.940;   0:< 
  Jrn.Command "Ribbon"  , "Save the active project back to the Central Model , ID_FILE_SAVE_TO_CENTRAL" 
  ' 0:< Unnecessary nesting;ArrowUI_4;-1;ID_FILE_SAVE_TO_CENTRAL ;N++EB(NB); 
  ' 1:<   System (MB) [Available /  Total ]  [Revit Memory Usage (MB)   ] 
  ' 1:< RAM Statistics:     7326 /    65241       838=InUse     1465=Peak  
  ' 1:< VM  Statistics: 134176489 / 134217727      1586=InUse     1587=Peak  
  ' 1:<  0 ModelServerState "Created": Current server = "Not Queried", Model server = "", Model server state = "Not Applicable" 
  'C 23-Aug-2023 12:23:37.971;   2:< ADialog::doModal start 
    ' 2:< ::82:: Delta VM: Avail -15 -> 134176474 MB, Used +2 -> 1587 MB, Peak +4 -> 1591 MB; RAM: Avail -29 -> 7297 MB, Used +4 -> 842 MB 
    ' 2:< GUI Resource Usage GDI: Avail 8934, Used 1066, User: Used 598 
    'E 23-Aug-2023 12:23:39.952;   2:< 
    Jrn.PushButton "Modal , Synchronize with Central , Dialog_Revit_PartitionsSaveToCentral"  _
              , "OK, IDOK" 
  'C 23-Aug-2023 12:23:40.001;   2:< ADialog::doModal stop 
  '  2.031232    2:<<doModal 
  ' 2:< ::83:: Delta VM: Avail -8 -> 134176466 MB, Used +18 -> 1606 MB, Peak +98 -> 1690 MB; RAM: Avail -102 -> 7196 MB, Used +141 -> 983 MB 
  ' 2:< GUI Resource Usage GDI: Avail 8926, Used 1074, User: Used 599 
  'C 23-Aug-2023 12:23:44.114;  DBG_WARN: An internal error has occurred.
  '
  'Expect a soft crash after this warning.
  '
  'ApplicationException is being thrown on behalf of the function <bool __cdecl ADocument::synchronizeWithCentralInternal_(class TransactWithCentralOptions &,class SynchronizeWithCentralOptions &)>. Dump file: C:\Users\tamas.deri\AppData\Local\Autodesk\Revit\Autodesk Revit 2022\Journals\journal.0745.0001.dmp: line 6939 of E:\Ship\2022_px64\Source\Revit\RevitDB\Document\Document.cpp. 
  '  3.722098!!! 2:!!!BIG_GAP DesktopStorageLogic::onFileSaveToCentral Save to Central 

please let me know if you need additional details, or the dump file

0 Likes
Message 20 of 34

Messi_Hu
Autodesk
Autodesk

Can not see clues in above journal, I found there is a dmp file

journal.0745.0001.dmp

, can you send me this file and journal. I'll see call stack of it.

@tamas.deri 

0 Likes