CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 文档中心

关于实体上下文和坐标转换数据(AutoLISP)

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

摘要: nentsel 和 nentselp 函数与 entsel 类似,不同之处在于它们返回两个附加值来处理嵌套在块引用中的实体。

与 和 函数类似,只是它们返回两个附加值来处理嵌套在块引用中的实体。nentselnentselpentsel

这些函数之间的另一个区别是,当用户通过选择复杂实体或由以下方式选择复杂实体来响应 acall 时,这些函数返回所选子实体的实体名称,而不是复杂实体的标头 asdoes。nentselnentselpentsel

例如,当用户选择 3D 折线时,返回顶点子实体而不是折线标题。您可以通过连续调用 Seqend 子实体来检索折线标头,然后从 Deqend 子实体的 -2 dxf 组代码中获取标头的名称。当用户在嵌套块引用中选择属性时,这同样适用。nentselentnext

在块参照中选取属性将返回该属性的名称和拾取点。当所选对象是块参照的组件而不是属性时,返回包含以下元素的列表:nentsel

  • 所选实体的名称。
  • 包含用于选取对象的点坐标的列表。
  • 模型到世界转换矩阵。这是一个由四个子列表组成的列表,每个子列表都包含一组坐标。此矩阵可用于将实体定义数据点从称为模型坐标系 (MCS) 的内部坐标系转换为世界坐标系 (WCS)。包含选定图元的块的插入点定义 MCS 的原点。创建块时 UCS 的方向决定了 MCS 轴的方向。
  • 包含包含选定对象的块的实体名称的列表。如果所选对象位于嵌套块(块中的块)中,则列表还包含嵌套所选对象的所有块的图元名称,从最里面的块开始,一直向外,直到报告插入到图形中的块的名称。

选择块返回的列表汇总如下:nentsel

(<Entity Name: ename1>   ; Name of entity.
  (Px Py Pz)             ; Pick point.
  ( (X0 Y0 Z0)           ; Model to World Transformation Matrix.
  (X1 Y1 Z1)
  (X2 Y2 Z2)
  (X3 Y3 Z3)
)
(<Entity name: ename2>   ; Name of most deeply nested block
  .                      ; containing selected object.
  ..
  <Entity name: enamen>) ; Name of outermost block
)                        ; containing selected object.

在下面的示例中,创建一个要与函数一起使用的块。nentsel

命令:

指定第一个点:1,1

指定下一个点或[撤消]:3,1

指定下一个点或[撤消]:3,3

指定下一个点或[关闭/撤消]:1,3

指定下一个点或 [关闭/撤消]:c

命令:-块

输入块名称或 [?]:正方形

指定插入基点或[注释]:2,2

选择对象:选择刚刚绘制的四条线

选择对象:按回车

然后,将块插入绕Z轴旋转 45 度的 UCS 中:

命令:ucs

当前UCS名称:*世界*

指定 UCS 的原点或 [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>:z

指定绕 Z 轴的旋转角度 <90>:45

命令:插入

输入块名称或 [?]:正方形

指定插入点或[基点/缩放/X/Y/Z/旋转]:7,0

输入 X 比例因子,指定对角,或 [角/XYZ] <1>:按回车键

输入 Y 比例因子<使用 X 比例因子>:按回车键

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

Use to select the lower-left side of the square. nentsel

(setq ndata (nentsel))

This code sets equal to a list similar to the following: ndata

(<Entity Name: 400000a0>   ; Entity name.
  (6.46616 -1.0606 0.0)    ; Pick point.
  ((0.707107 0.707107 0.0) ; Model to World
  (-0.707107 0.707107 0.0) ; Transformation Matrix.
  (0.0 -0.0 1.0)
  (4.94975 4.94975 0.0)
)
  (<Entity name:6000001c>) ; Name of block containing
                           ; selected object.
)

Once you obtain the entity name and the Model to World Transformation Matrix, you can transform the entity definition data points from the MCS to the WCS. Use and on the entity name to obtain the definition points expressed in MCS coordinates. The Model to World Transformation Matrix returned by is a 4×3 matrix—passed as an array of four points—that uses the convention that a point is a row rather than a column. The transformation is described by the following matrix multiplication: entgetassocnentsel

So the equations for deriving the new coordinates are as follows:

米吉,其中 0 le;ijle;2、是模型到世界变换矩阵的坐标;XYZ是以 MCS 坐标表示的实体定义数据点,X',Y',Z' 是以 WCS 坐标表示的结果实体定义数据点。

要变换向量而不是点,请不要添加平移向量(变换矩阵第四列中的 M30 M31 M32)。

注意:这是唯一使用此类矩阵的 AutoLISP 函数。首选函数,因为它返回的矩阵类似于其他 AutoLISP、ObjectARX 和托管 .NET 函数使用的矩阵。nentselpnentsel

以下示例使用之前获取的实体名称说明如何获取块定义中包含的线(组代码 10)的 MCS 起点:nentsel

Command:(setq edata (assoc 10 (entget (car ndata))))

(10 -1.0 1.0 0.0)

以下语句将“模型到世界变换矩阵”子列表存储在符号中。matrix

Command:(setq matrix (caddr ndata))

((0.707107 0.707107 0.0)   ; X transformation
  (-0.707107 0.707107 0.0) ; Y transformation
  (0.0 -0.0 1.0)           ; Z transformation
  (4.94975 4.94975 0.0)    ; Displacement from WCS origin
)

以下语句应用 X' 的变换公式,将直线起点的X坐标从 MCS 坐标更改为 WCS 坐标:

(setq answer
  (+                                       ; add:
    (* (car (nth 0 matrix))(cadr edata))   ; M00 * X
    (* (car (nth 1 matrix))(caddr edata))  ; M10 * Y
    (* (car (nth 2 matrix))(cadddr edata)) ; M20 * Z
    (car (nth 3 matrix))                   ; M30
  )
)

此语句返回 3.53553,即所选直线起点的 WCSX坐标。


路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-19 14:37

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部