该函数查找包含文本实体的框的对角坐标。该函数采用一个参数,该参数必须以结果缓冲区列表的形式指定文本定义或字符串组。该函数将其参数设置为框的最小XY坐标,将其参数设置为最大XY坐标。acedTextBox()entacedTextBox()p1p2 如果文本是水平的并且没有旋转,(左下角)和(右上角)描述文本的边界框。坐标以实体坐标系 (ECS) 表示,原点 (0,0) 位于基线的左侧端点。(如果文本包含带有降序的字母,例如 g 和 p,则原点不是左下角。例如,下图显示了应用于高度为 1.0 的文本实体的结果。该图还显示了文本的基线和来源。p1p2entacedTextBox() ![]() 下图显示了为垂直和对齐文本示例返回的点值。在这两个样本中,字母的高度输入为 1.0。(对于旋转的文本,将缩放此高度以适合对齐点。acedTextBox() ![]() 请注意,对于垂直文本样式,点仍以从左到右、从下到上的顺序返回,因此第一个点列表包含与文本原点的负偏移。 该函数还可以测量 attdef 和 attrib 实体中的字符串。对于 attdef,测量标签字符串(组 2);对于属性实体,它测量当前值(组 1)。acedTextBox()acedTextBox() 以下函数使用一些实体处理函数,提示用户选择一个文本实体,然后根据返回的坐标在文本周围绘制一个边界框。acedTextBox() 注意:仅当您当前处于世界坐标系 (WCS) 中时,采样函数才能正常工作。如果不是,则代码应将从实体检索到的 ECS 点转换为 使用的 UCS 坐标。请参见坐标系变换。tbox()acedCommandS()
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 (acedCommandS(RTSTR, "pline", RTPOINT, p1,
RTPOINT, p2, RTPOINT, p3,RTPOINT, p4, RTSTR, "c",
0) != RTNORM) {
acdbFail("Problem creating polyline\n");
return BAD;
}
if (acedCommandS(RTSTR, "rotate", RTSTR, "L", RTSTR, "",
RTPOINT, origin, RTSTR, rotatstr, 0) != RTNORM) {
acdbFail("Problem rotating polyline\n");
return BAD;
}
return GOOD;
}
前面的示例通过使用 AutoCAD 旋转命令进行“欺骗”,以引起旋转。更直接的方法是将旋转纳入箱点的计算中,如下所示: 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);
|
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-29 09:45
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.