Getting the shape of a FamilyInstance object

Getting the shape of a FamilyInstance object

Anonymous
Not applicable
1,397 Views
1 Reply
Message 1 of 2

Getting the shape of a FamilyInstance object

Anonymous
Not applicable

I want to get the shape of a FamilyInstance object (for different instances).

Preferably, I would like to get the Solid object that describes it and then traverse its faces.

 

I'm not sure what is the easy way to do that (before looking into corner-cases).

 

I thought of checking its `HasModifiedGeometry()`, if it returns False, to do that:

 

foreach (GeometryObject geomObj in familyInstance.get_Geometry(opt))
{
    if (geomObj is Solid geomSolid)
    {
        // GOOD
    }
    else
    {
        // Should I do anything here?
    }
}

And if it returns False - to do the same for the FamilySymbol (familyInstance.Symbol):

foreach (GeometryObject geomObj in familyInstance.Symbol.get_Geometry(opt))
{
    if (geomObj is Solid geomSolid)
    {
        // GOOD
    }
    else
    {
        // Should I do anything here?
    }
}

But in this case, I should probably add the `familyInstance.Location`?

 

Is it correct?

Is it even the idea to follow with, or should I do something completely different

 

0 Likes
Accepted solutions (1)
1,398 Views
1 Reply
Reply (1)
Message 2 of 2

buihaviet
Participant
Participant
Accepted solution

Hi,

You can use this method in SDK examples to extract the solids of Element:

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;
        }

Cheer,

Viet.