我把这个放在一起,将一个选定的源块复制到另一个选定的块上。不是最快的例程,但它有效。
- ;; Function to copy blocks from one point to another
- (defun c:Replaceblocks
- (/ ent1 ent2 obj1 obj2 pt1
- pt2 x ss index keyw rot
- r2d copyobj
- )
- (while
- (= ent1 nil)
- (setq ent1 (car (entsel "\n Select block to copy: ")))
- (if (= ent1 nil)
- (alert "\n You missed, try again...")
- )
- )
- (while
- (= ent2 nil)
- (setq ent2 (car (entsel "\n Select block you want to swap: ")))
- (if (= ent2 nil)
- (alert "\n You missed, try again...")
- )
- )
- (setq obj1 (vlax-ename->vla-object ent1)
- pt1 (trans (vlax-get obj1 'insertionpoint) 0 1)
- )
- (setq obj2 (vlax-ename->vla-object ent2)
- x (vlax-get-property obj2 'Name)
- )
- (if
- (and
- (= (vla-get-ObjectName Obj1) "AcDbBlockReference")
- (not (vlax-property-available-p Obj1 'Path))
- )
- (progn
- (if (not *default*)
- (setq *default* "Select")
- )
- (initget 0 "Select All")
- (setq keyw
- (cond
- ((getkword
- (strcat "\nEnter selection option (Select / All): >: "
- )
- )
- )
- (*default*)
- )
- )
- (setq *default* keyw)
- (cond
- ((= Keyw "Select") (setq SS (ssget (list (cons '2 x)))))
- ((= Keyw "All") (setq SS (ssget "X" (list (cons '2 x)))))
- )
- (setq
- index -1
- )
- (while (vla-object obj)
- pt2 (trans (vlax-get obj2 'insertionpoint) 0 1)
- rot (vlax-get obj2 'Rotation)
- copyobj (vlax-invoke obj1 'Copy)
- )
- (vla-put-rotation copyobj rot)
- (vlax-invoke copyobj 'Move pt1 pt2)
- )
- )
- )
- (princ)
- (command "_erase" ss "")
- (princ)
- (princ (strcat "\nBlocks swapped - " (itoa index)))
- )
|