Transaction from an external application outside API not allowed

Transaction from an external application outside API not allowed

lrsmns
Enthusiast Enthusiast
780 Views
2 Replies
Message 1 of 3

Transaction from an external application outside API not allowed

lrsmns
Enthusiast
Enthusiast

Hi i'm trying to place a family from a plug in i created; however, i'm getting a warning saying "Placement is not permitted in an already modifiable document. The active transaction must be closed first". Then as i continue further, it's returning "Starting a transaction from external application running outside of the API is not allowed"

 

Screenshot 2024-05-13 084914.png

 

Screenshot 2024-05-13 084149.png

 

 

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.ObjectModel;
using System.Linq;
using System.Collections.Generic;


namespace Plugin.Revit
{
    public class FamilyLibraryModel
    {
        public UIApplication uiapp {  get; }
        public Document doc { get; }
        public UIDocument uidoc { get; }

        public FamilyLibraryModel(UIApplication uiApp)
        {
            uiapp = uiApp; 
            doc = uiApp.ActiveUIDocument.Document;
            uidoc = uiApp.ActiveUIDocument;
        }

       public void Place(IEnumerable<RevitFamilyWrapper> selected)
        {
            
            var selectedFamilySymbol = selected.Select(x=>x.familySymbol).First();
            using (var trans = new Transaction((doc), "Place Family"))
            {
                trans.Start();
                uidoc.PromptForFamilyInstancePlacement(selectedFamilySymbol);
                trans.Commit();
            }
        }      
    }
}

 

i'm not quite sure where i'm doing wrong, would appreciate any insights!

0 Likes
Accepted solutions (1)
781 Views
2 Replies
Replies (2)
Message 2 of 3

Moustafa_K
Collaborator
Collaborator
Accepted solution

the function PromptForFamilyInstancePlacement has its own transaction. you should not use it when any transaction is open.

just remove trans.Start and commit, and should work for you.

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 3 of 3

jeremy_tammik
Alumni
Alumni

Just looking at yur code snippet, it looks to me as if you have not implemented an external command or subscribed to any Revit events whatsoever. In that case, you will never have a valid Revit API context, and never be able to successfully execute any Revit API calls at all. Please work thorough the getting started material to see how to set up an external command and understand other basic aspects of the Revit API before doing anything else:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#2

  

Maybe I am mistaken, not seeing the rest of your code...

  

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