Selecting a face of 3D Solid and getting it Material

 Hello,
         For my application I need to select the face (sub entity) of a 3D Solid and extract material information from it. I have below code,which works fine in Teigha Viewer, i.e. I am able to select a Face and extract material information. But this code does not select sub entity (face) in BricsCAD.

[code]void DsFormBrepUtils::GetPoints(OdEdCommandContext* pCmdCtx)
{
    OdDbCommandContextPtr pDbCmdCtx(pCmdCtx);
    OdDbDatabasePtr pDb = pDbCmdCtx->database();

    OdDbSelectionSetIteratorPtr pIter = pDbCmdCtx->dbUserIO()->select(L"Select a face", OdEd::kSelAllowSubents)->newIterator();
    while ( !pIter->done() )
    {
        OdDbObjectId objId = pIter->objectId();
        if (objId.isNull())
            continue;

        OdDbObjectIdArray loopIds;
        loopIds.append(objId);
        if (OdUInt32 subents = pIter->subentCount())
        {
            OdDbEntityPtr pMainEnt = objId.safeOpenObject(OdDb::kForWrite);
            OdDb3dSolidPtr pBody = OdDb3dSolid::cast(pMainEnt);
            if (pBody == nullptr)
                continue;

            for (OdUInt32 i = 0; i < subents; ++i)
            {
                OdDbFullSubentPath subEntPath;
                if (pIter->getSubentity(i, subEntPath))
                {
                    OdDbEntityPtr subent = pMainEnt->subentPtr(subEntPath);
                    if (subent.isNull())
                        continue;

                    OdDbObjectId matIdGet;
                    OdResult res = pBody->getSubentMaterial(subEntPath.subentId(), matIdGet);
                    if (res == eOk)
                    {
                        OdDbMaterialPtr pMaterial = OdDbMaterial::cast(matIdGet.openObject());
                        if (!pMaterial.isNull())
                        {
                            OdString materialName = pMaterial->name();
                            if (pCmdCtx != nullptr)
                            {
                                OdDbCommandContextPtr pDbCmdCtx(pCmdCtx);
                                pDbCmdCtx->userIO()->putString(materialName);
                            }
                        }
                    }
                }
            }
        }
        pIter->next();
    }
}[/code]

Comments

  • Hi Vinit,
    you obviously programm in C++ ....
    Have a look at these two examples written in C# .NET ...you could then write similar code in C++ .

    1. Select the Face of a Solid 3D
         http://adndevblog.typepad.com/autocad/2012/03/selecting-solid3d-sub-entities.html

    2. Getting the Face Material...after getting the subentity ID of the Face...
        http://adndevblog.typepad.com/autocad/2012/03/getting-material-name-associated-with-a-face.html

    ********  Code Snippet *********************

        using (Brep brep = new Brep(path))

        {

            foreach    ( Autodesk.AutoCAD.BoundaryRepresentation.Face    face   in    brep.Faces )

            try

            {

                ObjectId materialId = solid3d.GetSubentityMaterial( face.SubentityPath.SubentId);

                    Material material = tr.GetObject(materialId, OpenMode.ForRead) as Material;

                               ......................



        
  •  Thanks for the reply. 
    I was able to implement the suggested code. I was able to get the AcDbFullSubentPath of the selected face. But following code is not linking because of highlighted line

    [code]
         ... // Code to select the face and get AcDbFullSubentPath
         AcBrFace *pEnt = new AcBrFace();
         AcBr::ErrorStatus returnValue = AcBr::eOk;
         returnValue = pEnt->setSubentPath(subPath);
         if (returnValue != AcBr::eOk) {
             acutPrintf(ACRX_T("\n Error in AcBrEntity::set:"));
             return;
         }
    /code]

    Is AcBrEntity::setSubentPath() not implemented yet. Do you have some C++ samples of AcBr ?
    Also as per your suggestion I have to use AcDb3dSolid::getSubentMaterial(), which is not implemented in BricsCAD SDK 15.
    I am still using BRXSDK_V15_1_04. Are these implemented in BricsCAD SDK 16.1
  • AcBrEntity::setSubentPath() is implemented, minimum required versions are BRX SDK r9326 and BricsCAD V15.3.04
This discussion has been closed.