Message 1 of 6
Copying Columns From One Project to Another Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have created a routine that copies grids, levels, columns, walls, floors and roofs from one project to another. It works on all of the elements except the columns, which produces the error “Copying one or more elements failed”. There are columns in the source model but they will not copy. The code snippet below is for the column copying only. Any suggestions?
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
namespace MyRevitCommands
{
[TransactionAttribute(TransactionMode.Manual)]
public class CopyElements : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Variables
String filename = @"some file path";
//Copy OST_Columns From Source Model
//(this same code works for OST_Walls, OST_Roofs, OST_Floors, etc.)
Document doc1 = commandData.Application.Application.OpenDocumentFile(filename);
FilteredElementCollector collector3 = new FilteredElementCollector(doc1);
ElementCategoryFilter filter3 = new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns);
ICollection<ElementId> acolumns = collector3.WherePasses(filter3).ToElementIds();
TaskDialog.Show("Architectural Columns", string.Format("{0} columns found!", acolumns.Count)); //for my test project it confirmed that 69 columns were found
//Place Elements to Destination Model
UIDocument uidoc2 = commandData.Application.ActiveUIDocument;
Document doc2 = uidoc2.Document;
try
{
using (Transaction trans = new Transaction(doc2, "Copy Elements"))
{
trans.Start();
if (acolumns.Count > 0) {ICollection<ElementId> ids3 = ElementTransformUtils.CopyElements(doc1, acolumns, doc2, null, null);}
trans.Commit();
}
return Result.Succeeded;
}
catch (Exception err)
{
message = err.Message;
return Result.Failed;
}
}
}
}