nentsel 如何取得: 图块(可能多层嵌套图块)中某直线端点坐标?
nentsel 如何取得: 图块(可能多层嵌套图块)中某直线端点坐标? 本帖最后由 fools 于 2017-11-6 15:49 编辑用这个函数
;;;-----------------------------------------------------------;;
;;; 功能: 某点在块内坐标系统和世界或者用户坐标系统的转换 ;;
;;; 参数: pt 要变换的点。 ;;
;;; rlst 用 nentselp或者nentsel得到的表的最后一项 ;;
;;; from坐标系:0,WCS; 1,当前UCS; 2,块参照坐标系RCS;;
;;; to 坐标系:0,WCS; 1,当前UCS; 2,块参照坐标系RCS;;
;;;-----------------------------------------------------------;;
;;; MAT:TransNested (gile) ;;
;;; Translates a point coordinates from WCS or UCS to RCS ;;
;;; -coordinates system of a ;;
;;; reference (xref or block) whatever its nested level- ;;
;;; ;;
;;; Arguments ;;
;;; pt : the point to translate ;;
;;; rlst : the parents entities list from the deepest nested;;
;;; to the one inserted in current space -same as ;;
;;; (last (nentsel)) or (last (nentselp)) ;;
;;; from to : as with trans function: 0.WCS, 1.UCS, 2.RCS ;;
;;;-----------------------------------------------------------;;
(defun MAT:TransNested (pt rlst from to / GEOM)
(and (= 1 from) (setq pt (trans pt 1 0)))
(and (= 2 to) (setq rlst (reverse rlst)))
(and (or (= 2 from) (= 2 to))
(while rlst
(setq geom (if (= 2 to)
(MAT:RevRefGeom (car rlst))
(MAT:RefGeom (car rlst))
)
rlst (cdr rlst)
pt (mapcar '+ (MAT:mxv (car geom) pt) (cadr geom))
)
)
)
(if (= 1 to)
(trans pt 0 1)
pt
)
)
或者这个函数
;;;-----------------------------------------------------------;;
;;; 点的矩阵(4x4 matrix) 变换 ;;
;;; 输入:矩阵m和一个三维点p ;;
;;; 输出:点变换后的位置 ;;
;;;-----------------------------------------------------------;;
(defun MAT:mxp (m p)
(reverse (cdr (reverse (MAT:mxv m (append p '(1.0))))))
)
很好的资料,谢谢分享 本帖最后由 pxt2001 于 2023-10-16 09:33 编辑
电脑版链接 http://bbs.mjtd.com/forum.php?mod=viewthread&tid=93216&fromuid=288402
手机版链接 http://www.mjtd.com/forum.php?mod=viewthread&tid=93216&mobile=2
;; tt(嵌套图块内直线坐标)
(defun c:tt ()
(defun dxf (code s1) (cdr (assoc code (entget s1))))
(if (and (setq e1 (nentsel "\n选择: "))
(= (length e1) 4)
)
(progn
(setq s1 (car e1)
s2 (last (last e1))
pt (dxf 10 s2)
p1 (dxf 10 s1)
p2 (dxf 11 s1)
p1 (mapcar '(lambda (x y) (+ x y)) p1 pt)
p2 (mapcar '(lambda (x y) (+ x y)) p2 pt)
)
(grvecs (list 1 p1 p2))
)
)
(princ)
) 这就看懂了? 子函数都没有给
fools 发表于 2017-11-6 15:29
用这个函数
求子函数 江南十笑 发表于 2020-8-19 13:00
求子函数
(defun revrefgeom (ent / ang enx mat ocs)
(setq enx (entget ent)
ang (cdr (assoc 050 enx))
ocs (cdr (assoc 210 enx))
)
(list (setq mat (mxm (list (list (/ 1.0 (cdr (assoc 41 enx))) 0.0 0.0) (list 0.0 (/ 1.0 (cdr (assoc 42 enx))) 0.0)
(list 0.0 0.0 (/ 1.0 (cdr (assoc 43 enx))))
) (mxm (list (list (cos ang) (sin ang) 0.0) (list (- (sin ang)) (cos ang) 0.0) '(0.0 0.0 1.0))
(mapcar
'(lambda (v)
(trans v ocs 0 t)
)
'((1.0 0.0 0.0) (0.0 1.0 0.0)
(0.0 0.0 1.0)
)
)
)
)
)
(mapcar
'-
(cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 enx)))))
(mxv mat (trans (cdr (assoc 10 enx)) ocs 0))
)
)
) ;;;-----------------------------------------------------------;;
;;; 功能:图块的变换矩阵 ;;
;;; 输入:块参照的图元名 ;;
;;; 输出:块参照的变换矩阵 ;;
;;;-----------------------------------------------------------;;
;;; MAT:RefGeom (gile) ;;
;;; Returns a list which first item is a 3x3 transformation ;;
;;; matrix(rotation,scales normal) and second item the object ;;
;;; insertion point in its parent(xref, bloc or space) ;;
;;; ;;
;;; Argument : an ename ;;
;;;-----------------------------------------------------------;;
(defun mat:refgeom (ename / elst ang norm mat)
(setq elst (entget ename)
ang (cdr (assoc 50 elst))
norm (cdr (assoc 210 elst))
)
(list (setq mat (mat:mxm (mapcar
(function (lambda (v)
(trans v 0 norm t)
)
)
'((1.0 0.0 0.0) (0.0 1.0 0.0)
(0.0 0.0 1.0)
)
) (mat:mxm (list (list (cos ang) (- (sin ang)) 0.0) (list (sin ang) (cos ang) 0.0) '(0.0 0.0 1.0))
(list (list (cdr (assoc 41 elst)) 0.0 0.0) (list 0.0 (cdr (assoc 42 elst)) 0.0)
(list 0.0 0.0 (cdr (assoc 43 elst)))
)
)
)
)
(mapcar
'-
(trans (cdr (assoc 10 elst)) norm 0)
(mat:mxv mat (cdr (assoc 10 (tblsearch "BLOCK" (cdr (assoc 2 elst))))))
)
)
)
页:
[1]
2