SynchronizeWithCentral Errors
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there, I'm working on a script to automatically link files hosted on BIM360 and then synchronize back to central to save the changes. Everything works perfectly except when it gets to the synchronization. For a little more context, the code works by manually opening a workshared, cloud-hosted file from BIM360 in Revit, and then the action is triggered manually (I've been using the Add-In Manager). It gets any necessary cloud data from the open document. Authentication for BIM360 is handled manually, but with the token it works (it uses this to find the linked files, and this works fine).
The issue is I cannot get the file to synchronize at all. I've tried SynchronizeWithCentral using the method just copied from the API documentation:
public void SyncWithoutRelinquishing(Document doc)
{
// Set options for accessing central model
TransactWithCentralOptions transOpts = new TransactWithCentralOptions();
SynchLockCallback transCallBack = new SynchLockCallback();
// Override default behavior of waiting to try again if the central model is locked
transOpts.SetLockCallback(transCallBack);
// Set options for synchronizing with central
SynchronizeWithCentralOptions syncOpts = new SynchronizeWithCentralOptions();
// Sync without relinquishing any checked out elements or worksets
RelinquishOptions relinquishOpts = new RelinquishOptions(false);
syncOpts.SetRelinquishOptions(relinquishOpts);
// Do not automatically save local model after sync
syncOpts.SaveLocalAfter = false;
syncOpts.Comment = "Changes to Workset1";
try
{
doc.SynchronizeWithCentral(transOpts, syncOpts);
}
catch (Exception e)
{
TaskDialog.Show("Synchronize Failed", e.Message);
}
}
// This class implements the ICentralLockedCallback to override Revit's default
// behavior for how to handle when the central model is locked by another user
class SynchLockCallback : ICentralLockedCallback
{
// If unable to lock central, give up rather than waiting
public bool ShouldWaitForLockAvailability()
{
return false;
}
}
This produced an Autodesk.Revit.Exceptions InvalidOperationException: Saving local before first reload latest and after saving changes to central in Synchronize with Central is mandatory for server-based local models. Then here is where it gets even more confusing: I changed line 15 to
syncOpts.SaveLocalAfter = true; to fix this problem. And then I get the error: An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Length cannot be less than zero.
Any further changes to the code produced this error. I removed the relinquish options, as my original intent was to relinquish everything (I was just testing the given code), same error. I tried keeping everything with the default settings:
TransactWithCentralOptions transact = new TransactWithCentralOptions();
SynchronizeWithCentralOptions synch = new SynchronizeWithCentralOptions();
synch.Comment = "Synchronized with central";
doc.SynchronizeWithCentral(transact, synch);
Same error, length cannot be less than zero. I tried using someone else's code I found online, which they claimed works. Same error. Is there any way to synchronize this file? It works manually, of course, but I'd like to automate it as it's part of a larger script.
I've also tried using SaveAs with the cloud path, Save (which can save the local version), SaveAsCloudModel and SaveCloudModel, none of which work. Any help would be so appreciated 🙂
Lastly, here's the stack trace of the error:
Parameter name: length
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
at Autodesk.Revit.UI.Collaborate.Views.CollaborationSWCDialog..ctor(SWCStep step, IntPtr pOwner)
at Autodesk.Revit.UI.Collaborate.Views.CollaborationSWCDialog.WindowWorkerThread(Object arg)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)</ExceptionString></Exception></TraceRecord>
An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
Length cannot be less than zero.
The program '[12456] Revit.exe' has exited with code 4294967295 (0xffffffff).