Author Topic: square ft to watts  (Read 3904 times)

0 Members and 1 Guest are viewing this topic.

Royalchill

  • Guest
square ft to watts
« on: December 13, 2005, 03:15:30 PM »
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

  • Guest
Re: square ft to watts
« Reply #1 on: December 13, 2005, 03:29:21 PM »
Code: [Select]
(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)
)



Royalchill

  • Guest
Re: square ft to watts
« Reply #2 on: December 13, 2005, 03:47:10 PM »
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

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: square ft to watts
« Reply #3 on: December 13, 2005, 04:16:26 PM »
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: [Select]
(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))
      )
    )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Royalchill

  • Guest
Re: square ft to watts
« Reply #4 on: December 14, 2005, 07:25:31 AM »
Beautiful, two thumbs up. Thank you so much for sharing your talent.

hudster

  • Gator
  • Posts: 2848
Re: square ft to watts
« Reply #5 on: December 14, 2005, 07:38:30 AM »
I'm not that good at coding, but I do have some good ideas.

Would it be a good idea for the lisp to ask you to input the room type and then calculate the watts for you, save you having to remember the multipliers,.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Fatty

  • Guest
Re: square ft to watts
« Reply #6 on: December 14, 2005, 08:18:42 AM »
Hi Royalchill

I'm not sure about this routine anyway you could give it a try

Thank you

Fatty

Code: [Select]
(defun C:wat (/ cnt     head       head_string
      i mult_number        mult_string
      new_string patt     ss        tail   tmp_string
      txt_obj wat
     )
  (vl-load-com)
  (command "undo" "e")
  (command "undo" "g")
  (setq mult_string
(getstring
   "\nEnter multiplier in writing form <.09> : \n"
)
  )
  (if (eq "" mult_string)
    (progn
      (setq mult_string ".09")
      (setq mult_number
   (atof (strcat "0"
(chr 46)
(substr mult_string 3 1)
)
   )
    )
      )
      (progn
      (cond ((eq (substr mult_string 1 1) (chr 46))
     (cond ((not (eq (substr mult_string 2 1) "0"))
    (setq mult_number (atof (strcat "0" mult_string)))
   )
   (T
    (setq mult_number
   (atof (strcat "0"
(chr 46)
(substr mult_string 3 1)
)
   )
    )
   )
     )
    )
    (T (setq mult_number (atof mult_string)))
      )
    )
  )
  (prompt
    "\n\t***\tSelect all text you want to change \t*** \n"
  )
  (if
    (setq ss (ssget (list (cons 0 "TEXT") (cons 1 "*ft"))))
     (progn
       (setq i -1
     cnt 0
       )
       (repeat (sslength ss)
(setq txt_obj    (vlax-ename->vla-object (ssname ss (setq i (1+ i))))
       patt    (vla-get-textstring txt_obj)
       head_string ""
)
(while (not (eq " " (setq tmp_string (substr patt 1 1))))
   (setq head_string (strcat head_string tmp_string))
   (setq patt (substr patt 2 (strlen patt)))
)
(setq wat   (rtos (* (atoi head_string) mult_number) 2 1)
       tail   (strcat wat " " "watts")
       head   (strcat head_string "x" mult_string "=")
       new_string (strcat head tail)
)
(vla-put-textstring txt_obj new_string)
(vla-update txt_obj)
(vlax-release-object txt_obj)
(setq cnt (1+ cnt))
       )
     )
  )
  (alert (strcat "\nThere are changed :\n
    \n" (itoa cnt)
" total"
)
  )
  (command "undo" "e")
  (princ)
)
(prompt "\n\t\t>>>\tType WAT to execute\t<<<\n")

Edited at 08:50:52 AM by Fatty
« Last Edit: December 14, 2005, 09:04:20 AM by Fatty »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: square ft to watts
« Reply #7 on: December 14, 2005, 08:21:30 AM »
Beautiful, two thumbs up. Thank you so much for sharing your talent.

You are welcome.
Peter & mark did all the hard work I just stirred the soup.  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: square ft to watts
« Reply #8 on: December 14, 2005, 08:23:46 AM »
I'm not that good at coding, but I do have some good ideas.

Would it be a good idea for the lisp to ask you to input the room type and then calculate the watts for you, save you having to remember the multipliers,.
Good idea, If Royalchill would post the list of rooms with the multipliers.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: square ft to watts
« Reply #9 on: December 14, 2005, 08:37:04 AM »
Fatty,
Nice routine but the problem is with the original text. It is not as you expected.
The actual text is "(2060.72 sqft)", so you see you can't assume the string ends with "ft"
That was the problem with Peters routine. The actual string criteria was not known we he
wrote his routine. Another note, the default should be 0.9 as RoyalChill made a typo I think.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Fatty

  • Guest
Re: square ft to watts
« Reply #10 on: December 14, 2005, 08:54:00 AM »
Fatty,
Nice routine but the problem is with the original text. It is not as you expected.
The actual text is "(2060.72 sqft)", so you see you can't assume the string ends with "ft"
That was the problem with Peters routine. The actual string criteria was not known we he
wrote his routine. Another note, the default should be 0.9 as RoyalChill made a typo I think.

Hi Alan

You are right as always,
I have misplaced again
Now I edited default string
Maybe it will work for Royalchill

Thank you

Oleg

Peter Jamtgaard

  • Guest
Re: square ft to watts
« Reply #11 on: December 14, 2005, 10:00:57 AM »
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.

I typed 2060.72 sqft into a piece of dtext onto a drawing and this routine converted it into 1854.6 watts without any problems. I couldn't recreate your error. It worked in every test case I could attempt.

Could you send me a copy of the file with one of the pieces of text in it. So at least I can find out why you had the trouble. The algorithm is perfectly straight forward, and I am a little perplexed why it wouldn't work

Peter

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: square ft to watts
« Reply #12 on: December 14, 2005, 10:11:16 AM »
Peter the parentheses are part of the actual text.

This  "(2060.72 sqft)" and not this  "2060.72 sqft"
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.