Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Transaction Problem, Linked Document.

Message 1 of 6
1828 Views, 5 Replies

Transaction Problem, Linked Document.



My code is written to create a space inside a linked element. This is an error I get when using the NewSpace() method.



I call the method inside a Transaction in the main document and It does nothing to the error. 


UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

foreach (Document d in app.Documents)
using (Transaction t = new Transaction(doc, "New Space")) { t.Start(); Autodesk.Revit.Creation.Document docu = d.Create; Space sp = docu.NewSpace(... ,...);
} }

Could this error be due to that I am calling NewSpace() in the Linked element but the Transaction is in the primary document?.

Revit does not seem to allow me use transactions in anything but the primary document.


If anyone has any suggestions of how I might be able to edit the linked element successful I would be very appreciative.


Thanks, Jack


Message 2 of 6
in reply to: JackTilley

May be my short example helps You

 "Creating a space in first linked file"               

ElementClassFilter filter = new ElementClassFilter(typeof(RevitLinkInstance));

FilteredElementCollector collector = new FilteredElementCollector(doc);

ICollection<Element> allLinks = collector.WherePasses(filter).ToElements();


doc_link=(allLinks.First<Element>() as RevitLinkInstance).GetLinkDocument();

Space sp = doc_link.Create.NewSpace(new Phase());

Message 3 of 6
in reply to: JackTilley

Dear Jack,


Yes, absolutely, a transaction is totally tied to a document.


If you have two separate documents to modify, you need two separate transactions for them.


If your subtransaction is in a different document B, it cannot be nested into a transaction tied to document A.





Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 6
in reply to: jeremytammik

It is correct what Jeremy stated: that to modify a document one needs to open a transaction in that document.

However, what is even more applicable in this particular case is the fact that linked documents are not modifiable - they cannot have transactions. In order to modify a linked document, one would have to close the link, open the document as a separate main document, make the changes there, save it, and link it again in the original host.

Arnošt Löbel
Message 5 of 6
in reply to: jeremytammik

You are right, but my example not. I am sorry.

Message 6 of 6
in reply to: arnostlobel

Dear Arnošt,


Thank you very much for the real answer!


I published a summary of these explanations on The Building Coder:





Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

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

Post to forums  

Autodesk DevCon in Munich May 28-29th

Rail Community