Transact |
Options to customize Revit behavior when accessing the central model.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)

The TransactWithCentralOptions type exposes the following members.

Name | Description | |
---|---|---|
![]() | TransactWithCentralOptions | Constructs a new TransactWithCentralOptions. |

Name | Description | |
---|---|---|
![]() | IsValidObject | Specifies whether the .NET object represents a valid Revit entity. |

Name | Description | |
---|---|---|
![]() | Dispose | Releases all resources used by the TransactWithCentralOptions |
![]() | Equals | Determines whether the specified object is equal to the current object. (Inherited from Object ) |
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object ) |
![]() | GetLockCallback | Gets the callback object that changes Revit's default behavior of endlessly waiting and repeatedly trying to lock a central model. |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object ) |
![]() | SetLockCallback | Sets or resets a callback object that would allow an external application to change Revit's default behavior of endlessly waiting and repeatedly trying to lock a central model. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object ) |

public static void SynchWithCentralWithMessage(Document doc)
{
// Checkout workset (for use with "keep checked out worksets" option later)
FilteredWorksetCollector fwc = new FilteredWorksetCollector(doc);
fwc.OfKind(WorksetKind.UserWorkset);
Workset workset1 = fwc.First<Workset>(ws => ws.Name == "Workset1");
WorksharingUtils.CheckoutWorksets(doc, new WorksetId[] { workset1.Id });
// Make a change
using (Transaction t = new Transaction(doc, "Add Level"))
{
t.Start();
Level.Create(doc, 100);
t.Commit();
}
// Tell user what we're doing
TaskDialog td = new TaskDialog("Alert");
td.MainInstruction = "Application 'Automatic element creator' has made changes and is prepared to synchronize with central.";
td.MainContent = "This will update central with all changes currently made in the project by the application or by the user. This operation " +
"may take some time depending on the number of changes made by the app and by the user.";
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Do not synchronize at this time.");
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Synchronize and relinquish all elements.");
td.AddCommandLink(TaskDialogCommandLinkId.CommandLink3, "Synchronize but keep checked out worksets.");
td.DefaultButton = TaskDialogResult.CommandLink1;
TaskDialogResult result = td.Show();
switch (result)
{
case TaskDialogResult.CommandLink1:
default:
{
// Do not synch. Nothing to do.
break;
}
case TaskDialogResult.CommandLink2:
case TaskDialogResult.CommandLink3:
{
// Prepare to synch
// TransactWithCentralOptions has to do with the behavior related to locked or busy central models.
// We'll use the default behavior.
TransactWithCentralOptions twcOpts = new TransactWithCentralOptions();
// Setup synch-with-central options (add a comment about our change)
SynchronizeWithCentralOptions swcOpts = new SynchronizeWithCentralOptions();
swcOpts.Comment = "Synchronized by 'Automatic element creator' with user acceptance.";
if (result == TaskDialogResult.CommandLink3)
{
// Setup relinquish options to keep user worksets checked out
RelinquishOptions rOptions = new RelinquishOptions(true);
rOptions.UserWorksets = false;
swcOpts.SetRelinquishOptions(rOptions);
}
doc.SynchronizeWithCentral(twcOpts, swcOpts);
break;
}
}
}
