Transaction Problem, Linked Document.

Transaction Problem, Linked Document.

Anonymous
Not applicable
2,476 Views
5 Replies
Message 1 of 6

Transaction Problem, Linked Document.

Anonymous
Not applicable

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

 

0 Likes
Accepted solutions (1)
2,477 Views
5 Replies
Replies (5)
Message 2 of 6

OR_AND_NO
Advocate
Advocate

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());

0 Likes
Message 3 of 6

jeremytammik
Autodesk
Autodesk
Accepted solution

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
Alumni
Alumni

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
Advocate
Advocate

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

0 Likes
Message 6 of 6

jeremytammik
Autodesk
Autodesk

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

0 Likes