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: 

ElementTransformUtils.CopyElements (from linked document)

10 REPLIES 10
Reply
Message 1 of 11
HD12310
5226 Views, 10 Replies

ElementTransformUtils.CopyElements (from linked document)

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 🙂

 

 

10 REPLIES 10
Message 2 of 11
jeremytammik
in reply to: HD12310

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 11
Revitalizer
in reply to: HD12310

 



Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 11
arnostlobel
in reply to: Revitalizer

HD12310:

It is probably not entirely obvious from the documentation, but the Copy method that takes views as arguments only work for copying of view-specific elements. And, indirectly, since 3D views - which is what I assume you are copying between - cannot even have view-specific elements, they can never be used in that particular Copy method. That is why you see the error you got even before Revit went on testing whether the elements themselves were view-specific or not.

The work-around is simple: Use the Copy method that takes two documents instead. That should work.

Cheers
Arnošt Löbel
Message 5 of 11
HD12310
in reply to: arnostlobel

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;

}

}

 

}

}

 

 

 

 

 

Message 6 of 11
jeremytammik
in reply to: HD12310

 

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:

 

http://thebuildingcoder.typepad.com/blog/2015/05/copyelements-revit-2016-scalability-python-and-ruby...

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 11

Hi,

 

i am beginner to revit api programing if you dont mind can u explain the steps to right the program.

 

Regards

vinay

Message 8 of 11

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 11

@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!

Message 10 of 11

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.

Tags (1)
Message 11 of 11
Sean_Page
in reply to: havard.leding

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.

 

https://forums.autodesk.com/t5/revit-api-forum/elementtransformutils-copy-legend-from-linked-documen...

 

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

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community