CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2022 开发者帮助

文本框实用程序函数

2024-5-18 18:49| 发布者: admin| 查看: 115| 评论: 0|原作者: admin|来自: AutoCAD

文本框实用程序函数

该函数查找包含文本实体的框的对角坐标。该函数采用一个参数 ,该参数必须以结果缓冲区列表的形式指定文本定义或字符串组。该函数将其参数设置为框的最小 XY 坐标,并将其参数设置为最大 XY 坐标。acedTextBox()entacedTextBox()p1p2

如果文本是水平的且未旋转,则(左下角)和(右上角)描述文本的边界框。坐标以实体坐标系 (ECS) 表示,原点 (0,0) 位于基线的左侧端点。(如果文本包含带有降序的字母,例如 g 和 p,则原点不是左下角。例如,下图显示了应用于高度为 1.0 的文本图元的结果。该图还显示了文本的基线和来源。p1p2entacedTextBox()

下图显示了为垂直文本和对齐文本样本返回的点值。在两个样本中,字母的高度都输入为 1.0。(对于旋转的文本,将缩放此高度以适合对齐点。acedTextBox()

请注意,对于垂直文本样式,点仍按从左到右、从下到上的顺序返回,因此第一个点列表包含与文本原点的负偏移量。

该函数还可以测量 attdef 和 attrib 实体中的字符串。对于 attdef,测量标签字符串(组 2);对于 Attrib 实体,它测量当前值(组 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 ROTATE 命令导致旋转来“作弊”。更直接的方法是将旋转合并到箱点的计算中,如下所示:

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); 

父主题:

  1. 常规访问

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2025-3-14 07:35

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部