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: 

ElementTransformUtils Copy Legend from linked Document doesn't act as expected

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Sean_Page
1015 Views, 2 Replies

ElementTransformUtils Copy Legend from linked Document doesn't act as expected

I am working to copy a Legend from a linked Document to the Current Document, but when I copy the View, and then try to copy the elements, it is creating the Legend twice with an incremental number, and the second Legend (Legend1) contains the copied elements, but the first does not.

 

I then tried to use a Legend already in the current document and Copy the linked elements into it, but it creates a new Legend with the elements in it, but does nothing in the existing legend.

 

Here is the code I am using:

 

                if (new FilteredElementCollector(doc).OfClass(typeof(View)).Cast<View>().Where(x => x.ViewType == ViewType.Legend).FirstOrDefault() is View tempLegend)
                {
                    using (Transaction trans = new Transaction(doc))
                    {
                        trans.Start("Copy Legends");
                        foreach (ListViewItem item in lsvLegends.CheckedItems)
                        {
                            View view = (View)item.Tag;
                            ICollection<ElementId> elemIds = new FilteredElementCollector(linkDoc, view.Id).ToElementIds();
                            ElementTransformUtils.CopyElements(view, elemIds, tempLegend, Transform.Identity, options);
                            count++;
                        }
                        trans.Commit();
                    }
                    MessageBox.Show("Copied " + count + " Legends");
                    DialogResult = DialogResult.OK;
                    Close();
                }

The result of this should be the existing Legend (view) with the Copied elements in it from the Linked document.  The actual result is the existing Legend is untouched, and a new Legend with the Name of the linked Legend containing all of the elements in it.  Now, this is actually what I want, but doesn't work as it says it should.

2 REPLIES 2
Message 2 of 3
p.smithSTNZ
in reply to: Sean_Page

Hi spage,

 

I had this problem and what I found is that when I was running the FilteredElementCollector on the target legend view I am grabbing a view extent element which is creating a second view and adding the elements into that.

 

Try adding a selection filter to your elemIds collector where element.Name != "ExtentElem", this did the trick for me

 

Hope this helps

Message 3 of 3
Sean_Page
in reply to: p.smithSTNZ

Thanks @p.smithSTNZ, that is exactly what I found as well when I stepped through each element in the collector, but again I don't believe that is the expected result based on the documentation which is why I raised the question. Well actually as I am writing this it is working as intended, I just didn't expect the "view extents" to create another view.

 

As I note, this actually works very well because the other solution is a two step copy, but this way it only requires one CopyElements and if you use a local Legend and the Destination view there isn't any filtering nor clean up needed to rename or delete the duplicate view.

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