你好
像这样的?(刚刚拼凑起来):
- (defun c:SyncAtt ( / *error* _StartUndo _EndUndo doc source tag val ss )
- (vl-load-com)
- ;; © Lee Mac 2010
- (defun *error* ( msg )
- (if doc (_EndUndo doc))
- (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
- (princ (strcat "\n** Error: " msg " **")))
- (princ)
- )
- (defun _StartUndo ( doc ) (_EndUndo doc)
- (vla-StartUndoMark doc)
- )
- (defun _EndUndo ( doc )
- (if (= 8 (logand 8 (getvar 'UNDOCTL)))
- (vla-EndUndoMark doc)
- )
- )
- (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
- (if
- (and
- (setq source
- (LM:Selectif
- (lambda ( x )
- (eq "ATTRIB" (cdr (assoc 0 (entget x))))
- )
- nentsel "\nSelect Source Attribute: "
- )
- )
- (ssget '((0 . "INSERT") (66 . 1)))
- )
- (progn
- (setq tag (cdr (assoc 2 (entget source)))
- val (cdr (assoc 1 (entget source)))
- )
- (_StartUndo doc)
- (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
- (mapcar
- (function
- (lambda ( attrib )
- (if (eq tag (vla-get-TagString attrib))
- (vla-put-TextString attrib val)
- )
- )
- )
- (vlax-invoke obj 'GetAttributes)
- )
- )
- (vla-delete ss)
- (_EndUndo doc)
- )
- )
- (princ)
- )
- ;;---------------------=={ Select if }==----------------------;;
- ;; ;;
- ;; Continuous selection prompts until the predicate function ;;
- ;; foo is validated ;;
- ;;------------------------------------------------------------;;
- ;; Author: Lee McDonnell, 2010 - www.lee-mac.com ;;
- ;; ;;
- ;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
- ;; Contact: Lee @ lee-mac.com ;;
- ;; Forums: Lee Mac @ TheSwamp.org, CADTutor.net, AUGI.com ;;
- ;;------------------------------------------------------------;;
- ;; Arguments: ;;
- ;; foo - optional predicate function taking ename argument ;;
- ;; fun - selection function to invoke ;;
- ;; str - prompt string ;;
- ;;------------------------------------------------------------;;
- ;; Returns: selected entity ename if successful, else nil ;;
- ;;------------------------------------------------------------;;
- (defun LM:Selectif ( foo fun str / e )
- ;; © Lee Mac 2010
- (while
- (progn (setq e (car (fun str)))
- (cond
- ( (eq 'ENAME (type e))
- (if (and foo (not (foo e)))
- (princ "\n** Invalid Object Selected **")
- )
- )
- )
- )
- )
- e
- )
您可能也对此感兴趣-如果您将其与“TextString”属性一起使用,它也可以执行您的任务。 |