Jump to content

Condition statement not working properly


CHLUCFENG

Recommended Posts

I'm having trouble with a conditional statement. This code appears to do the math correctly, but it is supposed to return the minimum size conduit that I can use for the wire size entered.

 

For example...

 

Command: CCC

Enter phase 1 or 3: 1

Enter feeder size with # (pound) sign (ex:#4/0 or #250):  Feeder: #2

Enter ground size with # (pound) sign (ex:#4/0 or #250):  Ground: #6

 

Result:

Wire area 0.5238 is < 0.8200, use 1" conduit.

 

The math is correct for the wireArea @ 0.5238, but the conditional statement returns the < 0.8200 (which is for 1-1/2" conduit), and tells me to use 1" conduit (which should be 1-1/4" conduit since the wire area is greater than 0.3400 for 1" conduit, but less than 0.6000 for 1-1/4" conduit).

 

I have placed the result statement within a conditional phrase, for which I believe should evaluate the first correct (true) response, and ignore all others. I do not understand why am getting the text from the conditional statement prior to the true statement, then getting the conduit area value from the conditional statement after the true statement.

 

Hopefully this description makes sense. Perhaps the code will illustrate it better. Please let me know how I have goofed this code. Thanks.

 

(defun c:ccc (/ phse num fs gs wireArea cc) 

  (setq cc nil)

;;; conductor area

  (setq    #14  0.0206
    #12  0.0251
    #10  0.0311
    #8   0.0598
    #6   0.0819
    #4   0.1087
    #3   0.000001
    #2   0.1473
    #1   0.2027
    #1/0 0.2367
    #2/0 0.2781
    #3/0 0.3288
    #4/0 0.3904
    #250 0.4877
    #300 0.5581
    #350 0.6291
    #400 0.6969
    #500 0.8316
    #600 1.0261
    #750 1.2252
  )

;;; conduit usable area

  (setq    c0.5  0.1200
    c0.75 0.2100
    c1    0.3400
    c1.25 0.6000
    c1.5  0.8200
    c2    1.340
    c2.5  1.920
    c3    2.950
    c3.5  3.960
    c4    5.090
    c5    8.000
  )

;;; start program
  (setq phse (getint "\nEnter phase 1 or 3: "))
  (if (= phse 1)
    (setq num 3)
    ;;else
    (setq num 4)
  )
  (setq fs (getstring "\nEnter feeder size with # (pound) sign (ex:#4/0 or #250):  Feeder: "))
  (setq gs (getstring "\nEnter ground size with # (pound) sign (ex:#4/0 or #250):  Ground: "))
  (if (or (= gs "")(= gs nil))
    (setq gs nil)
  )
  (if gs
    (setq wireArea (+ (* num (eval (read fs))) (eval (read gs))))
    ;;else
    (setq wireArea (* num (eval (read fs))))
  )
  (cond    ((< wireArea c0.5)
     (setq cc c0.5)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 1/2\" conduit."
        )
     )
    )
    ((< c0.5 wireArea c0.75)
     (setq cc c0.75)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 3/4\" conduit."
        )
     )
    )
    ((< c0.75 wireArea c1)
     (setq cc c1)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 1\" conduit."
        )
     )
    )
    ((< c1 wireArea c1.25)
     (setq cc c1.25)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 1-1/4\" conduit."
        )
     )
    )
    ((< c1.25 wireArea c1.5)
     (setq cc c1.5)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 1-1/2\" conduit."
        )
     )
    )
    ((< c1.5 wireArea c2)
     (setq cc c2)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 2\" conduit."
        )
     )
    )
    ((< c2 wireArea c2.5)
     (setq cc c2.5)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 2-1/2\" conduit."
        )
     )
    )
    ((< c2.5 wireArea c3)
     (setq cc c3)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 3\" conduit."
        )
     )
    )
    ((< c3 wireArea c3.5)
     (setq cc c3.5)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 3-1/2\" conduit."
        )
     )
    )
    ((< c3.5 wireArea c4)
     (setq cc c4)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 4\" conduit."
        )
     )
    )
    ((< c4 wireArea c5)
     (setq cc c5)
     (princ    (strcat    "\nWire area "
            (rtos wireArea 2 4)
            " is < "
            (rtos cc 2 4)
            ", use 5\" conduit."
        )
     )
    )
    (t nil)
  )
  (princ)
)                    ;end defun ccc


 

 

Link to comment
Share on other sites

Take the periods out of your variable names. FWIW an association list could simplify this quite a bit.


Command: CCC
Enter phase 1 or 3: 1
Enter feeder size with # (pound) sign (ex:#4/0 or #250):  Feeder: #2
Enter ground size with # (pound) sign (ex:#4/0 or #250):  Ground: #6
Wire area 0.5238 is < 0.6000, use 1-1/4" conduit.

 

  ;; OK
  (setq	c05  0.1200
	c075 0.2100
	c1   0.3400
	c125 0.6000
	c15  0.8200
	c2   1.340
	c25  1.920
	c3   2.950
	c35  3.960
	c4   5.090
	c5   8.000
  )
  ;; Command: !c125 0.6
  ;; Bad
  (setq	c0.5  0.1200
	c0.75 0.2100
	c1    0.3400
	c1.25 0.6000
	c1.5  0.8200
	c2    1.340
	c2.5  1.920
	c3    2.950
	c3.5  3.960
	c4    5.090
	c5    8.000
  )
  ;; Command: !c1.25 0.82

Or if you keep those variables, set them like so:

  (setq c0.5 0.1200)
  (setq c0.75 0.2100)
  (setq c1 0.3400)
  (setq c1.25 0.6000)
  ...

 

Edited by ronjonp
Link to comment
Share on other sites

Thanks ronjonp.

 

I didn't think the periods made that much  affect. Works properly now.

 

This was supposed to just be a quick and simple check routine, but you are correct, association lists may also work well with this.

 

Thanks again,

Chuck

Link to comment
Share on other sites

I am think more along the line of rather than setq's like Ronjonp use lists have a look at this uses Lee-mac listboxv1-2.lsp you can get from his website. You have lst2 which is area and using nth num lst2 as below returns the correct area. This saves the # part of strings as your pick list can have # as part of the string. I can hear use pairs in the lists but I have tried to provide a very simple example. 

 



(setq lst1 (list "c0.5"  "c1.0" "c1.25"  "c1.5" "c2.0"  "c2.5"  "c3.0" "c3.5" "c4.0" "c5.0" ) )
(setq lst2 (list 0.1200 0.2100 0.3400 0.6000 0.8200 1.340 1.920 2.950 3.960 5.090 8.000))
(if (not LM:listbox)(load "listboxV1-2"))
(setq num (nth 0 (LM:listbox "pick conduit size" lst1 2)))
(alert  (strcat "You have picked " (nth num lst1) " conduit size\n\nwith an area of " (rtos (nth num lst2) 2 3)))

 

Link to comment
Share on other sites

Maybe something like this:

(defun c:foo (/ keyword a b c d l l2 w x)
  ;; RJP » 2018-09-14
  (defun keyword (key options text default / *error* def vars)
    (defun *error* (msg)
      (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
      (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
	(princ (strcat "\nError: " msg))
      )
      (princ)
    )
    (or (setq def (getenv key)) (setq def default))
    (setq vars (mapcar '(lambda (x) (cons x (getvar x))) (list 'dynmode 'dynprompt)))
    (mapcar '(lambda (a b) (setvar (car a) b)) vars '(1 1))
    (initget options)
    (setq def
	   (cond
	     ((getkword	(strcat "\n" text ": [" (vl-string-translate " " "/" options) "] <" def ">:")
	      )
	     )
	     (def)
	   )
    )
    (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
    (setenv key def)
  )
  (setq	l '(("#14" 0.0206)
	    ("#12" 0.0251)
	    ("#10" 0.0311)
	    ("#8" 0.0598)
	    ("#6" 0.0819)
	    ("#4" 0.1087)
	    ("#3" 0.000001)
	    ("#2" 0.1473)
	    ("#1\\0" 0.2027)
	    ("#1\\0" 0.2367)
	    ("#2\\0" 0.2781)
	    ("#3\\0" 0.3288)
	    ("#4\\0" 0.3904)
	    ("#250" 0.4877)
	    ("#300" 0.5581)
	    ("#350" 0.6291)
	    ("#400" 0.6969)
	    ("#500" 0.8316)
	    ("#600" 1.0261)
	    ("#750" 1.2252)
	    ("none" 0)
	   )
  )
  ;; These ID's seem small? http://www.alliedeg.us/pvc/rigid-conduit/ Wouldn't it be better to use (/ ID 2.) ?
  (setq	l2 '(("0.5" 0.12)
	     ("0.75" 0.21)
	     ("1" 0.34)
	     ("1.25" 0.6)
	     ("1.5" 0.82)
	     ("2" 1.34)
	     ("2.5" 1.92)
	     ("3" 2.95)
	     ("3.5" 3.96)
	     ("4" 5.09)
	     ("5" 8.00)
	    )
  )
  (cond	((and (setq a (keyword "MyPipesPhase" "1 3" "Pick Phase" "1"))
	      (setq b (keyword "MyPipesFeeder"
			       (apply 'strcat (mapcar '(lambda (x) (strcat (car x) " ")) l))
			       "Pick feeder size"
			       (caar l)
		      )
	      )
	      (setq c (keyword "MyPipesGround"
			       (apply 'strcat (mapcar '(lambda (x) (strcat (car x) " ")) l))
			       "Pick ground size"
			       (caar l)
		      )
	      )
	 )
	 (setq w (+ (* (if (= a "1")
			 3
			 4
		       )
		       (cadr (assoc b l))
		    )
		    (cadr (assoc c l))
		 )
	 )
	 (setq d (car (vl-remove-if '(lambda (x) (>= w (cadr x))) l2)))
	 (alert	(strcat	"\nWire area: "
			(rtos w 2 4)
			" is < "
			(rtos (cadr d) 2 4)
			", use "
			(rtos (atof (car d)) 3 2)
			"\" conduit."
		)
	 )
	)
  )
  (princ)
)

 

2018-09-14_8-15-11.png

Edited by ronjonp
Link to comment
Share on other sites

Thanks BigAL, and WOW ronjonp.

 

You took a simple little program and really jazzed it up with dynmode. That is slick. I've never used that.

 

From the code:

;; These ID's seem small? http://www.alliedeg.us/pvc/rigid-conduit/ Wouldn't it be better to use (/ ID 2.) ?

As an FYI, in the NEC, Chapter 9, wire is only allowed to fill a percentage of the area inside the conduit. The numbers used in this program are already calculated for the maximum "useable" area. The wire area can also change depending on the type of wire used. These cross sectional areas are based on type THHW wire, and are taken from a table in the NEC 1993. (We still have that one laying around, the table are easier to read than the newer versions)

 

image.png.ac78ae80609160f9a4c8374ed7753f87.png

 

For this program, I have used the assumption that each conduit will contain "Over 2" wires per conduit, so only 40% fill is acceptable.

 

Again, thank you very much for such a nifty program. I'll use this one an toss mine by the wayside.

 

 

Link to comment
Share on other sites

Glad you can use it! :) .. BTW .. I found an error in 'l2' so please copy the code above again.

 

Are these correct?

	     ("3.5" 3.96)
	     ("4" 5.09)
	     ("5" 8.00)

 

Link to comment
Share on other sites

Quote

("3.5" 3.96)

("4" 5.09)

("5" 8.00)

Yes, these are correct.

 

Also, another quick correction from list l

("#3" 0.1263)

("#1" 0.2027)

#3 I had not corrected previously, and the #1 wire was listed as #1/0

Link to comment
Share on other sites

22 minutes ago, CHLUCFENG said:

#3 I had not corrected previously, and the #1 wire was listed as #1/0

Fixed above.

 

Also .. you could add something like this to do the math for you depending on material .. then you can just maintain lists of '((OD ID)).

(defun usable (pipeid #wires)
  (* (* pi (* (/ pipeid 2.) (/ pipeid 2.)))
     (cond ((= 1 #wires) 0.52)
	   ((= 2 #wires) 0.31)
	   (0.40)
     )
  )
)
(usable  4.975 1)
;10.1083 
(usable  4.975 2)
;6.02612 
(usable  4.975 3)
;7.77564 

Why is 2 wires cross sectional area less than 3 or more?

Edited by ronjonp
Link to comment
Share on other sites

Just now, ronjonp said:

Why is 2 wires cross sectional area less than 3 or more?

Such is the way of the code books. 

 

From the NEC:

Quote

 

Informational Note No. I: Table I is based on common 
conditions of proper cabling and alignment of conductors 
where the length of the pull and the number of bends are 
within reasonable limits. ft should be recognized that, for 
certain conditions, a larger size conduit or a lesser conduit 
fill should be considered. 


Informational Note No.2: When pulling three conductors 
or cables into a raceway, if the ratio of the raceway (inside 
diameter) to the conductor or cable (outside diameter) is 
between 2.8 and 3.2, jamming can occur. While jamming 
can occur when pulling four or more conductors or cables 
into a raceway, the probability is very low. 

 

 

Just now, ronjonp said:

Also .. you could add something like this to do the math for you depending on material .. then you can just maintain lists of '((OD ID)).

 

That is a good idea also. That way, I could change EMT to Rigid, or even flexible (metal or PVC), and then with PVC, there is schedule 40, schedule 80, etc. with differing ID's.

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