找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1255|回复: 2

[ARX函数]:用ARX的方法获取文字文字外框

[复制链接]
发表于 2004-5-29 09:54:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
请问怎样用ARX的方法获取文字的外边界?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 13个

财富等级: 恭喜发财

发表于 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]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2004-5-31 18:34:25 | 显示全部楼层
请问,块实体外框又怎么获得呢?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-21 17:30 , Processed in 0.163123 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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