Problem with transaction

Problem with transaction

cugelkater
Explorer Explorer
262 Views
1 Reply
Message 1 of 2

Problem with transaction

cugelkater
Explorer
Explorer

When Im run this script there is error:

 

"No transaction attribute.

Could not run the add-in because it does not have the Transaction attribute assigned." 

 

What is missing here? Maybe it is related to the .addin file?

 

using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

namespace lib1
{
    public class SelPW_save
    {
        public static ICollection<ElementId> SavedElementIds { get; set; } = new List<ElementId>();
    }

    [Transaction(TransactionMode.Manual)]
    public class SelPWget1 : IExternalCommand

    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {

            UIDocument uiDoc = commandData.Application.ActiveUIDocument;
            Document doc = uiDoc.Document;

            // Transaction begin

            using (Transaction trans = new Transaction(doc, "trans"))
            {
                trans.Start();

                try
                {
                    
                    ICollection<ElementId> selectedIds = uiDoc.Selection.GetElementIds();
                    if (selectedIds.Count == 0)
                    {
                        TaskDialog.Show("Info", "No elements has been choosen");
                        return Result.Succeeded;
                    }

                    
                    SelPW_save.SavedElementIds = selectedIds;

                    
                    string idList = "Element IDs:\n";
                    foreach (ElementId id in selectedIds)
                    {
                        idList += id.IntegerValue + "\n";
                    }

                    
                    TaskDialog.Show("Result", idList);
                    return Result.Succeeded;
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.RollBack();
                    TaskDialog.Show("error", ex.Message);
                    return Result.Failed;
                }
                return Result.Succeeded;
            }
        }
    }
}

 

0 Likes
263 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

Hard to tell without seeing the add-in manifest file. It needs to specify your full class name, lib1.SelPWget1. Just follow the instructions in the add-in integration guide and all will be well:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes