;****************************************************************** ;Add.lsp 6/17/96 ;v1.01 7/2/96 fixed to use local variables ;v1.02 1/15/97 Cleaned up commented out code. Added more instructions. ;v1.03 5/12/00 sets LUPREC to 0 decimal places. Should improve to allow other values with 0 as default. ;***************************************************************** ;Add string lisp routine will take a selection of text and add the ;numbers together. ;Use: ;Select some stuff. All non-text items are ignored. Any numbers in ;the selected text will be added together. Select a text item to be ;updated. The selected text item will be replaced with the result of ;the addition. ; ;Note that the units command will affect the format of the results. ;If you get a number will a bunch of trailing 0's then change units ;to fix the problem. ; ; * Copyright 1996 by J. Marsden DeLapp * ;************************************************************* ;dxf function takes an integer dxf code & ent data list and ;returns the value for that dxf code. (defun dxf (code elist) (cdr (assoc code elist)) );defun ;************************************************************* ;ss1 - selection set ;n - number of items in selection set (counter) ;total - total of float numbers in selection set ;e - ; (defun C:Add ( / ed en et i n oluprec ss1 text1 total) (setq OLUPREC (getvar "LUPREC")) (setvar "LUPREC" 0);set precision to 0 decimal places (setq ss1 (ssget '((0 . "TEXT")))) ; Select objects, only text (if ss1 ; If any objects selected (progn (setq i 0 total 0 n (sslength ss1)); reset tot, set n to number of items (while (< i n) ; For each selected object... (setq text1 (cdr (assoc 1 (setq e (entget (ssname ss1 i)))))) (setq total (+ total (atof text1))) (setq i (1+ i)) ; increment counter );while );progn );if (princ "Total ") (princ total) (terpri) (setq en (car (entsel "\nSelect text to update to total")) ed (entget en) et (dxf 0 ed) ) (if (= et "TEXT") ; verify text was selected ;(rtos total 2) returns total formated as a string in decimal format ;substitute the new text for the old text... (progn (entmod (setq ed (subst (cons 1 (rtos total 2)) (assoc 1 ed) ed)) );entmod ) );if (setvar "LUPREC" oluprec);reset precision (princ) );defun (PRINC "\n ADD.LSP v1.03 Copyright (c) 1997-2000 by J. Marsden DeLapp")(princ)