;; ------------------------ LDRUPD.LSP ------------------------------- ;; Purpose: Updates a selection set of leaders to values set by ;; current leader style. ;; Clears all existing overrides in the selection set. ;; Ignores current dimstyle overrides (i.e. uses style params). ;; Updates leader-associated MTEXT, if it exists. ;; Version: 1.0 ;; Date: 08 Oct. 00 ;; Author: Herman Mayfarth ;; Copyright © 2000 by Herman Mayfarth. All rights reserved. ;; Provided "as is" and without warranty. ;; Permission granted to use and redistribute without fee provided ;; notice of copyright and disclaimer of warranty remain in file. ;; Usage: AutoCAD R14 ->? ;;--------------------------------------------------------------------- (defun C:LDRUPD ( / #ent ldrupd ldrss oldeko sing_pl) ;;---------------------sing_pl--------------------------------------- ;; Purpose: supplies correct suffix for singular vs. plural noun ;; Needs: string for root of noun ;; counter for quantity ;; Returns: correct string for quantity referenced (defun sing_pl(root i / ) (if (/= i 1) (strcat root "s") root );if );end sing_pl ;;;;---------------------ldrupd---------------------------------------- ;;; Purpose: update a selection set of LEADER entities to current settings ;;; Param: selection set of LEADER entities - calling function must filter ;;; Returns: # of entities processed if successful ;;; -1 if attempt to use DIMSCALE =0 with TILEMODE=1 (defun ldrupd (ss / case childent dimscl dimsty dstyle i ldinfo ldrchild mtinfo retval sf txtht ) ;;get the current value of DIMSTYLE (setq dimsty (getvar "DIMSTYLE")) ;;; account for the possibility that the current style is a child style (if (= (substr dimsty (- (strlen dimsty) 1) 1) "$") (setq dimsty (substr dimsty 1 (- (strlen dimsty) 2))));it's a child style ;;now check to see if a leader child exists (if (setq childent (tblsearch "DIMSTYLE" (strcat dimsty "$7"))) (setq ldrchild (strcat dimsty "$7")) (setq ldrchild dimsty);no leader child exists, so use parent style ) (setq txtht (cdr (assoc 140 childent));get text height for associated text dimscl (cdr (assoc 40 childent)));get dimension scale of current style ;;find out where we are and calculate appropriate scale factor (cond ((= 1 (getvar "TILEMODE")) (setq sf dimscl case "TILED"));tiled space ((= 1 (getvar "CVPORT")) (setq sf 1.0 case "PAPER"));in paper space ;; in a viewport (T (if (= dimscl 0) (setq sf (last (trans '(0 0 1.0) 3 2)) case "VPORT");calc scale factor (setq sf dimscl case "VPORT");use dimscale of current style if not zero ) );end default );end cond ;;deal with nonsense case of zero DIMSCALE in TILEMODE=1 (if(and(= 0 sf)(= case "TILED")) (setq retval -1)) ;;if the above did not happen, (if (null retval) ;;process the selection set (progn ;;initialize entity counter & get length of selection set (setq i 0.0 retval (sslength ss)) ;;process the selection set (repeat retval (setq ldinfo (entget(ssname ss i)) dstyle (cdr (assoc 3 ldinfo)) );setq ;;update the leader DIMSTYLE to the current leader child style ;;or parent style, if no leader child exists (if (/= dstyle ldrchild) (entmod (subst (cons 3 ldrchild) (assoc 3 ldinfo) ldinfo)) ) ;;remove all existing DIMSTYLE overrides ;;in R14, the following will reset DIMSTYLE to a leader child, w/ overrides! ;;this appears to be anomalous behaviour of DIMOVERRIDE (command "_.DIMOVERRIDE" "CLEAR" (cdr (assoc -1 ldinfo)) "");resets DIMSTYLE (command "_.DIMSTYLE" "RESTORE" dimsty);so set it back the way we want it ;;;if the leader has associated MTEXT, scale the text (if (setq mtinfo (entget(cdr (assoc 340 ldinfo)))) (entmod (subst (cons 40 (* sf txtht)) (assoc 40 mtinfo) mtinfo)) ) (setq i (1+ i)) );repeat );progn );if retval );ldrupd (command "_.UNDO" "BEGIN") (setq oldeko (getvar "CMDECHO")) (setvar "CMDECHO" 0) (prompt "\nSelect Leaders to Update:") (if(setq ldrss (ssget '((0 . "LEADER")))) (setq #ent (ldrupd ldrss)) (setq #ent 0) ) (command "_.UNDO" "END") (setvar "CMDECHO" oldeko) (if (minusp #ent) (alert " Zero Dimension Scale! Set Tilemode = 0, \n or Use a Non-Zero Dimension Scale") (princ (strcat "\n" (itoa #ent) (sing_pl " Leader" #ent) " updated.")) );if (princ) ) ;end C:LDRUPD (princ "\nLDRUPD © 2000 by Herman Mayfarth") (princ "\nType LDRUPD to Run.") (princ)