本文整理汇总了C#中Transaction.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Commit方法的具体用法?C# Transaction.Commit怎么用?C# Transaction.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DuplicateDependent
//Description: Create 4 Dependent Views for currently active View
public void DuplicateDependent()
{
//setup uidoc and doc for accessing the Revit UI (uidoc and the Model (doc)
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
//create a transaction
using(Transaction t = new Transaction(doc, "Duplicate View 5x"))
{
//start the transaction
t.Start();
//create a counter for incrementing alphabet
int i = 0;
//loop through until you reach 4(change 4 to increase/decreas the before running macro)
while(i<4)
{
//duplicate the currently active view
ElementId dupViewId=uidoc.ActiveView.Duplicate(ViewDuplicateOption.AsDependent);
//get the new dependent view
View dupView = doc.GetElement(dupViewId) as View;
//use char command to get the Letter A
char c = (char)(i+65);
//rename the dependent view to include the original name and the new Area
dupView.Name = uidoc.ActiveView.Name + " - AREA " + c.ToString();
//increment the char each loop (A, B, C, etc)
i++;
}
//finalize the transaction
t.Commit();
}
}
示例2: IncrementX
/// <summary>
/// adds 1 to X
/// </summary>
public void IncrementX()
{
Transaction transaction = new Transaction(_dbDoc);
transaction.Start("Score Update");
_xScore.Text = X_SCORE_PRE_TEXT + (GetXScore()+1);
transaction.Commit();
}
示例3: Execute
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
try
{
Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");
documentTransaction.Start();
// Get the application of revit
Autodesk.Revit.UI.UIApplication revit = commandData.Application;
// New a real operation class.
ModelLines deal = new ModelLines(revit);
// The main deal operation
deal.Run();
documentTransaction.Commit();
// if everything goes well, return succeeded.
return Autodesk.Revit.UI.Result.Succeeded;
}
catch (Exception ex)
{
// If any error, give error information and return failed
message = ex.Message;
return Autodesk.Revit.UI.Result.Failed;
}
}
示例4: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
UIDocument uidoc = app.ActiveUIDocument;
Document doc = uidoc.Document;
List<Element> rooms = new List<Element>();
if( !Util.GetSelectedElementsOrAll(
rooms, uidoc, typeof( Room ) ) )
{
Selection sel = uidoc.Selection;
message = ( 0 < sel.GetElementIds().Count )
? "Please select some room elements."
: "No room elements found.";
return Result.Failed;
}
using ( Transaction t = new Transaction( doc ) )
{
t.Start( "Bump Room Occupancy" );
foreach ( Room room in rooms )
{
BumpOccupancy( room );
}
t.Commit();
}
return Result.Succeeded;
}
示例5: CreateDimensionElement
/// <summary>
/// Create a new dimension element using the given
/// references and dimension line end points.
/// This method opens and commits its own transaction,
/// assuming that no transaction is open yet and manual
/// transaction mode is being used.
/// Note that this has only been tested so far using
/// references to surfaces on planar walls in a plan
/// view.
/// </summary>
public static void CreateDimensionElement(
View view,
XYZ p1,
Reference r1,
XYZ p2,
Reference r2)
{
Document doc = view.Document;
ReferenceArray ra = new ReferenceArray();
ra.Append( r1 );
ra.Append( r2 );
Line line = Line.CreateBound( p1, p2 );
using( Transaction t = new Transaction( doc ) )
{
t.Start( "Create New Dimension" );
Dimension dim = doc.Create.NewDimension(
view, line, ra );
t.Commit();
}
}
示例6: CreateInstances
private void CreateInstances(List<FamilySelectorViewModel> ds)
{
UpdateFamilySymbolTypes(ds);
using( var transaction = new Transaction(_creator.RevitDoc.Document, "CreateFamilyInstance"))
{
transaction.Start();
foreach (var vm in ds)
{
foreach (var instanse in vm.DataType.Instances)
{
var convertedCoords = GetConvertedCoords(instanse);
_creator.CreateInstanceInPlace(convertedCoords, vm.SelectedSymbol.Item1);
}
foreach (var cabel in vm.DataType.CabelInstances)
{
var convertedCoords = GetConvertedCoords(cabel);
var cabelInstance = _creator.CreateInstanceInPlace(convertedCoords, vm.SelectedSymbol.Item1);
var lengthParam = cabelInstance.get_Parameter("Length");
if (lengthParam != null)
lengthParam.Set(Utils.MetersToFeet(cabel.Length));
var fromParam = cabelInstance.get_Parameter("From");
if (fromParam != null)
fromParam.Set(cabel.From);
}
}
transaction.Commit();
}
}
示例7: UpdateReferencingSheet
void UpdateReferencingSheet(
ViewSection selectedViewport)
{
BuiltInParameter bip
= BuiltInParameter.VIEW_DISCIPLINE;
Parameter discipline
= selectedViewport.get_Parameter( bip );
int disciplineNo = discipline.AsInteger();
Document doc = selectedViewport.Document;
Transaction transaction = new Transaction( doc );
if( TransactionStatus.Started
== transaction.Start( "Updating the model" ) )
{
//switch( disciplineNo )
//{
// case 1:
// discipline.Set( 2 );
// break;
// default:
// discipline.Set( 1 );
// break;
//}
//discipline.Set( disciplineNo );
discipline.Set( 1 == disciplineNo ? 2 : 1 );
transaction.Commit();
}
}
示例8: TestOne
public void TestOne()
{
using (var t = new Transaction(DocumentManager.Instance.CurrentDBDocument))
{
if (t.Start("Test one.") == TransactionStatus.Started)
{
//create a reference point
var pt = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewReferencePoint(new XYZ(5, 5, 5));
if (t.Commit() != TransactionStatus.Committed)
{
t.RollBack();
}
}
else
{
throw new Exception("Transaction could not be started.");
}
}
//verify that the point was created
var collector = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
collector.OfClass(typeof (ReferencePoint));
Assert.AreEqual(1, collector.ToElements().Count);
}
示例9: Execute
public void Execute(UIDocument uiDocument, object data)
{
var filter = data as string;
if (null == filter) return;
var family = "TestAnno";
var parameters = new[] {"Series", "Number", "Text"};
var document = uiDocument.Document;
var schedule =
new FilteredElementCollector(document).OfClass(typeof (ViewSchedule))
.FirstOrDefault(s => s.Name.Contains(filter));
Element schedElem = null;
using (var t = new Transaction(document))
{
t.Start("Place schedule");
if (null == schedule)
schedule = Schedule.Factory(uiDocument.Document, family, parameters, filter);
schedElem = ScheduleSheetInstance.Create(uiDocument.Document, uiDocument.ActiveView.Id, schedule.Id, new XYZ());
t.Commit();
}
uiDocument.Selection.SetElementIds(new List<ElementId>() { schedElem.Id });
//var uiapp = new UIApplication(document.Application);
//uiapp.PostCommand(RevitCommandId.LookupCommandId("ID_EDIT_MOVE"));
//uiDocument.PromptToPlaceViewOnSheet(schedule, false);
}
示例10: deleteLinePatterns
public void deleteLinePatterns(Document doc)
{
var collector = new FilteredElementCollector(doc)
.OfClass(typeof(LinePatternElement)).Where(i => i.Name.StartsWith("IMPORT")).ToList();
List<ElementId> ids = new List<ElementId>();
for (int i = 0; i < collector.Count(); i++)
{
ids.Add(collector[i].Id);
}
using (Transaction t = new Transaction(doc, "Remove Pattern"))
{
t.Start();
try
{
doc.Delete(ids);
}
catch (Exception)
{
t.RollBack();
return;
}
t.Commit();
}
}
示例11: Execute
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
try
{
Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");
documentTransaction.Start();
using (SpotDimensionInfoDlg infoForm = new SpotDimensionInfoDlg(commandData))
{
//Highlight the selected spotdimension
if (infoForm.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& infoForm.SelectedSpotDimension != null)
{
elements.Insert(infoForm.SelectedSpotDimension);
message = "High light the selected SpotDimension";
return Autodesk.Revit.UI.Result.Failed;
}
}
documentTransaction.Commit();
return Autodesk.Revit.UI.Result.Succeeded;
}
catch (Exception ex)
{
// If there are something wrong, give error information and return failed
message = ex.Message;
return Autodesk.Revit.UI.Result.Failed;
}
}
示例12: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
Transaction tx = new Transaction( doc,
"Extract Part Atom" );
tx.Start();
string familyFilePath
= "C:/Documents and Settings/All Users"
+ "/Application Data/Autodesk/RAC 2011"
+ "/Metric Library/Doors/M_Double-Flush.rfa";
string xmlPath = "C:/tmp/ExtractPartAtom.xml";
app.ExtractPartAtomFromFamilyFile(
familyFilePath, xmlPath );
tx.Commit();
return Result.Succeeded;
}
示例13: application_DocumentOpened
public void application_DocumentOpened(object sender, DocumentOpenedEventArgs args)
{
Document doc = args.Document;
//add new parameter when a document opens
Transaction transaction = new Transaction(doc, "Add PhaseGraphics");
if (transaction.Start() == TransactionStatus.Started)
{
var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Autodesk\Revit\Addins\2012\PhaseSyncSharedParams.txt");
SetNewParameterToInstances(doc, fileName.ToString());
transaction.Commit();
}
//sync phasegraphics param with Phases of all empty PhaseGraphics objects
Transaction transaction2 = new Transaction(doc, "Sync PhaseGraphics");
ICollection<Element> types = null;
if (transaction2.Start() == TransactionStatus.Started)
{
// Apply the filter to the elements in the active document
FilteredElementCollector collector = new FilteredElementCollector(doc);
types = collector.WherePasses(PhaseGraphicsTypeFilter()).ToElements();
foreach (Element elem in types)
{
//get the phasegraphics parameter from its guid
if (elem.get_Parameter(new Guid(PhaseGraphicsGUID)).HasValue == false)
{
SyncPhaseGraphics(doc, elem);
}
}
transaction2.Commit();
}
}
示例14: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
// Get application and document objects
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
UIDocument uidoc = uiApp.ActiveUIDocument;
try
{
if (!doc.IsWorkshared)
{
TaskDialog.Show("Workset 3D View", "Project doesn't have any Worksets.");
}
else
{
ViewFamilyType vft = new FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
.Cast<ViewFamilyType>()
.FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional);
using (Transaction t = new Transaction(doc, "Workset View Creation"))
{
t.Start();
int i = 0;
// Loop through all User Worksets only
foreach (Workset wst in new FilteredWorksetCollector(doc)
.WherePasses(new WorksetKindFilter(WorksetKind.UserWorkset)))
{
// Create a 3D View
View3D view = View3D.CreateIsometric(doc, vft.Id);
// Set the name of the view to match workset
view.Name = "WORKSET - " + wst.Name;
// Isolate elements in the view using a filter to find elements only in this workset
view.IsolateElementsTemporary(new FilteredElementCollector(doc)
.WherePasses(new ElementWorksetFilter(wst.Id))
.Select(q => q.Id)
.ToList());
i++;
}
t.Commit();
TaskDialog.Show("Workset 3D View", i.ToString() + " Views Created Successfully!");
}
}
return Result.Succeeded;
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
return Result.Cancelled;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
}
示例15: Execute
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
try
{
Transaction tran = new Transaction(commandData.Application.ActiveUIDocument.Document, "Rooms");
tran.Start();
// create a new instance of class data
RoomsData data = new RoomsData(commandData);
// create a form to display the information of rooms
using (roomsInformationForm infoForm = new roomsInformationForm(data))
{
infoForm.ShowDialog();
}
tran.Commit();
return Autodesk.Revit.UI.Result.Succeeded;
}
catch (Exception ex)
{
// If there are something wrong, give error information and return failed
message = ex.Message;
return Autodesk.Revit.UI.Result.Failed;
}
}