Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Revit .NET: Try to Copy Elements from an Opened Project to Another

$
0
0

It may not be uncommon at all to merge two Revit projects (.RVT files) but we haven’t seen any code addressing it. In the previous post, we tried to merge a side Revit document opened into memory through the Application.OpenDocumentFile call into the current opened Revit document but got an exception saying “Some of the elements cannot be copied, because they are view-specific”.

In this post, let’s try on two opened projects in Revit then in case the problem was with the in-memory document only. Here we go:

if( CachedApp.Documents.Size >= 2 )
{
    List<Document> docs = (from Document doc in CachedApp.Documents select doc).ToList();
    using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(docs[0], "MergeProjects2"))
    {
        trans.Start();

        FilteredElementCollector finalCollector = new FilteredElementCollector(docs[1]);
        ElementIsElementTypeFilter filter1 = new ElementIsElementTypeFilter(false);
        finalCollector.WherePasses(filter1);
        ElementIsElementTypeFilter filter2 = new ElementIsElementTypeFilter(true);
        finalCollector.UnionWith((new FilteredElementCollector(docs[1])).WherePasses(filter2));
        ICollection<ElementId> ids = finalCollector.ToElementIds();

        CopyPasteOptions cpOpts = new CopyPasteOptions();
        ElementTransformUtils.CopyElements(docs[1], ids, docs[0], Autodesk.Revit.DB.Transform.Identity, cpOpts);

        trans.Commit();
    }
}

However, the same exception came up:
“Autodesk.Revit.Exceptions.ArgumentException: Some of the elements cannot be copied, because they are view-specific.
Parameter name: elementsToCopy
   at Autodesk.Revit.DB.ElementTransformUtils.CopyElements(Document sourceDocument, ICollection`1 elementsToCopy, Document destinationDocument, Transform transform, CopyPasteOptions options)
   at …”

So, the Autodesk.Revit.DB.ElementTransformUtils.CopyElements() method simply rejected to copy some so called ‘view-specific’ elements no matter whether in an opened and visible project or in a loaded in-memory document and aborted the whole operation. Since a useful Revit project definitely contains view-specific elements, the simple task of merging Revit projects cannot be done due to this severe limitation. It is frustrating!

Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.


Viewing all articles
Browse latest Browse all 872

Trending Articles