Jump to content

Voltage drop calculator lisp - help


Eslam mansour

Recommended Posts

3 hours ago, Eslam mansour said:

 

Still cannot open the drawing as it is saved in a version later than 2010. That aside here is attempt 2. It incorporated @BIGAL's Multi Getvals function to collect connected devices. I'm still not sure of exactly how you want this to run. The lisp will loop asking for a polyline/line selection. It then askes for connected devices for that line before returning for another polyline. Once you have finished select a blank area of the screen for the polyline and it will proceed to the alert. This will be a total of all lines selected.

 

(defun AH:getvalsm (dcllst / x y num fo fname keynum key_lst v_lst)
  (setq num (/ (- (length dcllst) 1) 4))
  (setq x 0)
  (setq y 0)
  (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
  (write-line "ddgetvalAH : dialog {" fo)
  (write-line (strcat " label =" (chr 34) (nth 0 dcllst) (chr 34) " ;") fo)
  (write-line " : column {" fo)
  (repeat num
    (write-line "spacer_1 ;" fo)
    (write-line ": edit_box {" fo)
    (setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
    (write-line (strcat "    key = " (chr 34) keynum (chr 34) ";") fo)
    (write-line (strcat " label = " (chr 34) (nth (+ x 1) dcllst) (chr 34) ";") fo)
    (write-line (strcat "     edit_width = " (rtos (nth (+ x 2) dcllst) 2 0) ";") fo)
    (write-line (strcat "     edit_limit = " (rtos (nth (+ x 3) dcllst) 2 0) ";") fo)
    (write-line "   is_enabled = true ;" fo)
    (write-line "    }" fo)
    (setq x (+ x 4))
  )
  (write-line "    }" fo)
  (write-line "spacer_1 ;" fo)
  (write-line "ok_only;}" fo)
  (close fo)

  (setq dcl_id (load_dialog fname))
  (if (not (new_dialog "ddgetvalAH" dcl_id))
    (exit)
  )
  (setq x 0)
  (setq y 0)
  (setq v_lst '())
  (repeat num
    (setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
    (setq key_lst (cons keynum key_lst))
    (set_tile keynum (nth (setq x (+ x 4)) dcllst))
    (mode_tile keynum 3)
  )
  (action_tile "accept" "(mapcar '(lambda (x) (setq v_lst (cons (get_tile x) v_lst))) key_lst)(done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete fname)

  (princ v_lst)
)

(vl-load-com)

(defun c:vdrop ( / *error* sv_lst sv_vals iu sv RL vd len cu sel p_len I obj ans ld )

  (defun *error* ( msg )
    (mapcar 'setvar sv_lst sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : ( " msg " ) occurred.")))
    (princ)
  );end_*error*_defun

  (setq sv_lst (list 'osmode 'cmdecho 'dimzin)
        sv_vals (mapcar 'getvar sv_lst)
        iu (getvar 'insunits)
  );end_setq

  (mapcar 'setvar sv_lst (list 0 0 8))

  (setq sv 24.0 RL 0.015 vd 0.0 len 0.0)

  (cond ( (= iu 4) (setq cu 1000.0))
        ( (= iu 5) (setq cu 100.0))
        ( (= iu 6) (setq cu 1.0))
  );end_cond

  (prompt "\nSelect Polyline : ")

  (while (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE,POLYLINE,LINE"))))
    (setq p_len nil
          I 0.0
          obj (vlax-ename->vla-object (ssname sel 0))
          p_len (vlax-get obj 'length)
          sel nil
          ans (AH:getvalsm (list "Enter Quantities for Line" "   Lamp" 2 2 "0" "   Heater" 2 2 "0" "   Socket" 2 2 "0" "   TV" 2 2 "0" "   Motor" 2 2 "0" ))
    );end_setq

    (mapcar '(lambda (x y) (setq I (+ (* (atof x) y) I))) ans '(4.5 8.3 5.11 3.2 10.06))

    (if (and p_len I) (setq vd (+ vd (* RL I (/ p_len cu)))))

    (setq len (+ len (/ p_len cu)))
    (prompt "\nSelect Polyline : ")
  );end_while

  (setq ld (- sv vd))
  (alert (strcat "Constant Voltage           :  " (rtos sv 2 0) "\n\n"
                 "Total Line Lengths (m)  :  " (rtos len 2 3) "\n\n"
                 "Total Voltage Drop         :  " (rtos vd 2 6) "\n\n"
                 "Voltage @ Last Device   :  " (rtos ld 2 6)
          );end_strcat
  );end_alert

  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

 

Link to comment
Share on other sites

1 hour ago, dlanorh said:

 

Still cannot open the drawing as it is saved in a version later than 2010. That aside here is attempt 2. It incorporated @BIGAL's Multi Getvals function to collect connected devices. I'm still not sure of exactly how you want this to run. The lisp will loop asking for a polyline/line selection. It then askes for connected devices for that line before returning for another polyline. Once you have finished select a blank area of the screen for the polyline and it will proceed to the alert. This will be a total of all lines selected.

 


(defun AH:getvalsm (dcllst / x y num fo fname keynum key_lst v_lst)
  (setq num (/ (- (length dcllst) 1) 4))
  (setq x 0)
  (setq y 0)
  (setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
  (write-line "ddgetvalAH : dialog {" fo)
  (write-line (strcat " label =" (chr 34) (nth 0 dcllst) (chr 34) " ;") fo)
  (write-line " : column {" fo)
  (repeat num
    (write-line "spacer_1 ;" fo)
    (write-line ": edit_box {" fo)
    (setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
    (write-line (strcat "    key = " (chr 34) keynum (chr 34) ";") fo)
    (write-line (strcat " label = " (chr 34) (nth (+ x 1) dcllst) (chr 34) ";") fo)
    (write-line (strcat "     edit_width = " (rtos (nth (+ x 2) dcllst) 2 0) ";") fo)
    (write-line (strcat "     edit_limit = " (rtos (nth (+ x 3) dcllst) 2 0) ";") fo)
    (write-line "   is_enabled = true ;" fo)
    (write-line "    }" fo)
    (setq x (+ x 4))
  )
  (write-line "    }" fo)
  (write-line "spacer_1 ;" fo)
  (write-line "ok_only;}" fo)
  (close fo)

  (setq dcl_id (load_dialog fname))
  (if (not (new_dialog "ddgetvalAH" dcl_id))
    (exit)
  )
  (setq x 0)
  (setq y 0)
  (setq v_lst '())
  (repeat num
    (setq keynum (strcat "key" (rtos (setq y (+ Y 1)) 2 0)))
    (setq key_lst (cons keynum key_lst))
    (set_tile keynum (nth (setq x (+ x 4)) dcllst))
    (mode_tile keynum 3)
  )
  (action_tile "accept" "(mapcar '(lambda (x) (setq v_lst (cons (get_tile x) v_lst))) key_lst)(done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete fname)

  (princ v_lst)
)

(vl-load-com)

(defun c:vdrop ( / *error* sv_lst sv_vals iu sv RL vd len cu sel p_len I obj ans ld )

  (defun *error* ( msg )
    (mapcar 'setvar sv_lst sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : ( " msg " ) occurred.")))
    (princ)
  );end_*error*_defun

  (setq sv_lst (list 'osmode 'cmdecho 'dimzin)
        sv_vals (mapcar 'getvar sv_lst)
        iu (getvar 'insunits)
  );end_setq

  (mapcar 'setvar sv_lst (list 0 0 8))

  (setq sv 24.0 RL 0.015 vd 0.0 len 0.0)

  (cond ( (= iu 4) (setq cu 1000.0))
        ( (= iu 5) (setq cu 100.0))
        ( (= iu 6) (setq cu 1.0))
  );end_cond

  (prompt "\nSelect Polyline : ")

  (while (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE,POLYLINE,LINE"))))
    (setq p_len nil
          I 0.0
          obj (vlax-ename->vla-object (ssname sel 0))
          p_len (vlax-get obj 'length)
          sel nil
          ans (AH:getvalsm (list "Enter Quantities for Line" "   Lamp" 2 2 "0" "   Heater" 2 2 "0" "   Socket" 2 2 "0" "   TV" 2 2 "0" "   Motor" 2 2 "0" ))
    );end_setq

    (mapcar '(lambda (x y) (setq I (+ (* (atof x) y) I))) ans '(4.5 8.3 5.11 3.2 10.06))

    (if (and p_len I) (setq vd (+ vd (* RL I (/ p_len cu)))))

    (setq len (+ len (/ p_len cu)))
    (prompt "\nSelect Polyline : ")
  );end_while

  (setq ld (- sv vd))
  (alert (strcat "Constant Voltage           :  " (rtos sv 2 0) "\n\n"
                 "Total Line Lengths (m)  :  " (rtos len 2 3) "\n\n"
                 "Total Voltage Drop         :  " (rtos vd 2 6) "\n\n"
                 "Voltage @ Last Device   :  " (rtos ld 2 6)
          );end_strcat
  );end_alert

  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

 

I save it in 2007 autocad

Drawing2.dwg

Link to comment
Share on other sites

vdrop3.lsp

6 hours ago, Eslam mansour said:

I save it in 2007 autocad

Drawing2.dwg 93.59 kB · 1 download

 

Excellent. Attached is the third iteration of the lisp. I have returned and improved on version 1. This produces the an Autocad Table. You are asked to select a Polyline/Line, and then the list of electrical items appears to allow you to select the next item type (default is "LAMP"). You can then continue to select Polylines/Lines and items until you reach the end. Select a blank area of the screen to quit the selection process and you will be prompted for an insertion point for the table. The lisp will then insert a table as per your example drawing. The only difference will be that the text in the table will be in the current text style (not calibri unless you create one).

 

vdrop3.lsp

samplevdrop.dwg

Edited by dlanorh
forgot to attach dwg
Link to comment
Share on other sites

For any one Multi getvals image does not need alantest.dcl. BUT dcl uses slides so make use MSLIDE to make image.

 

Eslam don't worry about Multi getvals image for now.

Edited by BIGAL
Link to comment
Share on other sites

15 hours ago, dlanorh said:

vdrop3.lsp 5.26 kB · 1 download

 

Excellent. Attached is the third iteration of the lisp. I have returned and improved on version 1. This produces the an Autocad Table. You are asked to select a Polyline/Line, and then the list of electrical items appears to allow you to select the next item type (default is "LAMP"). You can then continue to select Polylines/Lines and items until you reach the end. Select a blank area of the screen to quit the selection process and you will be prompted for an insertion point for the table. The lisp will then insert a table as per your example drawing. The only difference will be that the text in the table will be in the current text style (not calibri unless you create one).

 

vdrop3.lsp 5.26 kB · 1 download

samplevdrop.dwg 107.11 kB · 0 downloads

Thank you very much for your interest ^_^

It is perfect work ^^

Link to comment
Share on other sites

12 hours ago, BIGAL said:

For any one Multi getvals image does not need alantest.dcl. BUT dcl uses slides so make use MSLIDE to make image.

 

Eslam don't worry about Multi getvals image for now.

Thank you very much for your interest  Mr. BIGAL ^_^

Link to comment
Share on other sites

  • 1 year later...

Hello all! I currently design low voltage systems (fire alarm, access control, cameras, etc.). I am looking for something similar to this lisp to help with tedious voltage drop calculations without having to use slow online calculators from manufacturers. I am new to lisps and this may be way too much to ask for help with, so I apologize if so. 

The formula I use is as follows:


((Distance (ft.) x 2) / 1000) x (User Defined Wire Resistance in Ohms (Ω)) x (Current draw of all appliances in circuit (V)) = Volts (V) dropped at Device1 from output source    

 

AND 

 

(User defined terminal cut-off voltage (V)) - (Volts dropped at Device1 from output source (V)) = Voltage available at Device1 (V)


There is a great example of a 4 device circuit here > http://www.firealarmsonline.com/2019/04/voltage-drop-for-fire-alarm-circuits.html
See "Point to Point Voltage Drop Calculation Break Down" towards the bottom of the page.


Ideally the flow would look something like this:

 

input command > prompt for circuit number (there are typically multiple circuits per project) > prompt for user input for wire resistance (Ω)  > prompt asking to choose between "Control Panel" or "Power Supply" (this is where the circuit originates and is for information only) > Click on first dynamic block for source (either control panel or power supply symbol) and input starting terminal cut-off voltage > Click on first polyline connecting devices (automatically input this wire distance) > Click on next devices in circuit and input device number and device's current draw (Amps) > Continue this until end of line is reached > click or type "EOL" and either be able to place table/ text with calculations, or output calculations in command line to copy & paste.

 

I would like output to display:


-Power Source (either "Control Panel" or "Power Supply") > Starting terminal cut off voltage
-Circuit # > Device # > Current draw of device > Distance from previous device > voltage dropped and voltage available at each device 
-Line below last calculation = "EOL" (indicates end of circuit)

Again, this may be way more complex than I understand as I am new to coding and lisps, so please go easy on me if so. I truly appreciate any help anybody has to offer as this will save me hours on projects. 


I will also attach an example output from a manufacturer calculator.

InkedVolt Drop Calc Example_LI.jpg

Link to comment
Share on other sites

So to help you along the way, how far can you get with making up this LISP, doing it is of course the best way to learn.....

 

Most of the volt drop work is just sums, I am guessing that the part you are struggling with is getting the inputs you want from your drawing into the LISP to do the calculations with?

 

It's OK if you know absolutely nothing - people on here will guide you along the way, but where are we starting from....

Link to comment
Share on other sites

1 hour ago, Steven P said:

So to help you along the way, how far can you get with making up this LISP, doing it is of course the best way to learn.....

 

Most of the volt drop work is just sums, I am guessing that the part you are struggling with is getting the inputs you want from your drawing into the LISP to do the calculations with?

 

It's OK if you know absolutely nothing - people on here will guide you along the way, but where are we starting from....

 

Thanks for the response. To be completely honest, I know absolutely nothing about writing LISPs or coding in general. I just upgraded from LT and I am extremely excited to be able to use them. I'd love to learn to write my own. For this one, we would be starting from scratch. 

Link to comment
Share on other sites

Something like this

 

This is a line by line as if typing and adding each * / last line is the one actually used

((Distance (ft.) x 2) / 1000) x (User Defined Wire Resistance in Ohms (Ω)) x (Current draw of all appliances in circuit (V)) = Volts (V) dropped at D

(setq drop (* dist 2.0))
(setq drop (/ (* dist 2.0) 1000.0))
(setq drop (* res(/ (* dist 2.0) 1000.0)))

(setq drop (* totcurrent (* res(/ (* dist 2.0) 1000.0))))

Ok but need totcurrent which would be total of the current draw maybe from selecting a block/s.

 

Do you just want a answer ? Then pick a AWG. There is no elec code backing this its an example of a answer choice.

 

image.png.f3df9568af4d772435957ff58c30cc61.png

 

You need to post more info.

 

Edited by BIGAL
  • Thanks 1
Link to comment
Share on other sites

27 minutes ago, BIGAL said:

You need to post more info.

 

I was going to ask the same later, if you have an example drawing, which can be simple, 1 or 2 circuits, obviously no customer specific data, the LISP on this thread can be changed about I am sure to suit what you do

 

Link to comment
Share on other sites

6 hours ago, BIGAL said:

Something like this

 


This is a line by line as if typing and adding each * / last line is the one actually used

((Distance (ft.) x 2) / 1000) x (User Defined Wire Resistance in Ohms (Ω)) x (Current draw of all appliances in circuit (V)) = Volts (V) dropped at D

(setq drop (* dist 2.0))
(setq drop (/ (* dist 2.0) 1000.0))
(setq drop (* res(/ (* dist 2.0) 1000.0)))

(setq drop (* totcurrent (* res(/ (* dist 2.0) 1000.0))))

Ok but need totcurrent which would be total of the current draw maybe from selecting a block/s.

 

Do you just want a answer ? Then pick a AWG. There is no elec code backing this its an example of a answer choice.

 

image.png.f3df9568af4d772435957ff58c30cc61.png

 

You need to post more info.

 

 

Thank you for typing out line by line like this. I can start to see how you got to the last line. Total current could very well be calculated from selecting blocks. Maybe click the block and input current draw, click the next and input ect.. until the last one in the circuit , to get total. The inspectors like to see a breakdown similar to the one I attached in my initial post as far as device number, current draw of that device, distance between devices, and voltage available at the end of the circuit.

 

5 hours ago, Steven P said:

 

I was going to ask the same later, if you have an example drawing, which can be simple, 1 or 2 circuits, obviously no customer specific data, the LISP on this thread can be changed about I am sure to suit what you do

 

 

I have attached an extremely simple example. I tried to break it down the best I could, but please let me know if there is any data I left out that would help clarify.

 

Thanks again to you both!

 

 

 

CIRCUITS_EXAMPLE.pdf

Link to comment
Share on other sites

You can make a acad table with your results as per the excel example as part of the calcs.

 

The 1st suggestion is make the mtext values attributes to the blocks,

image.png.c30bef653463b18d0d22ec520bfcf8b0.png

then just do

pick block, pick line "length"

pick block, pick line "length"

pick block, pick line "length"

pick block, pick line "length"

do calcs

 

Make the blocks and submit dwg again, then people can help.

Link to comment
Share on other sites

I'd also tend to go for blocks  and attributes if you are inserting the same thing over and over. You can use the mtext and I think so long as it always follows a similar formatting for all the devices (name of device on top line, current draw in second line) you can strip out what you need... but that takes a little more work and effort.

 

I had some thoughts on what could be done last nigh but would need to check if I am right today sometime

Link to comment
Share on other sites

22 hours ago, BIGAL said:

You can make a acad table with your results as per the excel example as part of the calcs.

 

The 1st suggestion is make the mtext values attributes to the blocks,

image.png.c30bef653463b18d0d22ec520bfcf8b0.png

then just do

pick block, pick line "length"

pick block, pick line "length"

pick block, pick line "length"

pick block, pick line "length"

do calcs

 

Make the blocks and submit dwg again, then people can help.

 

13 hours ago, Steven P said:

I'd also tend to go for blocks  and attributes if you are inserting the same thing over and over. You can use the mtext and I think so long as it always follows a similar formatting for all the devices (name of device on top line, current draw in second line) you can strip out what you need... but that takes a little more work and effort.

 

I had some thoughts on what could be done last nigh but would need to check if I am right today sometime

 

I went ahead and attempted to add attribute values to each visibility state in the block. I don't have much experience with attributes or tables, so I hope I did this correctly. I have posted the block below; it's a very simplified version of what you are describing Steven. I would have to be able to add/modify these states & attributes to the block as needed, as we don't always use the same devices. We do 95% of the time, but there are rare occasions where things are on back-order and need replaced to get the job completed on time. The FACP and Power Supply states would always have to be selected first as the starting voltage. I like your idea BIGAL; run command > click power source to start, line, device, line device etc.

 

 

11 hours ago, SLW210 said:

IIRC, the AutoCAD Electrical Toolset has voltage drop. They took away my full 64-bit MS Office so I no longer have access to check.

 

I wasn't aware of that. I will have to look into it.

FIRE_BLOCK_10.8.21.dwg

Link to comment
Share on other sites

You could try this and see what you think, the prompts in the command line should guide you. the output is a table of mtexts.

 

 

You mentioned doing a recalculation if the selected wire gauge isn't quite right - that should be easy to do but for another day maybe

 

As always if anyone wants to rip the LISP to pieces and let me know a better way to do things, always appreciated.

 

So try this as a start, command is vdcalc

 

;;;Building Blocks copied from other stuff;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;http://www.turvill.com/t2/free_stuff/tlen.lsp
;;TLEN Sum line lengths
(defun TLEN (/ ss tl n ent itm obj l)  ;;;-GETS TOTAL LENGTH OF SELECTED LINES, POLYLINES AND SO ON-;;;
  (setq ss (ssget '((-4 . "<OR")(0 . "LINE")(0 . "LWPOLYLINE")(0 . "ELLIPSE")(0 . "LWPOLYLINE")(0 . "SPLINE")(-4 . "OR>")) )
        tl 0
        n (1- (sslength ss))
  )
  (while (>= n 0)
    (setq ent (entget (setq itm (ssname ss n)))
          obj (cdr (assoc 0 ent))
          l (cond
              ((= obj "LINE")
                (distance (cdr (assoc 10 ent))(cdr (assoc 11 ent))))
              ((= obj "ARC")
                (* (cdr (assoc 40 ent))
                   (if (minusp (setq l (- (cdr (assoc 51 ent))
                                          (cdr (assoc 50 ent)))))
                     (+ pi pi l) l)))
              ((or (= obj "CIRCLE")(= obj "SPLINE")(= obj "POLYLINE")
                   (= obj "LWPOLYLINE")(= obj "ELLIPSE"))
                (command "_.area" "_o" itm)
                (getvar "perimeter"))
              (T 0))
          tl (+ tl l)
          n (1- n)
    )
  )
  tl ;;returns tl, total length
)

(defun getfroment (ent listorstring entcodes / acount acounter mytext newtext stringtext)
;;;-Gets text string from a selected entity (text, mtext, block, dimension etc)-;;;
;;;-It won't remove formatting codes in for example mtexts.. which is why output table is mtexts....-;;;
  ;;get dotted pairs list
  (setq entlist (entget ent))
  (setq acount 0)
  (while (< acount (length entlist))
    (setq acounter 0)
    (while (< acounter (length entcodes))
      (setq entcode (nth acounter entcodes))
      (if (= (car (nth acount entlist)) entcode )
        (progn
          (setq newtext (cdr (nth acount entlist)))
          (if (numberp newtext)(setq newtext (rtos newtext))) ;fix for real numbers
           (setq mytext (append mytext (list (cons (car (nth acount entlist)) newtext) )) )
        );end progn
      );end if
      (setq acounter (+ acounter 1))
    );end while
    (setq acount (+ acount 1))
  );end while
  ;;get string from dotted pair lists
  (if (= listorstring "astring") ;convert to text
    (progn
      (if (> (length mytext) 0)
        (progn
          (setq acount 0)
          (setq temptext "")
          (while (< acount (length mytext))
            (setq temptext (cdr (nth acount mytext)) )
            (if (= stringtext nil)
              (setq stringtext temptext)
              (setq stringtext (strcat stringtext temptext ))
            );end if
            (setq acount (+ acount 1))
          );end while
        );end progn
      );end if
      (if (= stringtext nil)(setq stringtext ""))
      (setq mytext stringtext)
    );end progn
  );end if
  mytext
)

;;get text
  (defun gettext( message / ent1 entlist1 entcodes1 text01)
  (setq ent1 (getent message))
  (setq entlist1 (entget ent1))
  (setq entcodes1 (list 3 4 1 172 304) ) ;list of ent codes containing text.
  (if (= (cdr (assoc 0 entlist1)) "DIMENSION") (setq entcodes1 (list 4 1 172 304) )) ;;if dimension
  (setq text01 (getfroment ent1 "astring" entcodes1) ) ;Text as string
  text01
)

;;;;end of building blocks;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Only does loop for a single circuit
(defun c:vdcalc( / mysource mystartvolts mycircuitname wireresistances mywiresize mycircuit mydevice mydevicecurrent nomuttvar linelengths acount nextdevice circuitcount myresults drop totvd)

;;initial conditions. Note no error checking and so on.
  (setq circuitcount 1)
  (setq acount 1)
  (setq nextdevice "Y")
  (setq mycircuit (list (list "Circuit Name" "From" "Circuit Volts" "Wire Size" "Circuit Length" "To" "Device Current" "Volt Drop" "End volts")) )
  (setq totcurrent 0)
  (setq wireresistances (list (cons 12 2.01) (cons 14 3.19) (cons 16 5.08) (cons 18 8.08) (cons 22 16.14)))

;;Set up system details
  (setq mysource (gettext "\nSelect Panel Name"))
  (setq mystartvolts (getreal "\nEnter Supply Terminal Volts "))
;;;- see below for mywiresize if you want to limit circuit voltage to a set amount how to do that-;;;

;;circuit details
  (setq mycircuitname (getstring t "\nEnter Circuit Name/Number "))

;;;-wire sizes-;;;
;;;-assumes same wire size for the circuit-;;;
  (initget "12 14 16 18 22")
  (setq mywiresize (atof (getkword "\nEnter Circuit Wire Gauge [12/14/16/18/22] "))) ;;getkword so initget works

;;Loop for circuit
  (while (= nextdevice "Y")
    (setq nomuttvar (getvar "nomutt"))
    (princ (strcat "\nSelect Lines, to device " (rtos acount 2 0) ", then press enter " ))(setvar "nomutt" 1)
    (setq linelengths (tlen))
    (setvar "nomutt" nomuttvar)
    (setq mydevice (gettext (strcat "\nSelect device " (rtos acount 2 0) " name")))
    (setq mydevicecurrent (getreal "\nEnter Current Draw: ") )
    (setq totcurrent (+ totcurrent mydevicecurrent ))
    (setq mycircuit (append mycircuit
      (list (list mycircuitname mysource (rtos mystartvolts 2 2) (rtos mywiresize 2 0) (rtos linelengths) mydevice (rtos mydevicecurrent 2 3) ))
    ))

    (initget "Y N YES NO")
    (setq nextdevice (strcase (getstring "\nSelect another device [Y/N]")) )
    (setq acount (+ acount 1))
  )

  (setq myresults (list (nth 0 mycircuit)))
  (setq acount 1)
  (setq totvd 0)
  (while (< acount (length mycircuit))
    (setq res (cdr (assoc (atof (nth 3 (nth acount mycircuit))) wireresistances) ))
    (setq dist (atof (nth 4 (nth acount mycircuit))))

;;;-Calculation-;;;
;;;-from BigAl-;;;
    (setq drop (* totcurrent (* res (/ (* dist 2.0) 1000.0))))

    (setq totvd (+ totvd drop))
    (setq endvolts (- (atof (nth 2 (nth acount mycircuit))) totvd) )
    (setq myresults (append myresults (list (append (nth acount mycircuit) (list (rtos drop 2 3)) (list (rtos endvolts 2 3))) )))
    (setq acount (+ acount 1))
  )
  (setq myresults (append myresults
      (list (list "" "" "" "" "" "" "Total Volt Drop:" (rtos totvd) ))
    ))



;;Make up a table - just mtext, nothing fancy
  (setq pt (getpoint "Enter table Insertion Point"))
  (setq pt1 pt)
  (setq acount 0)
  (while (< acount (length myresults))
    (setq acounter 0)
    (while (< acounter (length (nth acount myresults)) )
      (entmakex (list
        (cons 0   "MTEXT")         
        (cons 100 "AcDbEntity")          
        (cons 100 "AcDbMText")    
        (cons 10 pt1)
        '(40 . 2.5)        
        (cons 1 (nth acounter (nth acount myresults)))
      ))
      (setq pt1 (list (+ (nth 0 pt1) 25) (nth 1 pt1) (nth 2 pt1)))
      (setq acounter (+ acounter 1))
  )
    (setq pt1 (list (nth 0 pt) (- (nth 1 pt1) 7.5) (nth 2 pt)))
    (setq acount (+ acount 1))
  )

  (princ)
)

 

  • Thanks 1
Link to comment
Share on other sites

if your blocks can have attributes for device name, and value (volt or current) then the above can be modified to select them instead of entering them via the keyboard

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...