天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 140|回复: 0

[每日一码] 创建图纸空间Viewports

[复制链接]
  • TA的每日心情
    开心
    昨天 06:36
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    105

    主题

    11

    回帖

    1308

    积分

    管理员

    积分
    1308
    QQ
    发表于 2024-3-14 19:38:05 | 显示全部楼层 |阅读模式
    1. void fCreateViewPort()
    2. {
    3.   // Only works in **space
    4.   AcDbObjectId mCurViewportId = acedGetCurViewportObjectId();
    5.   if (mCurViewportId == AcDbObjectId::kNull)
    6.   {
    7.     acutPrintf("\nCommand only works in **space.");
    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 **space.");
    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 ** 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采用**采用SPACE, pPsBTR, AcDb::kForWrite))
    50.   {
    51.     acutPrintf("\nCannot access ** 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 ** 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. }
    复制代码

     

     

     

     

    [每日一码] 创建图纸空间Viewports
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-11-1 09:33 , Processed in 0.123425 second(s), 25 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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