Copying Columns From One Project to Another Error

Copying Columns From One Project to Another Error

dengebre
Contributor Contributor
913 Views
5 Replies
Message 1 of 6

Copying Columns From One Project to Another Error

dengebre
Contributor
Contributor

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;
            }
        }
    }
}
0 Likes
914 Views
5 Replies
Replies (5)
Message 2 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @dengebre ,

 

Please try copying the columns manually between projects without using API(In UI).

Let me know whether you are facing the same issue.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 6

Sean_Page
Collaborator
Collaborator

I don't recall exactly the issue I had with this before, but I believe it was related to the host levels of the columns being different than host levels in the other model. I think @naveen.kumar.t suggestion would be good for trying as well to see if you can get additional information.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 4 of 6

dengebre
Contributor
Contributor

The elements being copied from the source model into the blank destination model are grids, levels, columns, walls, floors and roofs, in that order. All elements copy over without error except the columns. If the problem is a levels-thing I don’t believe the floors and roof would copy either; instead, I suspect it is the way the columns are defined in the source model.

 

I copied all of the elements over, except the columns, using the routine. Then I tried to copy/paste the columns manually and only half of the columns copied. The error message was “Can’t place inserts outside of hosts. These elements won’t be copied”. As far as I can tell all of the columns are the same with the only difference being the base and top offsets. I have no idea what “inserts” the error is referring to.

0 Likes
Message 5 of 6

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @dengebre ,

 

As you are facing the same issue in Revit Product UI, It is better to find the solution to the problem manually first before using API.

Please be aware that the Revit API hardly ever supports any functionality that is not also available in the user interface.

So if you face a problem in UI, you will face the same problem in API also.

From the error message, I can say that the Your column is connected to the host so while copying the column to another project you have to copy the host also.

In UI, analyze your column and find out the host element of the column.

After finding out the host, copy columns along with their hosts to another project.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 6 of 6

dengebre
Contributor
Contributor

That is all understood. Since structural columns are level-based I assumed that the hosts are the levels, and that if the levels are successfully copied there should not be any host related issues. Upon further review, I found that the columns that were not copying were hosted by the floor and not the level (not quite sure how the author of the source model could even do that). All of the columns were re-defined using the appropriate level as the host, and the model was purged and saved. The columns could then be successfully copied manually, but I received the same error when trying to copy via the routine. Just to be sure, I tested using a different source model (all columns properly hosted by levels), and the columns could be copied manually but not by using the routine. Thank you very much for your help.

0 Likes