public void SetName( string name )
| Exception | Condition |
|---|---|
| ArgumentException | The name argument is an empty string. |
| ArgumentNullException | A non-optional argument was null |
Another ways of setting the name is either during construction or during the Start(String) method.
public bool ModelChangingMethod(Autodesk.Revit.DB.Document document) { bool result = false; // All and any transaction should be enclosed in a 'using' // block or guarded within a try-catch-finally blocks // to guarantee that a transaction does not out-live its scope. using (Transaction transaction = new Transaction(document)) { // We can either start a transaction with a name or give // it a name later, but we have to name it before we commit. transaction.Start(); // Some modification(s) of the model here, likely resulting in // changes of the 'result' value // result = ..... if (result == true) { // Since the transaction is still unnamed, // we have to give it a name now before we commit transaction.SetName("Model change"); // Now we can commit if (TransactionStatus.Committed != transaction.Commit()) { result = false; } } else // if modifications failed, transaction is to be rolled back { transaction.RollBack(); } } return result; }
Public Function ModelChangingMethod(document As Autodesk.Revit.DB.Document) As Boolean Dim result As Boolean = False ' All and any transaction should be enclosed in a 'using' ' block or guarded within a try-catch-finally blocks ' to guarantee that a transaction does not out-live its scope. Using transaction As New Transaction(document) ' We can either start a transaction with a name or give ' it a name later, but we have to name it before we commit. transaction.Start() ' Some modification(s) of the model here, likely resulting in ' changes of the 'result' value ' result = ..... If result = True Then ' Since the transaction is still unnamed, ' we have to give it a name now before we commit transaction.SetName("Model change") ' Now we can commit If TransactionStatus.Committed <> transaction.Commit() Then result = False End If Else ' if modifications failed, transaction is to be rolled back transaction.RollBack() End If End Using Return result End Function