CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 文档中心

关于获取文本的范围(AutoLISP)

2023-1-8 11:55| 发布者: admin| 查看: 497| 评论: 0|来自: AutoCAD

摘要: 文本框函数返回包含文本的框的对角坐标。

该函数返回包含文本的框的对角坐标。textbox

该函数将返回者的类型的实体定义列表(组代码和值的关联列表)作为其单个参数。此列表可以包含文本对象的完整关联列表说明,也可以仅包含描述文本字符串的列表。textboxentget

返回的点描述文本对象的边界框(包围文本的假想框),就好像它的插入点位于 (0,0,0) 处,旋转角度为 0。返回的第一个列表是点 (0.0 0.0 0.0),除非文本对象是倾斜的或垂直的,或者它包含带有降序的字母(如 g 和 p)。第一个点列表的值指定从文本插入点到包围文本的最小矩形的左下角的偏移距离。第二个点列表指定该框的右上角。返回的点列表始终描述此边界框的左下角和右上角,而不考虑要测量的文本的方向。textbox

以下示例代码显示接受的最小允许实体定义列表。由于未提供其他信息,因此使用文本样式和高度的当前默认值。textboxtextbox

命令:(文本框'((1 .“你好世界”)))

((0.0 0.0 0.0) (2.80952 1.0 0.0))

返回者的实际值将根据当前文本样式而有所不同。textbox

下面的示例代码演示一种为函数提供实体定义列表的方法。textbox

命令:文本

指定文本的起点或 [对齐/样式]:1,1

指定高度 <0.2000>:按回车键

指定文本的旋转角度 <0>:按回车

在就地文本编辑器中,输入test

在就地文本编辑器中,按 Enter

Command:(setq e (entget (entlast)))

((-1 . <实体名称:7ffffb05da0>) (0 .“文本”) (330 . <实体名称:

7ffffb039f0>) (5 .“1D2”) (100 .“AcDbEntity”) (67 . 0) (410 .

“模型”)(8 ."0") (100 .“AcDbText”) (10 1.0 1.0 0.0) (40 . 0.2) (1 .

“测试”) (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 .“标准”) (71 . 0) (72

.0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 .“AcDbText”) (73 . 0))

命令:(文本框 e)

((0.00491132 -0.00327422 0.0) (0.448295 0.195498 0.0))

下图显示了应用于高度为 1.0 的文本对象的结果。该图还显示了文本的基线和插入点。textbox

如果文本是垂直或旋转的,仍然是左下角,是右上角;如有必要,左下角的点可能有负偏移。pt1pt2

下图显示了为垂直和对齐文本示例返回的点值 (and)。在这两个示例中,字母的高度均为 1.0。(对于对齐的文本,将调整高度以适合对齐点。pt1pt2textbox

使用竖排文本样式时,点仍按从左到右、从下到上的顺序返回,就像水平样式一样,因此第一个点列表将包含与文本插入点的负偏移量。

Regardless of the text orientation or style, the points returned by are such that the text insertion point (group code 10) directly translates to the origin point of the object coordinate system (OCS) for the associated text object. This point can be referenced when translating the coordinates returned from into points that define the actual extent of the text. The following two sample functions use to place a box around selected text regardless of its orientation. textboxtextboxtextbox

The first routine uses the function to draw a box around a selected text object: textbox

(defun C:TBOX ( / textent tb ll ur ul lr)
  (setq textent (car (entsel "\nSelect text: ")))
  (command "._ucs" "Object" textent)
  (setq tb (textbox (list (cons -1 textent)))
        ll (car tb)
        ur (cadr tb)
        ul (list (car ll) (cadr ur))
        lr (list (car ur) (cadr ll))
  )
  (command "._pline" ll lr ur ul "Close")
  (command "._ucs" "p")
 (princ)
)

The second routine, which follows, accomplishes the same task as the first routine by performing the geometric calculations with the AutoLISP functions and . The result is correct only if the current UCS is parallel to the plane of the text object. sincos

(defun C:TBOX2 ( / textent ang sinrot cosrot t1 t2 p0 p1 p2 p3 p4)
  (setq textent (entget (car (entsel "\nSelect text: "))))
  (setq p0 (cdr (assoc 10 textent))
        ang (cdr (assoc 50 textent))
        sinrot (sin ang)
        cosrot (cos ang)
        t1 (car (textbox textent))
        t2 (cadr (textbox textent))
        p1 (list
               (+ (car p0)
                 (- (* (car t1) cosrot)(* (cadr t1) sinrot))
               )
               (+ (cadr p0)
                 (+ (* (car t1) sinrot)(* (cadr t1) cosrot))
               )
             )
        p2 (list
               (+ (car p0)
                 (- (* (car t2) cosrot)(* (cadr t1) sinrot))
               )
               (+ (cadr p0)
                 (+ (* (car t2) sinrot)(* (cadr t1) cosrot))
               )
             )
        p3 (list
               (+ (car p0)
                 (- (* (car t2) cosrot)(* (cadr t2) sinrot))
               )
               (+ (cadr p0)
                 (+ (* (car t2) sinrot)(* (cadr t2) cosrot))
               )
             )
        p4 (list
               (+ (car p0)
                 (- (* (car t1) cosrot)(* (cadr t2) sinrot))
               )
               (+ (cadr p0)
                 (+ (* (car t1) sinrot)(* (cadr t2) cosrot))
               )
             )
  )
  (command "._pline" p1 p2 p3 p4 "c")
 (princ)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 12:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部