VPORTS 命令:視口app
AcDbViewportTableRecord 類表示模型空間的視口(在 AutoCAD 中稱爲平鋪視口) ,
AcDbViewport 類則表示圖紙空間的視口(在 AutoCAD 中稱爲浮動視口) 。函數
建立4個等大的視口:佈局
void ZffCHAP4Create4VPorts() { // 得到視口表 AcDbViewportTable *pVPortTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getViewportTable(pVPortTbl, AcDb::kForWrite); // 分別建立四個視口 AcGePoint2d pt1, pt2; AcDbViewportTableRecord *pVPortTblRcd1=new AcDbViewportTableRecord; pt1.set(0, 0); pt2.set(0.5, 0.5); pVPortTblRcd1->setLowerLeftCorner(pt1); pVPortTblRcd1->setUpperRightCorner(pt2); pVPortTblRcd1->setName("4VPorts"); AcDbViewportTableRecord *pVPortTblRcd2=new AcDbViewportTableRecord; pt1.set(0.5, 0); pt2.set(1, 0.5); pVPortTblRcd2->setLowerLeftCorner(pt1); pVPortTblRcd2->setUpperRightCorner(pt2); pVPortTblRcd2->setName("4VPorts"); AcDbViewportTableRecord *pVPortTblRcd3=new AcDbViewportTableRecord; pt1.set(0, 0.5); pt2.set(0.5, 1); pVPortTblRcd3->setLowerLeftCorner(pt1); pVPortTblRcd3->setUpperRightCorner(pt2); pVPortTblRcd3->setName("4VPorts"); AcDbViewportTableRecord *pVPortTblRcd4=new AcDbViewportTableRecord; pt1.set(0.5, 0.5); pt2.set(1, 1); pVPortTblRcd4->setLowerLeftCorner(pt1); pVPortTblRcd4->setUpperRightCorner(pt2); pVPortTblRcd4->setName("4VPorts"); pVPortTbl->add(pVPortTblRcd1); pVPortTbl->add(pVPortTblRcd2); pVPortTbl->add(pVPortTblRcd3); pVPortTbl->add(pVPortTblRcd4); pVPortTbl->close(); pVPortTblRcd1->close(); pVPortTblRcd2->close(); pVPortTblRcd3->close(); pVPortTblRcd4->close(); struct resbuf rb; acedGetVar("TILEMODE", &rb); if (rb.resval.rint == 1) // 當前工做空間是模型空間 { acedCommand(RTSTR, ".-VPORTS", RTSTR, "R",RTSTR, "4VPorts", RTNONE); } else // 當前工做空間是圖紙空間 { acedCommand(RTSTR, ".-VPORTS", RTSTR, "R",RTSTR, "4VPorts", RTSTR, "", RTNONE); } }
圖紙空間建立一個新的視口:3d
void ZffCHAP4CreateVPortInSpace() { // 指定當前佈局 Acad::ErrorStatus es = acdbHostApplicationServices()->layoutManager()->setCurrentLayout("佈局1"); if (es != Acad::eOk) { return; } // 得到塊表 AcDbBlockTable *pBlkTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForRead); // 得到圖紙空間的塊表記錄 AcDbBlockTableRecord *pBlkTblRcd = NULL; pBlkTbl->getAt(ACDB_PAPER_SPACE, pBlkTblRcd,AcDb::kForWrite); pBlkTbl->close(); // 建立新的佈局對象 AcDbViewport *pViewport = new AcDbViewport(); pViewport->setCenterPoint(AcGePoint3d(100, 50, 0)); pViewport->setHeight(80); pViewport->setWidth(120); // 將新的佈局對象添加到圖紙空間塊表記錄中 AcDbObjectId viewportId; pBlkTblRcd->appendAcDbEntity(viewportId, pViewport); pViewport->close(); pBlkTblRcd->close(); // 將新建的視口做爲當前視口 AcDbViewport *pVP = NULL; acdbOpenObject(pVP, viewportId, AcDb::kForWrite); pViewport->setOn();//建立浮動視口以後,要想啓用該視口,必須使用 setOn 函數 acedSetCurrentVPort(pVP); pVP->close(); }