Jump to content

Demand Amps Lisp


ryankevin15

Recommended Posts

Hello, could someone make a .lsp for calculating demand amps similar to these two Lisps for adding numbers, and calculating phase balance percentage(%)?

 

They work by selecting a value, hitting space bar to execute the command and then selecting a destination piece of text for the calculation.

 

PhaseBalance.LSP

 

This .lsp would prompt for a demand wattage, and divide by 360 and then prompt the user for destination piece of text. I'd like the amperage to round up to the nearest tens.

 

Thank you in advance.

Link to comment
Share on other sites

Try this:

 

(defun c:208 (/ watts amps ent)

 (while (= watts nil)
   (setq watts (car (entsel "\nSelect Demand Watts: ")))
 )

(setq watts (cdr (assoc 1 (entget watts)))
     amps (rtos (/ (atof watts) 360) 2 1)
)

 (while (= ent nil)
   (setq ent (car (entsel "\nSelect Target Entity: ")))
 )

(setq ent (subst (cons 1 amps) (assoc 1 (entget ent)) (entget ent)))

(entmod ent)

(princ)

)

Link to comment
Share on other sites

Do you think you could make you lisp routine have a line of code where it shows the total in the command line after you divide by 360? After you use the ADD command it tells you the sum before you put it on the drawing.

Link to comment
Share on other sites

See if adding this code does what you need:

 

(defun c:208 (/ watts amps ent)

 (while (= watts nil)
   (setq watts (car (entsel "\nSelect Demand Watts: ")))
 )

(setq watts (cdr (assoc 1 (entget watts)))
     amps (rtos (/ (atof watts) 360) 2 1)
)

[color=red](princ (strcat "\nTOTAL DEMAND AMPS = " amps))[/color]

 (while (= ent nil)
   (setq ent (car (entsel "\nSelect Target Entity: ")))
 )

(setq ent (subst (cons 1 amps) (assoc 1 (entget ent)) (entget ent)))

(entmod ent)

(princ)

)

Link to comment
Share on other sites

Awesome! Also, if the user accidentally missed the text or selected a line, it seems like the add command will not exectute or exit until the user selects a number. Is this possible to make for these 208 and 480v ones?

Link to comment
Share on other sites

Right now, the code requires a selection of something, but doesn't exclude entities other than text. Lemme fiddle with it a bit and I'll get back to you.

 

Also, I made a new version that will allow you to enter either "208" or "480" after loading the program, so if you want to save a couple of steps in your process you can have that one instead.

Link to comment
Share on other sites

I combined some code to give you something else to try out:

 

(defun c:test (/ ss i n text1 total volts amps)

(initget 1 "208 480")
(setq volts (getkword "\nEnter Voltage < 208 / 480 > : "))

 (if (= volts "208")
   (setq volts 360)
   (setq volts 831)
 )

(setq ss (ssget '((0 . "TEXT")))
     i 0
     total 0
     n (sslength ss)
)

 (if ss
   (while (< i n)
     (setq text1 (cdr (assoc 1 (entget (ssname ss i)))))
     (setq total (+ total (atof text1)))
     (setq i (1+ i))
   )
 )

(princ (strcat "\nTOTAL WATTS = " (rtos total 2 0)))

(while (not (setq watts (car (entsel "\nUpdate TOTAL DEMAND WATTS: ")))))
(setq watts (entget watts))
 (if (eq (cdr (assoc 0 watts)) "TEXT")
   (entmod (setq watts (subst (cons 1 (rtos total 2 0)) (assoc 1 watts) watts)))
     (progn
       (princ "\nWrong Selection - Not Text!!")
       (exit)
     )
 )

(princ (strcat "\nTOTAL AMPS = " (rtos (/ total volts) 2 1)))

(while (not (setq amps (car (entsel "\nUpdate TOTAL DEMAND AMPS: ")))))
(setq amps (entget amps))
 (if (eq (cdr (assoc 0 amps)) "TEXT")
   (entmod (setq amps (subst (cons 1 (rtos (/ total volts) 2 1)) (assoc 1 amps) amps)))
     (progn
       (princ "\nWrong Selection - Not Text!!")
       (exit)
     )
 )

(princ)

)

Link to comment
Share on other sites

Honestly, I'd rather have the two separate, because it's just more to type out. Especially since most common systems are 208V. I just want it to be able to do the math with commas and also make sure that at least one piece of text was selected before executing the function.

 

Below is the add command that does both of these things. Hopefully it should be a matter of copying the code out from the right parts of this code.


;******************************************************************
;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 10/3/06 revised the program to work with numbers that include commas.
;v1.04 11/20/06 revised the program to stop adding zeros on the end.
;*****************************************************************
;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.
;
;*************************************************************
; below is the subroutine that removes the commas from the numbers and changes decimal points
; added by me

(defun comma ( / nc nt m tmp ntext )

 (setq nc 0)                   ;set counter to 0
 (setq m T)                    ;set m to true
 (setq ntext "")               ;blank out ntext
 (setq nt (strlen text1))      ;initalize counter (text1 from calling program)

 ; while loop test for ascii decimal point or number between 0 and 9 and eliminates none decimal or number char.

 (while m
   (setq nc (+ nc 1))
   (setq tmp (ascii (substr text1 nc 1)))
   (if (or (= tmp 46) (and (>= tmp 48) (<= tmp 57)))
     (setq ntext (strcat ntext (substr text1 nc 1)))
   )
   (if (= tmp 46)          ;this will adjust the decimal point to 1 if a decimal is present in the number.
     (setvar "luprec" 1)
   )
 (setq nt (- nt 1))
 (if (= nt 0) (setq m F))
 )

(setq text1 ntext)
)
ntext

;below is the original program
;end of by me


;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     -
;au    - current unit precision

(defun C:A ( / lu ed en et i n ss1 text1 total )

 ;added by me to remove the trailing zeros
 (setq lu (getvar "luprec")) ; save current precision
 (setvar "luprec" 0) ; set precision to 0


  (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))))))

           ;below is the subroutine call to remove the commas

           (comma)


           (setq total (+ total (atof text1)))
           (setq i (1+ i))          ; increment counter
        );while
     );progn
  );if
  (princ "Total ")
  (princ total)
  (terpri)
  (setq en (entsel "\nSelect text to update to total")
        ed  (entget (car 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" lu) ;return precision to it's original value
(princ)
);defun
(princ)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...