ryankevin15 Posted April 25, 2017 Posted April 25, 2017 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. Quote
BKT Posted April 26, 2017 Posted April 26, 2017 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) ) Quote
BKT Posted April 27, 2017 Posted April 27, 2017 Cool. If it works for you, making one for 480 from it will be easy. Just change the name of the lisp and the "360" entry. Quote
ryankevin15 Posted April 27, 2017 Author Posted April 27, 2017 Works perfectly, made a 480V one. Can't thank you enough! Quote
ryankevin15 Posted April 28, 2017 Author Posted April 28, 2017 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. Quote
BKT Posted April 28, 2017 Posted April 28, 2017 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) ) Quote
ryankevin15 Posted April 28, 2017 Author Posted April 28, 2017 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? Quote
BKT Posted April 28, 2017 Posted April 28, 2017 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. Quote
BKT Posted May 1, 2017 Posted May 1, 2017 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) ) Quote
ryankevin15 Posted May 1, 2017 Author Posted May 1, 2017 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) Quote
Recommended Posts
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.