Dia*_*san 3 lisp autocad autolisp dxf
我需要这条信息用于我正在创建的过滤器。
因此,假设我将网格设置为 1,然后将原点放置在 UCS 中。
然后我画一个中心为圆5, 0。
这是我得到的:
(
(-1 . <Entity name: 1f3dbb9d580>)
(0 . "CIRCLE")
(330 . <Entity name: 1f3dbba51f0>)
(5 . "270")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "0")
(100 . "AcDbCircle")
(10 2495.0 1180.0 0.0)
(40 . 3.16228)
(210 0.0 0.0 1.0)
)
Run Code Online (Sandbox Code Playgroud)
为什么在 10 号我有这些数字?
不应该是这样 (10 5.0 0.0 0.0)吗?
定义大多数平面实体(例如圆弧、圆、2D 折线等)几何的坐标是相对于称为对象坐标系(OCS)的坐标系定义的。
OCS 与世界坐标系 (WCS) 共享其原点,其 Z 轴对应于与实体(由 DXF 组表示)关联的法线矢量(也称为挤出矢量210),其 X 轴和 Y 轴由任意定义轴算法应用于法线向量。
任意轴算法在标准 AutoLISPtrans函数中实现,这有助于将点从一个坐标系轻松转换到另一个坐标系。
在您的特定示例中,法向量是(0.0 0.0 1.0),它等于 WCS 平面的法向量,因此对于这个特定示例,OCS 等于 WCS。
但是,一般来说,要将点从任意 OCS 转换为 WCS 或活动用户坐标系 (UCS),您需要为trans函数提供 OCS 法向矢量或相关实体的实体名称。
例如,使用 OCS 法向量从 OCS 转换为活动 UCS:
(trans (cdr (assoc 10 <dxf-data>)) (cdr (assoc 210 <dxf-data>)) 1)
Run Code Online (Sandbox Code Playgroud)
或者,使用实体名称从 OCS 转换为活动 UCS:
(trans (cdr (assoc 10 <dxf-data>)) (cdr (assoc -1 <dxf-data>)) 1)
Run Code Online (Sandbox Code Playgroud)
在示例程序中实现,这可能是:
(defun c:test ( / ent enx )
(cond
( (not (setq ent (car (entsel "\nSelect circle: "))))
(princ "\nNothing selected.")
)
( (/= "CIRCLE" (cdr (assoc 0 (setq enx (entget ent)))))
(princ "\nThe selected object is not a circle.")
)
( (princ "\nThe circle center relative to the UCS is: ")
(princ (trans (cdr (assoc 10 enx)) ent 1))
)
)
(princ)
)
Run Code Online (Sandbox Code Playgroud)
解决您在评论中遇到的问题,您需要将坐标从/向 OCS 和 UCS 转换以实现所需的结果,例如:
(defun c:test ( / ent enx new old xco )
(cond
( (not (setq ent (car (entsel "\nSelect circle: "))))
(princ "\nNothing selected.")
)
( (/= "CIRCLE" (cdr (assoc 0 (setq enx (entget ent)))))
(princ "\nThe selected object is not a circle.")
)
( (setq old (assoc 10 enx)
xco (car (trans (cdr old) ent 1))
new (cons 10 (trans (list xco 0.0 0.0) 1 ent))
enx (subst new old enx)
)
(entmod enx)
)
)
(princ)
)
Run Code Online (Sandbox Code Playgroud)
该操作也可以压缩为单个表达式,例如:
(setq old (assoc 10 enx)
enx (subst (cons 10 (trans (list (car (trans (cdr old) ent 1)) 0) 1 ent)) old enx)
)
(entmod enx)
Run Code Online (Sandbox Code Playgroud)
但是,这不太可读。
| 归档时间: |
|
| 查看次数: |
348 次 |
| 最近记录: |