Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Transaction.Start

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
1488 Views, 6 Replies

Transaction.Start

I am trying to insert an element into the active document and I have been stuck on getting the transaction to start. Below is a screen shot of the code I am running and the current documents properties are also visible. I understand the doc current state: isReadOnlyFile is false, meaning the document is meant to be modified at some point. isModifiable and isReadOnly are properties that cannot be directly manipulated. What am I missing to get the transaction started? I thought transaction internally took care of these things(isReadOnly, isModifiable). 

Labels (1)
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

    Public Function Execute(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result Implements IExternalCommand.Execute

        Dim app As Autodesk.Revit.UI.UIApplication = commandData.Application

        Dim uiDoc As UIDocument = app.ActiveUIDocument
        Dim doc As Document = uiDoc.Document
        Dim inLevel As ElementId
        Dim collector As New FilteredElementCollector(doc)
        Dim collection As ICollection(Of Element) = collector.OfClass(GetType(Level)).ToElements()
        For Each e As Element In collection
            Dim level As Level = TryCast(e, Level)

            If level IsNot Nothing Then
                If level.Name.Equals("Level 1") Then
                    inLevel = level.Id
                End If
            End If
        Next


        Using T As New Transaction(doc, "Make Stuff")

            If T.Start() = TransactionStatus.Started Then

                CreateWall(doc, inLevel)
                ' Ask the end user whether the changes are to be committed or not
                Dim taskDialog__1 As New TaskDialog("Revit")
                taskDialog__1.MainContent = "Click either [OK] to Commit, or [Cancel] to Roll back the transaction."
                Dim buttons As TaskDialogCommonButtons = TaskDialogCommonButtons.Ok Or TaskDialogCommonButtons.Cancel
                taskDialog__1.CommonButtons = buttons

                If TaskDialogResult.Ok = taskDialog__1.Show() Then
                    ' For many various reasons, a transaction may not be committed
                    ' if the changes made during the transaction do not result a valid model.
                    ' If committing a transaction fails or is canceled by the end user,
                    ' the resulting status would be RolledBack instead of Committed.
                    If TransactionStatus.Committed <> T.Commit() Then
                        TaskDialog.Show("Failure", "Transaction could not be committed")
                    End If
                Else
                    T.RollBack()
                End If

            End If
        End Using

        Return Autodesk.Revit.UI.Result.Succeeded
    End Function

Here's the code in text 😅

Message 3 of 7
sragan
in reply to: Anonymous

I don't see a t.start();  line, although its really hard to tell what is going on when we can only see a few lines of your code.

 

And what does it say if you hit the "details" button on that error message.

Message 4 of 7
sragan
in reply to: Anonymous

OK, you posted more code while I was posting.


You need a t.start() and a t.commit () line.

 

Message 5 of 7
Anonymous
in reply to: sragan

I can expand some fields if needed

Message 6 of 7
RPTHOMAS108
in reply to: Anonymous

That is an odd way of doing things to be honest i.e. to do something and then ask the user via task dialogue if they want to commit the transaction or not.

 

Would be better to move the user interaction i.e. taskdialog lines out of the transaction. When a task dialogue is showing the document status changes, perhaps.

 

Also what is your transaction mode attribute set to?

Message 7 of 7
Anonymous
in reply to: Anonymous

I solved it, I had ommited the access modifier statements just above the class declaration. It was set to <Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.ReadOnly)> when i needed

<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)>. Oops. Thank you all for your time and effort.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report