Create "solid" and find all elements within

Create "solid" and find all elements within

Anonymous
Not applicable
2,525 Views
2 Replies
Message 1 of 3

Create "solid" and find all elements within

Anonymous
Not applicable

Hey everyone,

 

I've been searching for a while, but struggle to find an approach to the solution. I try to create a 3-dimensional "solid" (sorry for the bad english) and find all elements that are inside. That solid should best be assembled from faces. How would I do that with the API?

 

Until now I searched in the SDK Samples and here, but I don't even know if I'm searching in the right direction. I'd really appreciate any hints where to start. Might it be necessary to create a family for such a "control solid"? If yes, I'd also appreciate every hint here!

 

Regards

0 Likes
2,526 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Hey again,

I'm still on the topic and just wanted to post my progress:
I managed to create a new family via GUI that is based on the template "Metric Generic Model face based.rft" that looks close to what I want to create with the API. I then inserted it (also via GUI) into the Revit Architecture Sample Project and now try to find out which elements are intersecting. While that is obvious in the 3D-view, it's again not so easy to get with the API. I tried this and the results were as expected, but since I don't need the intersection with the bounding box but with the geometry that was not useful for me. I then found this and copy-pasted from the Revit API help file to use the "ElementIntersectsElementFilter" and the "ElementIntersectsSolidFilter" classes. Unfortunately the results aren't as expected and now I think about "creating a solid from scratch using the routines in GeometryCreationUtilities" like the help file suggests.

I would still appreciate any help since I'm really not very experienced with the Revit API and expect that there has to be an easier way to achieve all this!?

Regards
0 Likes
Message 3 of 3

Mustafa.Salaheldin
Collaborator
Collaborator

Don't panic this is pretty simple to get Faces from a Solid of a geometry, try the following code:

 

#region Namespaces

using System;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;

using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;

using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;

#endregion

namespace RevitAddinCS1
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class GeometryManager : IExternalCommand
    {
        #region Cached Variables

        private static ExternalCommandData _cachedCmdData;

        public static UIApplication CachedUiApp
        {
            get
            {
                return _cachedCmdData.Application;
            }
        }

        public static RvtApplication CachedApp
        {
            get
            {
                return CachedUiApp.Application;
            }
        }

        public static RvtDocument CachedDoc
        {
            get
            {
                return CachedUiApp.ActiveUIDocument.Document;
            }
        }

        #endregion

        #region IExternalCommand Members

        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
        {
            _cachedCmdData = cmdData;

            try
            {
                Reference reference = CachedUiApp.ActiveUIDocument.Selection.PickObject(ObjectType.Element);

                Element element = CachedDoc.GetElement(reference);

                Options geoOptions = new Options();

                // Get geometry element of the selected element
                GeometryElement geoElement = element.get_Geometry(geoOptions);

                // Get geometry object
                foreach (GeometryObject geoObject in geoElement)
                {
                    // Get the geometry instance which contains the geometry information
                    Autodesk.Revit.DB.GeometryInstance instance = geoObject as Autodesk.Revit.DB.GeometryInstance;

                    if (null != instance)
                    {
                        foreach (GeometryObject instObj in instance.SymbolGeometry)
                        {
                            Solid solid = instObj as Solid;

                            if (null == solid || 0 == solid.Faces.Size || 0 == solid.Edges.Size)
                            {
                                continue;
                            }

                            if (solid.Faces.Size > 0)
                            {
                                // Get the faces and edges from solid, and transform the formed points
                                foreach (Face face in solid.Faces)
                                {
                                    TaskDialog.Show("Revit", face.Area.ToString());
                                }
                            }
                        }
                    }
                }


                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                return Result.Failed;
            }
        }

        #endregion
    }
}

Just select the element and the code will show you how to retrieve the solid and its faces showing up a dialog with each face's area. You can of course replace the PickObject function with a filter or you can create a function where you can pass the element from which the faces will be extracted as a parameter.

 

Don't forget to mark this reply as an answer if it satisfies your need.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn