- UID
- 5043
- 积分
- 1347
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
问题:
如何在图纸空间创建一个新的视口并激活它?我希望用户指定一个矩形(就像MVIEW命令那样)和一个已知的VIEW名字,然后创建一个新的视口。
回答:
要在图纸空间创建一个新的视口,要完成几个步骤:
1、创建一个AcDbViewPort 类对象
2、设置VIEW的坐标(使用 setWidth(), setHeight() and setCenterPoint())
3、把新的视口添加到图纸空间
4、获得用户指定的VIEW(AcDbViewTableRecord对象)
5、使用acdbSetCurrentView() 设置这个AcDbViewTableRecord 对象到新的视口
6、使用AcDbViewport::setOn() 设置为活动视口。
注意:AcDbViewport::setOn() 方法只有在命令注册标记不为ACRX_CMD_TRANSPARENT时候才能使用。如果标记设置了,AcDbViewport::setOn() 返回eCommandWasInProgress,并且直到tilemode系统变量设置到0时候才能激活视口。
Question
How can I create a new viewport in paper space and activate it? I want to let
the user specify a rectangle (like the MVIEW command) and an existing view name.
With this data I want to create a new viewport.
Answer
To create a new viewport in paper space, perform the following steps:
1. Create a new object of type AcDbViewport.
2. Set the view coordinates (with setWidth(), setHeight() and setCenterPoint()).
3. Append the new viewport to the paper space.
4. Get the view the user specified (AcDbViewTableRecord).
5. Set this view on the new viewport with acdbSetCurrentView().
6. Activate the viewport with AcDbViewport::setOn().
NOTE: The AcDbViewport::setOn() function only works if your command has been
registered without the ACRX_CMD_TRANSPARENT flag. If this flag is set,
AcDbViewport::setOn() returns with eCommandWasInProgress and you cannot activate
the viewport until you set tilemode to 1 and back to 0.
The following code demonstrates how to do this:
下面是示例代码:
[it618postdisplay>0]
[sell=5]
 - void fCreateViewPort()
- {
- // Only works in paperspace
- AcDbObjectId mCurViewportId = acedGetCurViewportObjectId();
- if (mCurViewportId == AcDbObjectId::kNull)
- {
- acutPrintf("\nCommand only works in paperspace.");
- 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 paperspace.");
- 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 paper 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_PAPER_SPACE, pPsBTR, AcDb::kForWrite))
- {
- acutPrintf("\nCannot access paper space.");
- pTable->close();
- delete pViewport;
- return;
- }
- pTable->close();
- AcDbObjectId mViewPortId;
- if (Acad::eOk != pPsBTR->appendAcDbEntity(mViewPortId, pViewport))
- {
- acutPrintf("\nCannot append viewport to paper 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();
- }
[/sell]
[/it618postdisplay]
|
|