本帖最后由 Gu_xl 于 2013-1-6 10:23 编辑
我也凑个热闹,给个图块转换矩阵应用实例:
- ;;选择物体加入图块示例,非等比图块无效
- (defun c:tt1 (/ BLKREF SS MAT TMAT N OBJLIST DOC)
- (if (and
- (setq blkref (car (entsel "\n选择图块:")))
- (= "INSERT" (cdr (assoc 0 (entget blkref))))
- (progn
- (redraw blkref 3)
- (princ "\n选择要添加的物体:")
- (setq ss (ssget))
- )
- )
- (progn
- (ssdel blkref ss)
- (if (> (sslength ss) 0)
- (progn
- ;;计算图块的变换矩阵的逆矩阵
- (setq mat (MAT:RevRefGeom blkref))
- ;;计算VLA 方法可用的 4x4 转换矩阵
- (setq tmat
- (vlax-tMatrix
- (append
- (mapcar 'append
- (car Mat)
- (mapcar 'list (cadr mat)))
- '((0. 0. 0. 1.))
- )
- )
- )
- (repeat (setq n (sslength ss))
- (setq objlist (cons (vlax-ename->vla-object
- (ssname ss (setq n (1- n))))
- objlist))
- )
- ;;对选择的物体进行矩阵转换
- (mapcar '(lambda (obj) (vla-transformby obj tMat))
- objlist)
- ;;将转换后的实体复制到图块定义内
- (vlax-invoke
- (setq doc
- (vla-get-ActiveDocument (vlax-get-acad-object)))
- 'CopyObjects
- objlist
- (vla-item (vla-get-blocks doc)
- (cdr (assoc 2 (entget blkref)))))
- ;;删除所选择物体
- (mapcar 'vla-delete ObjLst)
- ;;重显图形
- (vla-regen doc acActiveViewport)
- )
- )
- )
- )
- (princ)
- )
- ;;拷贝块内物体,非等比图块无效
- (defun c:tt2 (/ EN MAT TMAT DOC OBJ)
- (setq en (nentsel "\n选择块内物体:"))
- (if (> (length en) 2)
- (progn
- ;;计算图块的变换矩阵
- (setq mat (MAT:RefGeom (last (last en))))
- ;;计算VLA 方法可用的 4x4 转换矩阵
- (setq tmat
- (vlax-tMatrix
- (append
- (mapcar 'append
- (car Mat)
- (mapcar 'list (cadr mat)))
- '((0. 0. 0. 1.))
- )
- )
- )
- (vlax-invoke
- (setq doc
- (vla-get-ActiveDocument (vlax-get-acad-object)))
- 'CopyObjects
- (list (vlax-ename->vla-object (car en)))
- (vlax-get-property
- doc
- (if (= 1 (getvar 'CVPORT))
- 'PaperSpace
- 'ModelSpace))
- )
- (if
- (VL-CATCH-ALL-ERROR-P
- (VL-CATCH-ALL-APPLY
- 'vla-TransformBy
- (list (setq obj (vlax-ename->vla-object (entlast)))
- tmat)))
- (vla-delete obj)
- obj)
- )
- )
- )
|