Message 1 of 2
Problem with transaction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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;
}
}
}
}