Message 1 of 8
3d solid from 3d polyline
Not applicable
03-06-2013
06:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have 3d polyline and want to create 3d solid, based on it.
i have to:
1.extrude polyline on some height
2. create bottom (my 3d polyline) and top (my polyline's copy moved at the same height) surfaces
3. use createSculptedSolid to create 3d solid.
here is the code of my function
AcDbObjectId add3dSolid(AcDbObjectId poly3dID, // bottom polyline
double height, // height for extrude and top polyline
Adesk::UInt16 Color = 0,
const ACHAR* Layer = NULL,
ACHAR * ModelPaperSpace = ACDB_MODEL_SPACE);
AcDbObjectId add3dSolid(AcDbObjectId poly3dID, double height, Adesk::UInt16 Color, const ACHAR* Layer, ACHAR * ModelPaperSpace)
{
Acad::ErrorStatus es;
AcDbObjectId eIdTop;
AcDbObjectId eId = AcDbObjectId::kNull;
AcDbEntity * pEnt;
if (Acad::eOk != acdbOpenObject(pEnt,poly3dID,AcDb::kForRead)) return eId;
AcDbEntity *pEntTop = (AcDbEntity*)pEnt->clone();
AcGeMatrix3d mat;
mat.setToTranslation(AcGeVector3d(0.0,0.0,height));
pEntTop->transformBy(mat);
es = postToDbase(pEntTop, eIdTop, ModelPaperSpace); // add top polyline to db
pEnt->close();
AcDb3dProfile *pSweepPerimeter = new AcDb3dProfile(pEnt);
AcDbSweepOptions swepOptions;
AcDbObjectId newId;
AcDbSurface * pPerimeter;
AcDbSurface * pTop;
AcDbSurface * pBottom;
es = AcDbSurface::createExtrudedSurface(pSweepPerimeter,AcGeVector3d(0.0,0.0,height),swepOptions,(AcDbExtrudedSurface*&)pPerimeter);
AcDb3dProfile *pSweepBottom = new AcDb3dProfile(pEnt);
AcDbPathRef pathRef;
pSweepBottom->getPathRef(pathRef);
AcDbObjectIdArray idArr;
es = AcDbSurface::createPatchSurface(pathRef, idArr,0,0.0,pBottom);
AcDb3dProfile *pSweepTop = new AcDb3dProfile(pEntTop);
AcDbPathRef pathRefTop;
pSweepTop->getPathRef(pathRefTop);
idArr.removeAll();
es = AcDbSurface::createPatchSurface(pathRefTop, idArr,0,0.0,pTop);
AcArray<AcDbEntity*> surfacesArray;
surfacesArray.append(pPerimeter);
surfacesArray.append(pTop);
surfacesArray.append(pBottom);
AcDb3dSolid *pSolid = new AcDb3dSolid();
pSolid->setDatabaseDefaults();
AcGeIntArray limits;
AcDbEntity *pSurfaceEnt;
es = pSolid->createSculptedSolid(surfacesArray, limits); // sometimes fails )))
if(es == Acad::eOk)
{
if (Color != 0) pSolid->setColorIndex(Color);
if (isLayerExists(Layer)) pSolid->setLayer(Layer);
pSolid->setLinetype(_T("Continuous"));
es = postToDbase(pSolid, eId, ModelPaperSpace);
if (es == Acad::eOk)
{
es = pSolid->draw();
es = pSolid->close();
}
}
else
{
delete pSolid;
}
delete pPerimeter;
delete pTop;
delete pBottom;
delete pSweepBottom;
delete pSweepTop;
delete pSweepPerimeter;
deleteEntities(eIdTop); // delete top polyline from db
return eId;
}the most wondering thing is that autocad sometimes can't create 3d solid because of "holes" between surfaces (attached dwg. black contour is ok, but red is wrong even for native autocad commands).
is that bug or expected behavior? 🙂
and how can i get 3d solid if this way is wrong?

