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: 

A transaction or sub-transaction was opened but not closed

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
rinacimareller
1457 Views, 2 Replies

A transaction or sub-transaction was opened but not closed

Hi, this is my first post in the forum, so if i do something wrong, just tell me please.

 

I started studying Revit  API  and i trying to do a simple AddIn, just copy a element to a location that i select.

I wrote the code but when i try to run in Revit i get a error message.this is the first messagethis is the first messageWhen i click on "Fechar" i get thisWhen i click on "Fechar" i get this

can someone help me please? 

this is the code i get:

 

namespace Lab1PlaceGroup
{
     [Transaction(TransactionMode.Manual)]
     [Regeneration(RegenerationOption.Manual)]
     public class Class1 : IExternalCommand
     {
          public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
          {
               //Get application and document objects
               UIApplication uiapp = commandData.Application;
               Document doc = uiapp.ActiveUIDocument.Document;

               

               //Define a reference Object to accept the pick result
               Reference pickedref = null;

 

               //Pick a group
               Selection sel = uiapp.ActiveUIDocument.Selection;
               pickedref = sel.PickObject(ObjectType.Element, "Please select a group");
               Element elem = doc.GetElement(pickedref);
               Group group = elem as Group;

 

               //Pick point
               XYZ point = sel.PickPoint("Please pick a point to place group");

 

               //Place the group
               Transaction trans = new Transaction(doc);
               trans.Start("JoinGeo");
               doc.Create.PlaceGroup(point, group.GroupType);
               trans.Commit();

 

               return Result.Succeeded;
          }
     }
}

 

I get this code on a tutorial from autodesk.

2 REPLIES 2
Message 2 of 3
1240904365
in reply to: rinacimareller

The element you select is not a group .

Message 3 of 3
fdkuenneke
in reply to: rinacimareller

As far as I am aware, proper Transaction syntax is as follows:

 

using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Your Transaction Name");
                //Do your stuff!
                tx.Commit();
            }

 

 

This is due to the fact that Transactions expect to be disposed (In this case, being disposed by the convenient Idisposible interface as an object). Let me know how this works for you.

I'd say Revit was a chisel if it wasn't used as a hammer.

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

Post to forums  

Autodesk Design & Make Report