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: 

Transaction Problem, Linked Document.

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
JackTilley
1828 Views, 5 Replies

Transaction Problem, Linked Document.

Hi,

 

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

  

      Capture.PNG

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(... ,...);
t.Commit();
} }

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

 

5 REPLIES 5
Message 2 of 6
OR_AND_NO
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
jeremytammik
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.

 

Cheers,

 

Jeremy



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

Message 4 of 6
arnostlobel
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
OR_AND_NO
in reply to: jeremytammik

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

Message 6 of 6
jeremytammik
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:

 

http://thebuildingcoder.typepad.com/blog/2015/09/geometry-basics-and-no-modifying-linked-files.html#...

 

Cheers,

 

Jeremy



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