# Thread: Electrical Panel Phase Balance Calculator LSP Lispertine

1. ## Electrical Panel Phase Balance Calculator LSP Lispertine

Registered forum members do not see this ad.

Okay, here's the deal. I need a LISP that calculates phase balance which is basically percent error between two numbers in the following form. However, we need it to take a selection and find the largest number, smallest number and make the following calculation, regardless of the numbers in the set.

(Big - Small)/Big * 100 = X.X%

Currently, we use an ADD.LSP which takes a selection and adds up the numbers. I am not familiar enough with the programming in order to take this relatively simple arithmetic and make it a working LSP.

I have attached the ADD command if anyone is able to do something like this.

It should work by making a selection, then prompting the user to select where to place the phase balance (By adjusting the selected text to the updated value X.X%).

2. In the image above. This program, if I can ever get it to work, would work by selecting all three numbers, hitting spacebar and then selecting the number next to phase balance, and then hitting spacebar again.

3. If you look in the lower right hand corner of the post you want to edit you should see the words Edit Post. Click on the phrase.

4. Originally Posted by ryankevin15
That option is not available to me.
Ah...the ten post minimum strikes again. Sorry.

5. Try this:
Code:
```(defun KGA_Conv_Pickset_To_ObjectList (ss / i ret)
(if ss
(repeat (setq i (sslength ss))
(setq ret (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) ret))
)
)
)

(defun c:PhaseBalance ( / ss numLst numMin numMax res trg)
(if
(and
(princ "\nSelect source entities: ")
(setq ss (ssget '((0 . "TEXT") (1 . "~*[~-.0-9]*") (1 . "~*`.*`.*") (1 . "~?*-*"))))
(setq trg (car (entsel "\nSelect target entity: ")))
(= "AcDbText" (vla-get-objectname (setq trg (vlax-ename->vla-object trg))))
)
(progn
(setq numLst
(mapcar
(KGA_Conv_Pickset_To_ObjectList ss)
)
)
(setq numMin (apply 'min numLst))
(setq numMax (apply 'max numLst))
;; Formula: (Big - Small)/Big * 100 = X.X%
(setq res (strcat (rtos (/ (- numMax numMin) numMax 0.01) 2 1) "%"))
(princ (strcat "\nPhase Balance: "  res))
(vla-put-textstring trg res)
)
)
(princ)
)```

6. Can you make one that takes a total wattage from a panel and divides it by 360 to find the amperage? I'd call it like 360 or something. Wow, still very amazed that you coded that!

7. Roy_043,

Could you potentially make a lisp that takes a value (total demand in Watts) and divide by 360 for 208V for total demand amps? Also, when using 480V we divide by 831. These two lisps will make things much quicker. And also, in the phase balance lips, is there any rounding applied to that value? Did you make the phase balance one yourself or just happened to already have it?

8. Registered forum members do not see this ad.

Originally Posted by ryankevin15
Roy_043,

Could you potentially make a lisp that takes a value (total demand in Watts) and divide by 360 for 208V for total demand amps? Also, when using 480V we divide by 831. These two lisps will make things much quicker. And also, in the phase balance lips, is there any rounding applied to that value? Did you make the phase balance one yourself or just happened to already have it?
If you just want to change the decimal place accuracy of the output, take a look at the RTOS function in Roy_043's code.

http://ronleigh.com/autolisp/afude12.htm#rtos