[每日一码] 在图纸空间创建非矩形的Viewport
void fCreateNonRectangularViewPort(){
//采用采用采用采用create the circle
ads采用point centerPoint;
if(RTNORM != acedGetPoint(NULL,"\nEnter the Viewport center point:",centerPoint))
return;
ads采用real radius;
if(RTNORM != acedGetDist(centerPoint,"\nEnter the radius of the Viewport:",&radius))
return;
char viewName;
if (RTNORM != ads采用getstring(0,"\nEnter name of view to use: ", viewName))
return;
AcDbCircle* pCircle = new AcDbCircle;
//采用采用采用采用assigning the center point
pCircle->setCenter(AcGePoint3d(centerPoint,centerPoint,0));
pCircle->setRadius(radius);
AcDbBlockTable *pTable;
AcDbBlockTableRecord *pRecord;
if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()->getBlockTable(pTable, AcDb::kForRead)) {
acutPrintf("\nCannot get block table.");
delete pCircle;
return;
}
if (Acad::eOk != pTable->getAt(ACDB采用PAPER采用SPACE, pRecord, AcDb::kForWrite)) {
acutPrintf("\nCannot access paper space.");
pTable->close();
delete pCircle;
return;
}
pTable->close();
AcDbObjectId circleId;
if (Acad::eOk != pRecord->appendAcDbEntity(circleId, pCircle)) {
acutPrintf("\nCannot append circle to paper space.");
pRecord->close();
delete pCircle;
return;
}
pRecord->close();
pCircle->close();
//采用采用采用采用create the viewport entity
AcDbViewport *pViewport = new AcDbViewport;
//采用采用采用assign the center point of circle (since the value is known directly assigning)
pViewport->setCenterPoint(AcGePoint3d(centerPoint,centerPoint,0));
//采用采用采用Append new viewport to the paper space
if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()->getBlockTable(pTable, AcDb::kForRead)) {
acutPrintf("\nCannot get block table.");
delete pViewport;
return;
}
if (Acad::eOk != pTable->getAt(ACDB采用PAPER采用SPACE, pRecord, AcDb::kForWrite)) {
acutPrintf("\nCannot access paper space.");
pTable->close();
delete pViewport;
return;
}
pTable->close();
AcDbObjectId viewportId;
if (Acad::eOk != pRecord->appendAcDbEntity(viewportId, pViewport)) {
acutPrintf("\nCannot append viewport to paper space.");
pRecord->close();
delete pViewport;
return;
}
pRecord->close();
pViewport->setNonRectClipEntityId(circleId);
pViewport->setNonRectClipOn();
//采用采用采用set the view
AcDbViewTable *pViewTable;
AcDbViewTableRecord *pView;
if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()->getViewTable(pViewTable, AcDb::kForRead)) {
acutPrintf("\nCannot get view table.");
pViewport->close();
return;
}
if (Acad::eOk != pViewTable->getAt(viewName, pView, AcDb::kForRead)) {
acutPrintf("\nCannot access view '%s'.", viewName);
pViewport->close();
pViewTable->close();
return;
}
pViewTable->close();
if (acedSetCurrentView(pView, pViewport)!=Acad::eOk)
acutPrintf("\nFailed to set view");
pViewport->setOn();
pView->close();
pViewport->close();
//update the screen such the viewport is updated
acedCommand(RTSTR,"采用REGEN",RTNONE,0);
}
页:
[1]