Hi all
Thanks for replies.
I finally found my mistake...finally at 00:25 🙂
I read somewhere that you needed to supply the FamilySymbolIds.
Which is what i did, so i got the familytypes not the instances.
(Cool enough since Transfer Project Standards doesnt transfer familys.)
But then i realized you probably get what you ask for here.
So i supplied the element ids of the linked familyinstances and voila, they pasted right in:-)
It even works on workplanebase familys, havent tried facebased yet.
For anyone interrested here's the code:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
namespace TransferFamilys
{
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class CopyPasteFamilys : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
Document hostDoc = commandData.Application.ActiveUIDocument.Document;
//Get the link
FilteredElementCollector links =
new FilteredElementCollector(hostDoc)
.OfClass(typeof(RevitLinkInstance));
Document linkedDoc = links.Cast<RevitLinkInstance>().FirstOrDefault().GetLinkDocument();
//Get familys in link
FilteredElementCollector linkedFamCollector = new FilteredElementCollector(linkedDoc);
ICollection<ElementId> ids = linkedFamCollector
.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_GenericModel)
.ToElementIds();
if (ids.Count == 0)
{
TaskDialog.Show("Copy Paste", "The link does not contain the specified elements.");
}
else
{
Transaction targetTrans = new Transaction(hostDoc);
CopyPasteOptions copyOptions = new CopyPasteOptions();
copyOptions.SetDuplicateTypeNamesHandler(new CopyUseDestination());
targetTrans.Start("Copy and paste linked familys");
ElementTransformUtils.CopyElements(linkedDoc, ids, hostDoc, null, copyOptions);
hostDoc.Regenerate();
targetTrans.Commit();
}
return Result.Succeeded;
}
public class CopyUseDestination : IDuplicateTypeNamesHandler
{
public DuplicateTypeAction OnDuplicateTypeNamesFound(
DuplicateTypeNamesHandlerArgs args)
{
return DuplicateTypeAction.UseDestinationTypes;
}
}
}
}