Hi,
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(... ,...);
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
Solved! Go to Solution.
Hi,
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(... ,...);
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
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
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());
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());
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
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
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.
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.
You are right, but my example not. I am sorry.
You are right, but my example not. I am sorry.
Dear Arnošt,
Thank you very much for the real answer!
I published a summary of these explanations on The Building Coder:
Cheers,
Jeremy
Dear Arnošt,
Thank you very much for the real answer!
I published a summary of these explanations on The Building Coder:
Cheers,
Jeremy
Can't find what you're looking for? Ask the community or share your knowledge.