Thursday, March 03, 2005

February Hit Graph


karishma ekka said...

hii fernando,
iam trying to read lines from screen and convert it into region then extrude it..iam not getting the id of the solid created so iam unable to append it into the database. Second,all the entities are read but only the first entity is converted into a solid and rest are not .
Here is my code..
Acad::ErrorStatus es;
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);

AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead);

AcDbBlockTableRecordIterator *pBlkTblRcdItr;
AcDbVoidPtrArray regions;
AcDbVoidPtrArray lineArray;
AcDbEntity *pEnt;
AcDbLine *line;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done();pBlkTblRcdItr->step())
es = pBlkTblRcdItr->getEntity(pEnt,AcDb::kForRead);
line = AcDbLine::cast(pEnt);
if ( line != NULL)
lineArray.append( line);
es = AcDbRegion::createFromCurves(lineArray, regions);
if(Acad::eOk != es)
acutPrintf(_T("\nFailed to create region\n"));

AcDbRegion *pRegion = AcDbRegion::cast((AcRxObject*)regions[0]);

ads_point pt;
double height;
AcDb3dSolid *pSolid = new AcDb3dSolid();
if (RTNORM == acedGetDist(pt,_T("\nEnter Extrusion height: "),&height))
es = pSolid->extrude(pRegion, height, 0.0);

for (int i = 0; i < lineArray.length(); i++)
delete (AcRxObject*)lineArray[i];

for (int ii = 0; ii < regions.length(); ii++)
delete (AcRxObject*)regions[ii];

AcDbObjectId savedExtrusionId = AcDbObjectId::kNull;

if(Acad::eOk == es)
AcDbDatabase *pDb = curDoc()->database();
AcDbObjectId modelId;
modelId = acdbSymUtil()->blockModelSpaceId(pDb);

AcDbBlockTableRecord *pBlockTableRecord;
modelId, AcDb::kForWrite);

es = pBlockTableRecord->appendAcDbEntity(modelId,pSolid);
delete pSolid;



please suggest something and point out my errors..

Fernando Malard said...

Hi Karishma,

At the first look your code seems to be right but you still need adjust:

1) Check the Acad::ErrorStatus returned extrude() method;

2) Walk through all regions returned by the createFromCurves() call because you are just using the first element (regions[0]). As I said before, this method can return several regions as a result of createFromCurves() method. So basically create a FOR statement to collect all regions returned and perform the extrusion one by one;

I would recommend you to isolate the extrusion process into a separate method to be called while processing the regions array so your code becomes cleaner and safer.


karishma ekka said...

hii fernando ,
i want to convert lines into polylines using objectarx but iam not getting any api.please suggest some method its urgent.

Fernando Malard said...

Hi Karishma,

There isn't any direct API to do that.
Depending on your requirements you can find some classical algorithms out there.
Note that all curves inside AutoCAD (derived from AcDbCurve) are parametric curves. AcDbLine are curves with two points and parameters varying from 0.0 to 1.0 because it has only one segment.