218
699
483
顶梁支柱
;;----------------=={ Add Objects to Block }==----------------;;;; ;;;; Adds all objects in the provided SelectionSet to the ;;;; definition of the specified block. ;;;;------------------------------------------------------------;;;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;;;------------------------------------------------------------;;;; Arguments: ;;;; doc - Document Object in which block resides. ;;;; block - Entity name of reference insert ;;;; ss - SelectionSet of objects to add to definition ;;;;------------------------------------------------------------;;(defun LM:AddObjectstoBlock ( doc block ss / lst mat ) (setq lst (LM:ss->vla ss) mat (LM:Ref->Def block) mat (vlax-tmatrix (append (mapcar 'append (car mat) (mapcar 'list (cadr mat))) '((0. 0. 0. 1.)))) ) (foreach obj lst (vla-transformby obj mat)) (vla-CopyObjects doc (LM:SafearrayVariant vlax-vbobject lst) (vla-item (vla-get-Blocks doc) (cdr (assoc 2 (entget block)))) ) (foreach obj lst (vla-delete obj)) (vla-regen doc acAllViewports));;-----------------=={ Remove From Block }==------------------;;;; ;;;; Removes an Entity from a Block Definition ;;;;------------------------------------------------------------;;;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;;;------------------------------------------------------------;;;; Arguments: ;;;; ent - Entity name of Object to Delete from Block [ENAME] ;;;;------------------------------------------------------------;;(defun LM:RemovefromBlock ( doc ent ) (vla-delete (vlax-ename->vla-object ent)) (vla-regen doc acAllViewports) (princ));;------------------=={ Safearray Variant }==-----------------;;;; ;;;; Creates a populated Safearray Variant of a specified ;;;; data type ;;;;------------------------------------------------------------;;;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;;;------------------------------------------------------------;;;; Arguments: ;;;; datatype - variant type enum (eg vlax-vbDouble) ;;;; data - list of static type data ;;;;------------------------------------------------------------;;;; Returns: VLA Variant Object of type specified ;;;;------------------------------------------------------------;; (defun LM:SafearrayVariant ( datatype data ) (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray datatype (cons 0 (1- (length data)))) data ) ));;------------=={ SelectionSet -> VLA Objects }==-------------;;;; ;;;; Converts a SelectionSet to a list of VLA Objects ;;;;------------------------------------------------------------;;;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;;;------------------------------------------------------------;;;; Arguments: ;;;; ss - Valid SelectionSet (Pickset) ;;;;------------------------------------------------------------;;;; Returns: List of VLA Objects, else nil ;;;;------------------------------------------------------------;;(defun LM:ss->vla ( ss / i l ) (if ss (repeat (setq i (sslength ss)) (setq l (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) l)) ) ));;---------------=={ Block Ref -> Block Def }==---------------;;;; ;;;; Returns the Transformation Matrix and Translation Vector ;;;; for transforming Block Reference Geometry to the Block ;;;; Definiton. ;;;;------------------------------------------------------------;;;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;;;------------------------------------------------------------;;;; Arguments: ;;;; e - Block Reference Entity ;;;;------------------------------------------------------------;;;; Returns: List of 3x3 Transformation Matrix, Vector ;;;;------------------------------------------------------------;;(defun LM:Ref->Def ( e / _dxf a l n ) (defun _dxf ( x l ) (cdr (assoc x l))) (setq l (entget e) a (- (_dxf 50 l)) n (_dxf 210 l)) ( (lambda ( m ) (list m (mapcar '- (_dxf 10 (tblsearch "BLOCK" (_dxf 2 l))) (mxv m (trans (_dxf 10 l) n 0) ) ) ) ) (mxm