- 积分
- 39674
- 明经币
- 个
- 注册时间
- 2006-8-18
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2013-1-7 09:20:54
|
显示全部楼层
本帖最后由 highflybir 于 2013-1-7 14:56 编辑
http://www.theswamp.org/index.php?topic=12887.msg157305#msg157305
的原帖发于此处:
Hi,
Quote
(setq ins1 (trans (cdr (assoc 10 (entget e1))) 0 1)) ;get insertion point
This will work only if UCS XY plane is parallel to WCS XY plane.
Insertion point coordinates of a block or text are defined in OCS (Object Coordinates System).
The following codes will work whatever the current UCS and the entity OCS :
Code: [Select]
(setq ins1 (trans (cdr (assoc 10 (entget e1))) e1 1))or
Code: [Select]
(setq ins1 (trans (cdr (assoc 10 (entget e1))) (cdr (assoc 210 (entget e1))) 1))
A 2D entiy's OCS is calculated by AutoCAD regarding its extrusion direction (210 DXF code or Normal property) using an "arbitrary axis algorithm" (see "Advanced DXF concepts" in the DXF section of the Developper's guide).
You can calculate an entity's OCS using this code :
;;; OCS Calculates the OCS of a 2D entity (text, block, circle, arc, lwpolyline, hatch ...)
;;; Argument : zdir, a single unit vector as returned by 210 DXF code
(defun sco (zdir / xdir)
(if (and (< (abs (car zdir)) 0.015625)
(< (abs (cadr zdir)) 0.015625)
)
(setq xdir (vunit (v^v '(0 1 0) zdir)))
(setq xdir (vunit (v^v '(0 0 1) zdir)))
)
(list xdir (vunit (v^v zdir xdir)) zdir)
)
;;; VUNIT Returns the vector's single unit vector
;;; Argument : v, a vector
(defun vunit (v / l)
(if (/= 0 (setq l (sqrt (apply '+ (mapcar '* v v)))))
(mapcar '(lambda (x) (/ x l)) v)
)
)
;;; V^V Returns the cross product of two vecors
;;; (the normal vector of the plane defined by v1 v2)
;;; Argument : v1 v2, two non-colinear vectors
(defun v^v (v1 v2)
(if (inters '(0 0 0) v1 '(0 0 0) v2)
(list (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
(- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
(- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
)
'(0.0 0.0 0.0)
)
)
|
|