不确定这是否有帮助?
- (defun c:BlkRep (/ *error* nlk doc spc blk i ss uflag ent nObj aLst att tag)
- (vl-load-com)
- (setq nblk "C:\\...dwg") ;; Filepath of New Block to Insert
- (defun *error* (msg)
- (and uFlag (vla-EndUndoMark doc))
- (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
- (princ (strcat "\n** Error: " msg " **")))
- (princ))
- (setq doc (vla-get-ActiveDocument
- (vlax-get-Acad-Object))
-
- spc (if (zerop (vla-get-activespace doc))
- (if (= (vla-get-mspace doc) :vlax-true)
- (vla-get-modelspace doc)
- (vla-get-paperspace doc))
- (vla-get-modelspace doc)))
-
- (while
- (progn
- (setq blk (getstring t "\nSpecify Block Name to Replace: "))
- (cond ( (eq "" blk) nil)
- ( (not (setq i -1 ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blk)))))
- (princ "\n** Block not Found in Drawing **")))))
- (if ss
- (progn
- (setq uflag (not (vla-StartUndomark doc)))
-
- (while (setq ent (ssname ss (setq i (1+ i))))
- (setq nObj
- (vla-Insertblock spc
- (vla-get-InsertionPoint
- (setq Obj (vlax-ename->vla-object ent))) nblk
- (vla-get-Xscalefactor obj)
- (vla-get-yScalefactor obj)
- (vla-get-zscalefactor obj)
- (vla-get-Rotation obj)))
- (setq aLst
- (mapcar
- (function
- (lambda (x)
- (cons (strcase (vla-get-TagString x)) (vla-get-TextString x))))
- (vlax-invoke Obj 'GetAttributes)))
- (foreach att (vlax-invoke nObj 'GetAttributes)
- (if (setq tag (assoc (strcase (vla-get-TagString att)) aLst))
- (vla-put-TextString att (cdr tag))))
- (entdel ent))
- (setq uflag (vla-EndUndoMark doc))))
- (princ))
-
在顶部用双反斜杠指定新块的文件路径。 |