- UID
- 5043
- 积分
- 1347
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-13
- 最后登录
- 1970-1-1
|
发表于 2004-5-31 12:52:47
|
显示全部楼层
Re: [ARX函数]:用ARX的方法获取文字文字外框
最初由 xux4618 发布
[B]请问怎样用ARX的方法获取文字的外边界? [/B]
不只是文字,所有的实体,你都可以用:AcDbEntity::getGeomExtents 获得包围盒。如果文字有转角,你需要根据水平方向的包围盒转换下。
另外也可以用:AcGiTextStyle::extents 获得,这个更好,是基于显示矢量的。你可以看看联机帮助。
再另外你可以用ARX全局函数:acedTextBox 获得,下面是联机帮助里面的代码:
[php]
int tbox()
{
ads_name tname;
struct resbuf *textent, *tent;
ads_point origin, lowleft, upright, p1, p2, p3, p4;
ads_real rotatn;
char rotatstr[15];
if (acedEntSel("\nSelect text: ", tname, p1) != RTNORM) {
acdbFail("No Text entity selected\n");
return BAD;
}
textent = acdbEntGet(tname);
if (textent == NULL) {
acdbFail("Couldn't retrieve Text entity\n");
return BAD;
}
tent = entitem(textent, 10);
origin[X] = tent->resval.rpoint[X]; //ECS coordinates
origin[Y] = tent->resval.rpoint[Y];
tent = entitem(textent, 50);
rotatn = tent->resval.rreal;
// acdbAngToS() converts from radians to degrees.
if (acdbAngToS(rotatn, 0, 8, rotatstr) != RTNORM) {
acdbFail("Couldn't retrieve or convert angle\n");
acutRelRb(textent);
return BAD;
}
if (acedTextBox(textent, lowleft, upright) != RTNORM) {
acdbFail("Couldn't retrieve text box
coordinates\n");
acutRelRb(textent);
return BAD;
}
acutRelRb(textent);
// If not currently in the WCS, at this point add
// acedTrans() calls to convert the coordinates
// retrieved from acedTextBox().
p1[X] = origin[X] + lowleft[X]; // UCS coordinates
p1[Y] = origin[Y] + lowleft[Y];
p2[X] = origin[X] + upright[X];
p2[Y] = origin[Y] + lowleft[Y];
p3[X] = origin[X] + upright[X];
p3[Y] = origin[Y] + upright[Y];
p4[X] = origin[X] + lowleft[X];
p4[Y] = origin[Y] + upright[Y];
if (acedCommand(RTSTR, "pline", RTPOINT, p1,
RTPOINT, p2, RTPOINT, p3,RTPOINT, p4, RTSTR, "c",
0) != RTNORM) {
acdbFail("Problem creating polyline\n");
return BAD;
}
if (acedCommand(RTSTR, "rotate", RTSTR, "L", RTSTR, "",
RTPOINT, origin, RTSTR, rotatstr, 0) != RTNORM) {
acdbFail("Problem rotating polyline\n");
return BAD;
}
return GOOD;
}
The preceding example "cheats" by using the AutoCAD ROTATE command to cause the rotation. A more direct way to do this is to incorporate the rotation into the calculation of the box points, as follows:
ads_real srot, crot;
tent = entitem(textent, 50);
rotatn = tent->resval.rreal;
srot = sin(rotatn);
crot = cos(rotatn);
.
.
.
p1[X] = origin[X] + (lowleft[X]*crot - lowleft[Y]*srot);
p1[Y] = origin[Y] + (lowleft[X]*srot + lowleft[Y]*crot);
p2[X] = origin[X] + (upright[X]*crot - lowleft[Y]*srot);
p2[Y] = origin[Y] + (upright[X]*srot + lowleft[Y]*crot);
p3[X] = origin[X] + (upright[X]*crot - upright[Y]*srot);
p3[Y] = origin[Y] + (upright[X]*srot + upright[Y]*crot);
p4[X] = origin[X] + (lowleft[X]*crot - upright[Y]*srot);
p4[Y] = origin[Y] + (lowleft[X]*srot + upright[Y]*crot);
[/php] |
|