找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 137|回复: 0

[每日一码] Create Paper Space Viewports

[复制链接]

1

主题

0

回帖

33

积分

管理员

积分
33
发表于 2024-3-14 21:00:08 | 显示全部楼层 |阅读模式
  1. void fCreateViewPort()
  2. {
  3.   // Only works in paperspace
  4.   AcDbObjectId mCurViewportId = acedGetCurViewportObjectId();
  5.   if (mCurViewportId == AcDbObjectId::kNull)
  6.   {
  7.     acutPrintf("\nCommand only works in paperspace.");
  8.     return;
  9.   }
  10.   AcDbViewport *pCurViewport;
  11.   if (Acad::eOk != acdbOpenObject(pCurViewport,mCurViewportId,AcDb::kForRead))
  12.   {
  13.     acutPrintf("\nCannot get active viewport.");
  14.     return;
  15.   }
  16.   if (pCurViewport->number() != 1)
  17.   {
  18.     acutPrintf("\nCommand only works in paperspace.");
  19.     pCurViewport->close();
  20.     return;
  21.   }
  22.   pCurViewport->close();
  23.   // Ask for the position
  24.   ads采用point pt1,pt2;
  25.   if (RTNORM != acedGetPoint(NULL, "\nSelect first corner: ", pt1))
  26.     return;
  27.   if (RTNORM != acedGetCorner(pt1, "\nSelect second corner: ", pt2))
  28.     return;
  29.   // Ask for the view to use
  30.   char mViewName[133];
  31.   if (RTNORM != acedGetString(0, "\nEnter name of view to use: ", mViewName))
  32.     return;
  33.   // Create new viewport
  34.   AcDbViewport *pViewport = new AcDbViewport;
  35.   pViewport->setWidth(fabs(pt2[X] - pt1[X]));
  36.   pViewport->setHeight(fabs(pt2[Y] - pt1[Y]));
  37.   pViewport->setCenterPoint(AcGePoint3d(pt1[X] + (pt2[X] - pt1[X]) / 2,
  38.       pt1[Y] + (pt2[Y] - pt1[Y]) / 2,
  39.       pt1[Z]));
  40.   // Append new viewport to paper space
  41.   AcDbBlockTable *pTable;
  42.   AcDbBlockTableRecord *pPsBTR;
  43.   if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()->getBlockTable(pTable, AcDb::kForRead))
  44.   {
  45.     acutPrintf("\nCannot get block table.");
  46.     delete pViewport;
  47.     return;
  48.   }
  49.   if (Acad::eOk != pTable->getAt(ACDB采用PAPER采用SPACE, pPsBTR, AcDb::kForWrite))
  50.   {
  51.     acutPrintf("\nCannot access paper space.");
  52.     pTable->close();
  53.     delete pViewport;
  54.     return;
  55.   }
  56.   pTable->close();
  57.   AcDbObjectId mViewPortId;
  58.   if (Acad::eOk != pPsBTR->appendAcDbEntity(mViewPortId, pViewport))
  59.   {
  60.     acutPrintf("\nCannot append viewport to paper space.");
  61.     pPsBTR->close();
  62.     delete pViewport;
  63.     return;
  64.   }
  65.   pPsBTR->close();
  66.   pViewport->setOn();
  67.   // Set the view
  68.   AcDbViewTable *pViewTable;
  69.   AcDbViewTableRecord *pViewTR;
  70.   if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()->getViewTable(pViewTable, AcDb::kForRead))
  71.   {
  72.     acutPrintf("\nCannot get view table.");
  73.     pViewport->close();
  74.     return;
  75.   }
  76.   if (Acad::eOk != pViewTable->getAt(mViewName, pViewTR, AcDb::kForRead))
  77.   {
  78.     acutPrintf("\nCannot access view '%s'.", mViewName);
  79.     pViewport->close();
  80.     pViewTable->close();
  81.     return;
  82.   }
  83.   pViewTable->close();
  84.   if (acedSetCurrentView(pViewTR, pViewport)!=Acad::eOk)
  85.    acutPrintf("\nFailed to set view");
  86.   // Close the objects
  87.   pViewTR->close();
  88.   pViewport->close();
  89. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-29 21:40 , Processed in 0.106220 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表