Trying to copy paste linked elements into the active document.
This is something that Revit can do manually.
Select a linked element, then ctrl + c and ctrl + v.
But I guess there is an API reason why this wont work:
ElementTransformUtils.CopyElements(view3DInLink, ids, view3DInHost, null, new CopyPasteOptions());
Errors out on "The specified view cannot be used as a source or destination for copying elements between two views."
(Which i presume is the linked view.)
I does work if you just want to copy the Familys from the link (without placing them) like this:
ElementTransformUtils.CopyElements(linkedDoc, ids, thisDoc, null, new CopyPasteOptions());
Is there any other method that will copy/paste linked elements, or should this work ?
If not then Create.NewFamilyInstance is probably the only option here 🙂
afaik it should work.
maybe it will help if you do it in several separate steps, e.g. first some supporting elements, like styles, etc., then the instances?
cheers,
jeremy
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;
}
}
}
}
Dear HD12310,
Thank you very much for the update and solution!
I am very glad you got it solved.
I made a note of this quite a while ago, both Arnošt's important hint above and your observations, and now finally got around to publishing them to enhance readability and ensure they don't get lost:
Cheers,
Jeremy
Hi,
i am beginner to revit api programing if you dont mind can u explain the steps to right the program.
Regards
vinay
Dear Vinay,
If you are a beginner, I would recommend that you work through the Revit API getting started material first of all, starting with the DevTV and My First Revit Plugin video tutorials:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#2
That will save both you and all the rest of us a lot of time and effort in the long run.
Have fun!
Best regards,
Jeremy
@jeremytammik , @HD12310 @vinaykrishnapoojary @arnostlobel @Revitalizer Can this method, or any others, work for copying model views from a linked file? Looking to copy a sheet with all views from a linked architectural model to quickly make sheets with "blank" views on them in an MEP model that match architectural package. The main purpose for this task is to get the crop areas and view positions to match throughout the entire drawing package the vast they can. Thanks!
This is something ElementTransformUtils cannot do unfortunately. (As the Revit UI cant)
You can get the crop region from a view in a linked file like this:
ViewCropRegionShapeManager managerFromView = viewInLink.GetCropRegionShapeManager();
IList<CurveLoop> cropBoundary = managerFromView .GetCropShape();
and then apply that crop boundary in the host project like this:
viewInHost.GetCropRegionShapeManager().SetCropShape(cropBoundary.First());
But you need some logic or UI to determine which cropBoundary(view) in the link,
should be applied to which view in the host.
Or for each applicable view in the link create a view in the host.
Perhaps copy the linked Levels first using ElementTransformUtils if they dont exist.
And then you can think about placing them on sheets.
This is something that can be done, and it is done by using the "ExtentElem" element within the view. I posted a solution to this on the Dynamo forums but it is based on the observations of another post about copying Legends.
Not sure if it a "hack" or not, but if you grab just the ExtentElem out of all the ements and use the CopyElements (fromview,elemIds,toview,transform,options) then it creates a new view rather than trying to paste it into the designated view.
https://forum.dynamobim.com/t/transfer-project-standards/44975/14?u=seanp