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: 

Insert Column

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
gustavosanmartin
422 Views, 4 Replies

Insert Column

Hi, I'm starting C# programming and I'm trying to run this code to understand how it works. I'm interested in being able to insert columns. Can you help me understand why I can't run it. Thank you so much

 

#region Creando un pilar Metodo 2 ICollection BatchCreateColumns(Autodesk.Revit.DB.Document document, Level level) { List fiCreationDatas = new List(); ICollection elementSet = null; //Try to get a FamilySymbol FamilySymbol familySymbol = null; FilteredElementCollector collector = new FilteredElementCollector(document); 1ICollection collection = collector.OfClass(typeof(FamilySymbol)).ToElements(); foreach (Element e in collection) { familySymbol = e as FamilySymbol; if (null != familySymbol.Category) { if ("Structural Columns" == familySymbol.Category.Name) { break; } } } if (null != familySymbol) { //Create 10 FamilyInstanceCreationData items for batch creation for (int i = 1; i < 11; i++) { XYZ location = new XYZ(i * 10, 100, 0); FamilyInstanceCreationData fiCreationData = new FamilyInstanceCreationData(location, familySymbol, level, StructuralType.Column); if (null != fiCreationData) { fiCreationDatas.Add(fiCreationData); } } if (fiCreationDatas.Count > 0) { // Create Columns elementSet = document.Create.NewFamilyInstances2(fiCreationDatas); } else { throw new Exception("Batch creation failed."); } } else { throw new Exception("No column types found."); } return elementSet; } #endregion

4 REPLIES 4
Message 2 of 5

Welcome to the Revit API! Are you interested in history? Here is a lesson from 13 years ago:

  

https://thebuildingcoder.typepad.com/blog/2009/02/inserting-a-column.html

  

I'm afraid one or two things have changed since then.

  

Before addressing this programmatically, I hope you have tried it out manually in the end user interface to understand the basic BIM principles involved.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5

Thank you very much for your answer, I have looked at the code that you have provided me and I have been able to arrive at the following. The problem I have is that I can't insert a column and I don't know what the problem could be.

 

// Obtener el documento actual y la aplicación de Revit
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            // Seleccionar la ubicación de inserción del pilar
            //UIDocument uiDoc = new UIDocument(doc);


            // Pedir al usuario que seleccione un muro
            Reference wallRef = uidoc.Selection.PickObject(ObjectType.Element, new WallSelectionFilter(), "Selecciona un muro");

            // Obtener el muro seleccionado
            Wall wall = doc.GetElement(wallRef) as Wall;
            // Obtener el nivel correspondiente al nivelId de un elemento
            ElementId levelId = wall.LevelId;
            Level level = doc.GetElement(levelId) as Level;
            // Imprimir el nombre del nivel (si se encontró)
            if (level != null)
            {
                TaskDialog.Show("Nivel correspondiente", "El nivel correspondiente es: " + level.Name);
            }
            else
            {
                TaskDialog.Show("Nivel correspondiente", "No se pudo encontrar el nivel correspondiente.");
            }

            XYZ columnLocation = uidoc.Selection.PickPoint("Selecciona la ubicación del pilar");
            TaskDialog.Show("Revit", "Coordenadas del Pickpoint: " + columnLocation.ToString());

            string columnName = "Columnas";
            // Definimos el tipo de pilar que queremos insertar
            FilteredElementCollector columnCollector = new FilteredElementCollector(doc);
            ElementFilter columnFilter = new ElementClassFilter(typeof(FamilySymbol));
            ICollection<Element> columnTypes = columnCollector.WherePasses(columnFilter).ToElements();

            FamilySymbol columnSymbol = null;

            foreach (Element elem in columnTypes)
            {
                FamilySymbol sym = elem as FamilySymbol;
                if (sym != null && sym.Family.Name == columnName)
                {
                    columnSymbol = sym;
                    break;
                }
            }
            TaskDialog.Show("Revit", "columnSymbol: " + columnSymbol.Family.Name.ToString());

            doc.Create.NewFamilyInstance(columnLocation, columnSymbol, level, StructuralType.Column);

 

Message 4 of 5

You need to use transaction to make changes to a document.

Put your doc.Create.NewFamilyInstance under transaction.

using (Transaction columnInsertTransaction = new Transaction(doc))
{
if (columnInsertTransaction.Start("Insert Column") == TransactionStatus.Started)
{
doc.Create.NewFamilyInstance(columnLocation, columnSymbol, level, StructuralType.Column);

}
columnInsertTransaction.Commit();
}

 

Message 5 of 5

Thank you very much for your answer, I had solved it this way considering what you mention.

 

            string columnName = "Columnas 6x6";
            // Buscar el FamilySymbol correspondiente al tipo de familia de columna que deseas insertar
            FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol));
            FamilySymbol columnType = col.FirstOrDefault(e => e.Name.Equals(columnName)) as FamilySymbol;


            // Verificar que se encontró el FamilySymbol correspondiente
            if (columnType == null)
            {
                TaskDialog.Show("Error", "No se encontró el tipo de familia de columna especificado.");

            }


            // Obtener el punto de inserción de la columna mediante el objeto de selección del usuario
            XYZ insertionPoint = uidoc.Selection.PickPoint();

            // Crear una nueva instancia de la columna utilizando el tipo de familia de columna y el punto de inserción seleccionados
            Transaction transaction = new Transaction(doc, "Insertar columna");
            transaction.Start();
            FamilyInstance columnInstance = doc.Create.NewFamilyInstance(insertionPoint, columnType, doc.ActiveView.GenLevel, Autodesk.Revit.DB.Structure.StructuralType.Column);
            transaction.Commit();

            // Mostrar un mensaje de confirmación
            TaskDialog.Show("Columna insertada", "Se insertó una nueva columna en la vista activa.");
            #endregion

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

Post to forums  

Forma Design Contest


Rail Community