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.
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.
Solved! Go to Solution.
Solved by 1240904365. Go to Solution.
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.
Can't find what you're looking for? Ask the community or share your knowledge.