哈哈,我在这里做了很多非真题(至少我学到了很多)。
为我工作的代码现在用新标签重命名旧标签,然后用新标签替换模板,并用attsync更新模板。它还调整新模板的比例。
- (defun changeTags (/ BLK DOC I TAGLST SS)
- (vl-load-com)
- (setq blk "A10"
- tagLst '(
- ;"Old Tag" "New Tag"
- ("REG1" "PROJECTTITLE2")
- ("REG2" "TITLE1")
- ("REG3" "TITLE2")
- ("CLIENT" "CLIENT1")
- ("PROJECT" "PROJECTTITLE1")
- ("REG1" "PROJECTTITLE2")
- )
- i -1
- doc (vla-get-activedocument (vlax-get-acad-object))
- )
- (if (ssget "_X" (list (cons 0 "INSERT")(cons 2 blk)))
- (vlax-for bl (setq ss (vla-get-activeselectionset doc))
- (foreach att (vlax-invoke bl 'getAttributes)
- (If (assoc (vla-get-tagstring att) tagLst)
- (vla-put-tagstring att (cadr (assoc (vla-get-tagstring att) tagLst)))
- )))
- (princ "\nNo Selection Set Found."))
- (princ)
- (progn
- (command "-rename" "b" "A10" "new block NEW LOGO")
- (command "_.-insert" "new block NEW LOGO=Template_New_2010" "y" nil);replaced convert template to new template.
- (command "_.attsync" "n" "new block NEW LOGO")
- (scl);; scales all templates
- )(princ)(princ "succes!")(princ)
- )
- ;; Run program manually with this:
- (defun c:ChTag () (changeTags))
- ;; Uncomment this to run when lisp loaded
- ;(changeTags)
- ;; Scale the old template to new one
- (defun scl (/ ss)
- (vl-load-com)
- (if (setq SS (ssget "_X" (list '(0 . "INSERT") (cons 2 "new block NEW LOGO"))))
- ;(if (setq ss (ssget '((0 . "CIRCLE,ARC,ELLIPSE"))))
- (mapcar
- (function
- (lambda (Obj)
- (vla-ScaleEntity Obj
- (vla-get-insertionpoint Obj)9.673518)))
- (mapcar 'vlax-ename->vla-object
- (vl-remove-if 'listp
- (mapcar 'cadr (ssnamex ss))))))
- (princ))
这一切都是成批进行的,所以我要休息一天 |