Solid element is missing

Solid element is missing

Anonymous
Not applicable
1,767 Views
4 Replies
Message 1 of 5

Solid element is missing

Anonymous
Not applicable

Hi there, 

I am trying to get boundary of elements, in order to do that I have used this code 

 

        public static List<List<XYZ>> GetColumnsBoundaryPolygons(
            List<Element> columns,
            Options opt)
        {
            var polygons = new List<List<XYZ>>();
            foreach (var column in columns)
            {
                var geo = column.get_Geometry(opt);

                foreach (var obj in geo) // 2013
                {
                    var solid = obj as Solid;
                    if (solid != null) GetBoundary(polygons, solid);
                }
            }
            return polygons;
        }

which I got from Jeremytammik's example. 

"columns" is  a list of column_structural. 

Doing a debug I can see just some elements from "columns" can be used as solid. All elements are column_structural, just the type of columns is different one each other. Does someone know what the problem is? 

I need the edges of the element, is there another way to get it?

 

Regards

 

 

 

0 Likes
1,768 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Hello @Anonymous 

I did something similar where i wanted to find edges and faces for a element and what worked for me was.

Options opt=new Options();
var GE = element.get_Geometry(opt);
var geometryObject = GE as GeometryObject;
var solid = geometryObject as Solid;
var edgeIterator=solid .Edges.ForwardIterator();
0 Likes
Message 3 of 5

Anonymous
Not applicable

thanks @Anonymous  but my problem is that element does not have a solid. In my list, there are 223 element and just 4 of them have a solid. So I have just done this in order to solve 

 foreach (var column in columns)
            {
                var geo = column.get_Geometry(opt);

                foreach (var obj in geo)
                {
                    var solid = obj as Solid;
                    if (solid != null) GetBoundary(polygons, solid);
                }

                var gInst = geo.First() as GeometryInstance;

                foreach (var obj in gInst.GetInstanceGeometry()) 
                {
                    var solid = obj as Solid;
                    if (solid != null) GetBoundary(polygons, solid);
                }
            }

 but this does not look like a good solution.  

As far as I know every element should have a solid. Now I don´t know where the problem is, in the family, in the columns in how the architect did the building or in the api revit 

0 Likes
Message 4 of 5

BobbyC.Jones
Advocate
Advocate

Hello @Anonymous ,

This is how the Revit API was designed.  The second paragraph in the link below explains it well.

 

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-...

 

 

--
Bobby C. Jones
0 Likes
Message 5 of 5

jlpgy
Advocate
Advocate

Hi:

I have run into the similar issue recently.

Here is my solution:

  1. Try to get Solids in GeometryElement,
  2. If there is not any valid Solid (Volumn not zero, Edges not empty, Faces not empty), try to get GeometryInstance
  3. Traverse all solids inside GeometryInstance

 

        static Solid GetStructrualColumnSolid(FamilyInstance fiStruColumn)
        {
            if (fiStruColumn.GetBuiltInCategory() != BuiltInCategory.OST_StructuralColumns)
                throw new InvalidCategoryException(fiStruColumn.GetBuiltInCategory());

            if (TryGetGeometryElem(fiStruColumn, ViewDetailLevel.Fine, out var geoElem))
            {
                var toReturn = GetUnionSolid(geoElem);
                if (toReturn == null && TryGetGeometryInstance(fiStruColumn, out var geoInst))
                    return GetUnionSolid(geoInst.GetInstanceGeometry());
                else
                    return null;
            }
            else
                return null;
        }
       static Solid GetUnionSolid(GeometryElement geoElem)
        {
            geoElem.AssertNotNull(nameof(geoElem));
            Solid toReturn = null;
            foreach (var geoObj in geoElem)
            {
                if (geoObj is Solid sld && sld.Volume.IsPositive() && sld.Edges.Size > 0)
                    toReturn = toReturn.UnionSolid(sld);
            }
            return toReturn;
        }
    public static Solid UnionSolid(this Solid main, Solid other)
        {
            if (IsValid(main) && !IsValid(other))
                return main;
            else if (!IsValid(main) && IsValid(other))
                return other;
            else if (!IsValid(main) && !IsValid(other))
                return null;
            else
                return BooleanOperationsUtils.ExecuteBooleanOperation(main, other, BooleanOperationsType.Union);
        }

// Just igonre some Method names, they are quite easy to understand.

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
0 Likes