Message 1 of 17
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to copy elements (FamilyInstance) from linked document to the host one (Exact at the same place).
First of all, I was able to copy them manually with pasting from the clipboard. The following option worked for me as expected.
But the following snippet of code does not work as expected:
// Standard plugin staff including defining currrentDoc and Execute method
IEnumerable<RevitLinkInstance> linkInstances = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance)).Cast<RevitLinkInstance>();
Document linkedDoc = null;
Transform transform = null;
foreach (RevitLinkInstance inst in linkInstances)
{
if (inst.Name.Contains(nameLink))
{
linkedDoc = inst.GetLinkDocument();
transform = inst.GetTransform();
}
}
// other staff including checking linkedDoc and transform for null values...
Reference selectedElement = uidoc.Selection.PickObject(ObjectType.LinkedElement, "Choose Family from the linked file");
ElementId linkedElementId = selectedElement.LinkedElementId;
FamilyInstance famInst = linkedDoc.GetElement(linkedElementId) as FamilyInstance;
View linkedView = new FilteredElementCollector(linkedDoc).OfClass(typeof(View)).Where(view => view.Name == viewName && linkedDoc.GetElement(view.GetTypeId()).Name == viewFamilyName).Cast<View>().First();
ISet<ElementId> ids = new FilteredElementCollector(linkedDoc, linkedView.Id).OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>().Where(x => x.Symbol.Family.Id == famInst.Symbol.Family.Id).Select(x => x.Id).ToHashSet();
Transaction tx = new Transaction(doc);
tx.Start("copyFamily");
ElementTransformUtils.CopyElements(linkedDoc, ids, currrentDoc, transform, new CopyPasteOptions());
tx.Commit();
I get the following warning:
I have also tried view-specific form of the CopyElements method but the result was the same. I would highly appreciate any ideas of such behavior as well as any advice of using another methods for my purpose.
Solved! Go to Solution.