Code Red > AutoLISP (Vanilla / Visual)
square ft to watts
Royalchill:
I have acquired a lisp routine that will give the area of a room using a closed polyline and put the text into the drawing, example 100 sq ft. Now I need a separate lisp routine where i can pick the text 100 sq ft and then the routine would ask me to enter a multiplier like 1.4 or .09 and then enter the text on the drawing. example. 100 sq ft x .09 = 90 watts. the reason i need this is electrical energy code only allows so many watts per square foot now, and that number varies per type of room. Thanks for the help here.
Peter Jamtgaard:
--- Code: ---(defun C:Watts (/ intCount intPosition entSelection objSelection
sngMultiplier ssSelections strText)
(setq sngMultiplier (getdist "\nEnter Multiplier: ")
ssSelections (ssget (list (cons 0 "TEXT")))
)
(repeat (setq intCount (sslength ssSelections))
(setq intCount (1- intCount)
entSelection (ssname ssSelections intCOunt)
objSelection (vlax-ename->vla-object entSelection)
strText (vla-get-textstring objSelection)
intPosition (vl-string-search " " strText 0)
strText (strcat (rtos (* sngMultiplier (atof (substr strText 1 intPosition)))
2 1
)
" watts"
)
)
(vla-put-textstring objSelection strText)
)
(princ)
)
--- End code ---
Royalchill:
I tried to use your lisp. here is what it does. command watts (this works) enter multiplier (this works) select objects (this works) answer is 0.0 watts (wrong). When I select my square ft (2060.72 sqft) in this case, multiblied by .9 in this case, this answer comes out 0.0 watts. I tried this on a couple of numbers with the same result. I also did not want to replace the sqft number but add a new pice of text to the dwg. Hope this helps.
CAB:
How about this for a quick fix?
Mark's routine can be found here http://www.theswamp.org/forum/index.php?topic=3710.0
--- Code: ---(defun c:watts (/ intcount intposition entselection objselection sngmultiplier
ssselections strtext
)
(setq sngmultiplier (getdist "\nEnter Multiplier: ")
ssselections (ssget (list (cons 0 "TEXT")))
)
(repeat (setq intcount (sslength ssselections))
(setq intcount (1- intcount)
entselection (ssname ssselections intcount)
objselection (vlax-ename->vla-object entselection)
strtext (vla-get-textstring objselection)
)
(if (and (setq number (car (extract-nums strtext)))
(numberp number)
)
(progn
(setq strtext (strcat strtext " = "
(rtos (* sngmultiplier number) 2 1)
" watts"
)
)
(vla-put-textstring objselection strtext)
)
)
)
(princ)
)
(defun extract-nums (str / ; local functions
is-num is-char parselst ; local variables
cntr x str_lst new_lst lst_of_lst final_lst
)
;;; FUNCTION
;;; returns a list of reals from a given string
;;; function does _not_ check argument type
;;;
;;; example; given the string "one 12 two 22.3 three .55 four 2.255"
;;; the function would return (12.0 22.3 0.55 2.255)
;;;
;;; ARGUMENTS
;;; str = string
;;;
;;; USAGE
;;; (setq lst_of_reals (extract-nums "str"))
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright 2004 Mark S. Thomas
;;; mark_at_theswamp.org
;;;
;;; VERSION
;;; 1.0
;; returns T if 'n' falls between 48 and 57
;; ascii characters 0-9
(defun is-num (n)
(and (> n 47) (< n 58))
)
;; returns T if 'n' is _not_ between 48 and 57 or 46
;; all ascii characters other than 0-9 and '.'(dot/period)
(defun is-char (n)
(not (or (and (> n 47) (< n 58)) (= n 46)))
)
;; Stig Madsen
;; returns a list of lists delimited by 'delim'
;; example
;; given the list '(12 0 32 56 0 45) where '0' is the delimiter
;; (parselst 0 '(12 0 32 56 0 45))
;; return would be ((12)(32 56)(45))
(defun parselst (delim lst / l ll)
(while lst
(cond
((not (eq (car lst) delim))
(setq l (cons (car lst) l))
)
((setq ll (if l
(cons (reverse l) ll)
ll
)
l nil
)
)
)
(setq lst (cdr lst))
)
(reverse (if l
(cons (reverse l) ll)
ll
)
)
)
;; ================== main starts here =======================
(setq str_lst (vl-string->list str)
cntr 0
)
(while (setq x (nth cntr str_lst))
(cond
((= x 46) ; <dot>
(if (is-num (nth (1+ cntr) str_lst)) ; next n is a num
(setq new_lst (cons x new_lst))
)
)
((is-num x)
(setq new_lst (cons x new_lst))
(if (is-char (nth (1+ cntr) str_lst)) ; next n is not a num
(setq new_lst (cons 32 new_lst))
)
)
((= x 32) ; <space>
(if (is-num (nth (1+ cntr) str_lst)) ; next n is a num
(setq new_lst (cons x new_lst))
)
)
((= x 80) ; <P>
(if (is-num (nth (1+ cntr) str_lst))
(setq new_lst (cons 32 new_lst))
)
)
) ; cond
(setq cntr (1+ cntr))
) ; while
(if new_lst
(progn
(setq lst_of_lst (parselst 32 (reverse new_lst))
final_lst (mapcar 'atof (mapcar 'vl-list->string lst_of_lst))
)
)
)
)
--- End code ---
Royalchill:
Beautiful, two thumbs up. Thank you so much for sharing your talent.
Navigation
[0] Message Index
[#] Next page
Go to full version