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.
Solved! Go to Solution.
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.
Solved! Go to Solution.
Solved by naveen.kumar.t. Go to 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();
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();
Can't find what you're looking for? Ask the community or share your knowledge.