|
- void fCreateViewPort()
- {
- // Only works in **space
- AcDbObjectId mCurViewportId = acedGetCurViewportObjectId();
- if (mCurViewportId == AcDbObjectId::kNull)
- {
- acutPrintf("\nCommand only works in **space.");
- return;
- }
- AcDbViewport *pCurViewport;
- if (Acad::eOk != acdbOpenObject(pCurViewport,mCurViewportId,AcDb::kForRead))
- {
- acutPrintf("\nCannot get active viewport.");
- return;
- }
- if (pCurViewport->number() != 1)
- {
- acutPrintf("\nCommand only works in **space.");
- pCurViewport->close();
- return;
- }
- pCurViewport->close();
- // Ask for the position
- ads采用point pt1,pt2;
- if (RTNORM != acedGetPoint(NULL, "\nSelect first corner: ", pt1))
- return;
- if (RTNORM != acedGetCorner(pt1, "\nSelect second corner: ", pt2))
- return;
- // Ask for the view to use
- char mViewName[133];
- if (RTNORM != acedGetString(0, "\nEnter name of view to use: ", mViewName))
- return;
- // Create new viewport
- AcDbViewport *pViewport = new AcDbViewport;
- pViewport->setWidth(fabs(pt2[X] - pt1[X]));
- pViewport->setHeight(fabs(pt2[Y] - pt1[Y]));
- pViewport->setCenterPoint(AcGePoint3d(pt1[X] + (pt2[X] - pt1[X]) / 2,
- pt1[Y] + (pt2[Y] - pt1[Y]) / 2,
- pt1[Z]));
- // Append new viewport to ** space
- AcDbBlockTable *pTable;
- AcDbBlockTableRecord *pPsBTR;
- if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()->getBlockTable(pTable, AcDb::kForRead))
- {
- acutPrintf("\nCannot get block table.");
- delete pViewport;
- return;
- }
- if (Acad::eOk != pTable->getAt(ACDB采用**采用SPACE, pPsBTR, AcDb::kForWrite))
- {
- acutPrintf("\nCannot access ** space.");
- pTable->close();
- delete pViewport;
- return;
- }
- pTable->close();
- AcDbObjectId mViewPortId;
- if (Acad::eOk != pPsBTR->appendAcDbEntity(mViewPortId, pViewport))
- {
- acutPrintf("\nCannot append viewport to ** space.");
- pPsBTR->close();
- delete pViewport;
- return;
- }
- pPsBTR->close();
- pViewport->setOn();
- // Set the view
- AcDbViewTable *pViewTable;
- AcDbViewTableRecord *pViewTR;
- if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()->getViewTable(pViewTable, AcDb::kForRead))
- {
- acutPrintf("\nCannot get view table.");
- pViewport->close();
- return;
- }
- if (Acad::eOk != pViewTable->getAt(mViewName, pViewTR, AcDb::kForRead))
- {
- acutPrintf("\nCannot access view '%s'.", mViewName);
- pViewport->close();
- pViewTable->close();
- return;
- }
- pViewTable->close();
- if (acedSetCurrentView(pViewTR, pViewport)!=Acad::eOk)
- acutPrintf("\nFailed to set view");
- // Close the objects
- pViewTR->close();
- pViewport->close();
- }
复制代码 |
|