Getting hold of the surfaces and faces of a solid object

Top  Previous  Next

You can start with an occurrence, then drill down to the data you are interested in:

 

1.Start with an occurrence.
2.Get the surface body(ies) of the occurrence. There should only ever be 1
3.Get the list of shells from the (single) surface body.
4.For every shell in the list get the Faces.
5.For every Face you can find out what it is.

 

Here are the sort of surfaces that you can find:

 

kCylinderSurface

kPlaneSurface

kConeSurface

kSphereSurface

kTorusSurface

kBSplineSurface

 

In the end a cylinder is composed of a single shell which is composed of two plane surfaces and a cylindrical surface.

 

And here is a code fragment illustrating the process:

 

// Get the surface bodies from the occurrence...

CComPtr<SurfaceBodies> pSurfaceBodies;

hr = pOcc1->get_SurfaceBodies(&pSurfaceBodies);

 

TRACE (L"Occurrence 1 has %d surface bodies\n",pSurfaceBodies->Count);

 

// Get the first surface body from the component definition.

// (There should only ever be one surface body.)

CComPtr<SurfaceBody> pBody;

hr = pSurfaceBodies->get_Item(1, &pBody);

 

// Get the shells from the body.

CComPtr<FaceShells> pShells;

hr = pBody->get_FaceShells(&pShells);

 

TRACE ("The surface body has has %d shells\n",pShells->Count) ;

 

// Enumerate through the shells.

long shellCount = 1;

CComPtr<FaceShell> pShell;

for (;(hr = pShells->get_Item(shellCount, &pShell)) == S_OK; pShell.Release())

{

    TRACE (L"  Shell %d\n", shellCount);

 

    // Increment the counter and print the current value.

    ++shellCount;

 

    // Get the faces from the shell.

    CComPtr<Faces> pFaces;

    hr = pShell->get_Faces(&pFaces);

 

    // Enumerate through the faces of the current shell.

    long faceCount = 1;

    CComPtr<Face> pFace;

    for (;(hr = pFaces->get_Item(faceCount, &pFace)) == S_OK;pFace.Release())

    {

        // Increment the counter and print the current value.

        ++faceCount;

        TRACE (L"    Face %d ", faceCount);

 

        // Get the geometry from the face.

        SurfaceTypeEnum surfaceType;

        hr = pFace->get_SurfaceType(&surfaceType);

 

        switch (surfaceType) {

            default :

                TRACE (L"    Unrecognised surface type:%d\n",surfaceType);

                break ;

 

            case kCylinderSurface :

                TRACE (L"    Cylindrical surface\n");

                break ;

 

            case kPlaneSurface :

                TRACE (L"    Plane surface\n");

                break ;

        }

    }

}

 

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)