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: 

Copying Linked Elements

1 REPLY 1
SOLVED
Reply
Message 1 of 2
jmyr
272 Views, 1 Reply

Copying Linked Elements

jmyr
Enthusiast
Enthusiast

Hi All,

 

I'm trying to copy from linked document with the following code, but unfortunately it's creating multiple element types. Ay idea what's happening?

 FilteredElementCollector links = new FilteredElementCollector(doc)
                    .OfClass(typeof(RevitLinkInstance));

                Document linkedDoc = links.Cast<RevitLinkInstance>().FirstOrDefault().GetLinkDocument();

                RevitLinkInstance revitLinkInstance = links.Cast<RevitLinkInstance>().FirstOrDefault();

                ElementFilter elementFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipeCurves);
                ICollection<ElementId> ids = new FilteredElementCollector(linkedDoc).WherePasses(elementFilter).ToElementIds();



                CopyPasteOptions copyOptions = new CopyPasteOptions();
                copyOptions.SetDuplicateTypeNamesHandler(new copyHandler());

                if (ids.Count == 0)
                {
                    TaskDialog.Show("Copy Paste", "The link does not contain the specified elements.");
                }
                else
                {
                    Transaction targetTrans = new Transaction(doc);


                    targetTrans.Start("Copy and paste linked elements");

                    Transform transform = revitLinkInstance.GetTotalTransform();

                    IList<ElementId> copiedElements = ElementTransformUtils.CopyElements(linkedDoc, ids, doc, transform, copyOptions).ToList();


                    targetTrans.Commit();
                }
            }
        }
        public class copyHandler : IDuplicateTypeNamesHandler
        {
            public DuplicateTypeAction OnDuplicateTypeNamesFound(DuplicateTypeNamesHandlerArgs args)
            {
                return DuplicateTypeAction.UseDestinationTypes;
            }
        }

 

Thank you.

 

 

0 Likes

Copying Linked Elements

Hi All,

 

I'm trying to copy from linked document with the following code, but unfortunately it's creating multiple element types. Ay idea what's happening?

 FilteredElementCollector links = new FilteredElementCollector(doc)
                    .OfClass(typeof(RevitLinkInstance));

                Document linkedDoc = links.Cast<RevitLinkInstance>().FirstOrDefault().GetLinkDocument();

                RevitLinkInstance revitLinkInstance = links.Cast<RevitLinkInstance>().FirstOrDefault();

                ElementFilter elementFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipeCurves);
                ICollection<ElementId> ids = new FilteredElementCollector(linkedDoc).WherePasses(elementFilter).ToElementIds();



                CopyPasteOptions copyOptions = new CopyPasteOptions();
                copyOptions.SetDuplicateTypeNamesHandler(new copyHandler());

                if (ids.Count == 0)
                {
                    TaskDialog.Show("Copy Paste", "The link does not contain the specified elements.");
                }
                else
                {
                    Transaction targetTrans = new Transaction(doc);


                    targetTrans.Start("Copy and paste linked elements");

                    Transform transform = revitLinkInstance.GetTotalTransform();

                    IList<ElementId> copiedElements = ElementTransformUtils.CopyElements(linkedDoc, ids, doc, transform, copyOptions).ToList();


                    targetTrans.Commit();
                }
            }
        }
        public class copyHandler : IDuplicateTypeNamesHandler
        {
            public DuplicateTypeAction OnDuplicateTypeNamesFound(DuplicateTypeNamesHandlerArgs args)
            {
                return DuplicateTypeAction.UseDestinationTypes;
            }
        }

 

Thank you.

 

 

1 REPLY 1
Message 2 of 2
naveen.kumar.t
in reply to: jmyr

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @jmyr ,

 

Did you check what is inside this "Ids"?

 

ICollection<ElementId> ids = new FilteredElementCollector(linkedDoc).WherePasses(elementFilter).ToElementIds();

 

I think the code you used, gets the element types, not the elements. That's why you have multiple element types.

To get the elements present inside the linked document, please use the below code

 

 FilteredElementCollector collectoer = new FilteredElementCollector(linkedDoc).WherePasses(elementFilter).WhereElementIsNotElementType();

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

Hi @jmyr ,

 

Did you check what is inside this "Ids"?

 

ICollection<ElementId> ids = new FilteredElementCollector(linkedDoc).WherePasses(elementFilter).ToElementIds();

 

I think the code you used, gets the element types, not the elements. That's why you have multiple element types.

To get the elements present inside the linked document, please use the below code

 

 FilteredElementCollector collectoer = new FilteredElementCollector(linkedDoc).WherePasses(elementFilter).WhereElementIsNotElementType();

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report