Beam intersect whit Column cut

Beam intersect whit Column cut

gustavosanmartin
Advocate Advocate
474 Views
4 Replies
Message 1 of 5

Beam intersect whit Column cut

gustavosanmartin
Advocate
Advocate

I am trying to create a separation or cut in a selected beam whose elements that intersect it will be columns and for this I am using the following code. The problem is that apparently the solid of the beam is not being obtained. Can someone guide me how to achieve this and how to generate the cut.

One idea would be to consider the following method SolidSolidCutUtils.AddCutBetweenSolids(doc, lastBeam, column);

 

            // Selecciona la viga.
            Reference beamRef = uidoc.Selection.PickObject(ObjectType.Element,new StructuralFramingSelectionFilter(),"Selecciona una viga");

            if (beamRef == null)
            {
                return Result.Cancelled;
            }

            ElementId beamId = beamRef.ElementId;
            Element beam = doc.GetElement(beamId);


            // Obtener la geometría de la viga
            GeometryElement geomElem = beam.get_Geometry(new Options());

            // Buscar la geometría sólida de la viga
            Solid beamSolid = null;
            foreach (GeometryObject geomObj in geomElem)
            {
                if (geomObj is Solid)
                {
                    beamSolid = geomObj as Solid;
                    break;
                }
            }

            // Verificar que se haya encontrado un sólido
            if (beamSolid != null)
            {
                // Hacer algo con el sólido de la viga, por ejemplo, obtener su volumen
                double beamVolume = beamSolid.Volume;
                TaskDialog.Show("Volumen de la viga", "El volumen de la viga seleccionada es " + beamVolume.ToString());
            }
            else
            {
                TaskDialog.Show("Error", "No se pudo encontrar un sólido para la viga seleccionada.");
            }


            // Obtiene los elementos que intersectan con la viga.
            BoundingBoxXYZ boundingBox = beam.get_BoundingBox(view);
            Outline outline = new Outline(boundingBox.Min, boundingBox.Max);
            BoundingBoxIntersectsFilter intersectsFilter = new BoundingBoxIntersectsFilter(outline);

            FilteredElementCollector collector = new FilteredElementCollector(doc, view.Id);
            IList<Element> intersectingElements = collector.WherePasses(intersectsFilter).WhereElementIsNotElementType().ToList();


            // Muestra los elementos intersectados en una ventana de diálogo.
            string messageBoxText = "Elementos intersectados:\n\n";
            foreach (Element intersectingElement in intersectingElements)
            {
                messageBoxText += intersectingElement.Id + "\n";
                //SolidSolidCutUtils.AddCutBetweenSolids(doc, beam, intersectingElement);
            }

            TaskDialog.Show("Intersección de elementos", messageBoxText);

 

0 Likes
475 Views
4 Replies
Replies (4)
Message 2 of 5

RPTHOMAS108
Mentor
Mentor

There are many examples of how to extract solids from elements.

 

If it is null then perhaps the solid does not exist at that level within the geometry, perhaps instead there is a GeometryInstance that contains the nested solids? What does RevitLookup tell you in that respect?

 

Generally there will be different geometry arrangement for those family instances that have been modified but cuts and those that haven't been.

 

Those geometry methods may not be suitable for your task depending on below:

 

ReviAPI.chm SolidSolidCutUtils class:

"These utilities are applicable for the generic forms, geometry combinations and family instances in conceptual model, pattern based curtain panel, or adaptive component families, and family instances which are permitted to participate in joining in projects. Thus, for example, a beam cannot cut a wall (as the wall is not a family instance) in projects. Nor can a steel beam participate in cutting another family (because steel beams do not participate in joining)."

 

 

Message 3 of 5

gustavosanmartin
Advocate
Advocate

I've tried another option and I can't get the solid of a selected beam either.

 

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Linq;

[Transaction(TransactionMode.Manual)]
public class GetBeamSolidCommand : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        // Obtener el documento activo y la selección del usuario
        UIDocument uidoc = commandData.Application.ActiveUIDocument;
        Document doc = uidoc.Document;

        // Obtener la referencia de la viga seleccionada
        Reference beamRef = uidoc.Selection.PickObject(ObjectType.Element, new StructuralFramingSelectionFilter(), "Selecciona una viga");
        ElementId beamId = beamRef.ElementId;

        // Obtener la viga seleccionada y su sólido
        FamilyInstance beam = doc.GetElement(beamId) as FamilyInstance;
        GeometryElement geometryElement = beam?.get_Geometry(new Options());
        Solid solid = null;

        if (geometryElement != null)
        {
            foreach (GeometryObject geomObj in geometryElement)
            {
                Solid solidObj = geomObj as Solid;
                if (solidObj != null && solidObj.Volume > 0)
                {
                    solid = solidObj;
                    break;
                }
            }
        }

        // Si no se pudo obtener el sólido de la viga seleccionada, mostrar un mensaje y salir
        if (solid == null)
        {
            TaskDialog.Show("Mensaje", "No se pudo obtener el sólido de la viga seleccionada.");
            return Result.Failed;
        }

        // Mostrar el volumen de la viga seleccionada
        double volume = solid.Volume;
        TaskDialog.Show("Mensaje", $"El volumen de la viga seleccionada es {volume} m^3.");

        return Result.Succeeded;
    }
}
0 Likes
Message 4 of 5

RPTHOMAS108
Mentor
Mentor

No you either have top level Solids or top level GeometryInstances nesting GeometryObjects such as solids via GeometryElement (which is a collection).

 

RPTHOMAS108_0-1681753155002.png

 

 

https://forums.autodesk.com/t5/revit-api-forum/getting-the-shape-of-a-familyinstance-object/m-p/8342...

Geometry Property (revitapidocs.com)

0 Likes
Message 5 of 5

gustavosanmartin
Advocate
Advocate

Thanks, that was the solution to obtain the solids of an element. Now could you guide me on how I can obtain the solid object to be able to use the method

SolidSolidCutUtils.AddCutBetweenSolids(doc, solids, intersectingElement);

 

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

[Transaction(TransactionMode.Manual)]
public class GetBeamSolidCommand : IExternalCommand
{
    #region
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        // Obtener el documento activo y la selección del usuario
        UIDocument uidoc = commandData.Application.ActiveUIDocument;
        Document doc = uidoc.Document;
        Autodesk.Revit.DB.View view = uidoc.ActiveView;

        // Obtener la referencia de la viga seleccionada
        Reference beamRef = uidoc.Selection.PickObject(ObjectType.Element, new StructuralFramingSelectionFilter(), "Selecciona una viga");
        ElementId beamId = beamRef.ElementId;

        // Obtener la viga seleccionada y su sólido
        FamilyInstance beam = doc.GetElement(beamId) as FamilyInstance;
        
        GetTargetSolids(beam);


        Solid finalSolid = GeometryCreationUtilities.CreateSolidFromGeometryObjects(new List<GeometryObject>());



        foreach (Solid s in GetTargetSolids(beam))
        {
            finalSolid = BooleanOperationsUtils.ExecuteBooleanOperation(finalSolid, s, BooleanOperationsType.Union);
        }



        // Obtiene los elementos que intersectan con la viga.
        BoundingBoxXYZ boundingBox = beam.get_BoundingBox(view);
        Outline outline = new Outline(boundingBox.Min, boundingBox.Max);
        BoundingBoxIntersectsFilter intersectsFilter = new BoundingBoxIntersectsFilter(outline);

        FilteredElementCollector collector = new FilteredElementCollector(doc, view.Id);
        IList<Element> intersectingElements = collector.WherePasses(intersectsFilter).WhereElementIsNotElementType().ToList();


        // Muestra los elementos intersectados en una ventana de diálogo.
        
        foreach (Element intersectingElement in intersectingElements)
        {
            
            SolidSolidCutUtils.AddCutBetweenSolids(doc, solids, intersectingElement);
        }



        return Result.Succeeded;
    }
    #endregion

    public static IList<Solid> GetTargetSolids(Element element)
    {
        List<Solid> solids = new List<Solid>();


        Options options = new Options();
        options.DetailLevel = ViewDetailLevel.Fine;
        GeometryElement geomElem = element.get_Geometry(options);
        foreach (GeometryObject geomObj in geomElem)
        {
            if (geomObj is Solid)
            {
                Solid solid = (Solid)geomObj;
                if (solid.Faces.Size > 0 && solid.Volume > 0.0)
                {
                    solids.Add(solid);
                }
                // Single-level recursive check of instances. If viable solids are more than
                // one level deep, this example ignores them.
            }
            else if (geomObj is GeometryInstance)
            {
                GeometryInstance geomInst = (GeometryInstance)geomObj;
                GeometryElement instGeomElem = geomInst.GetInstanceGeometry();
                foreach (GeometryObject instGeomObj in instGeomElem)
                {
                    if (instGeomObj is Solid)
                    {
                        Solid solid = (Solid)instGeomObj;
                        if (solid.Faces.Size > 0 && solid.Volume > 0.0)
                        {
                            solids.Add(solid);
                        }
                    }
                }
            }
        }
        return solids;
    }


}
0 Likes