(defun c:motwire ( / dcl_id edd enn x xit old_lay dclfnam amps ed en hp kw_units layername motor_fla motor_hp nema_size newedd newlayername old_layer size str voltage volts wire_en wire_size wire_segment_lst wsize xitflg) ; -- internal functions starting here -- (defun do_lookup_FLA ( volts hp / amps ) (setq amps nil) ; default return if no match (cond ((AND (>= volts 230)(<= volts 240)) ; 230 VOLT 3-PHASE MOTOR DATA (cond ((<= hp 0.5) (setq amps 2.2)) ((<= hp 0.75)(setq amps 3.2)) ((<= hp 1.0) (setq amps 4.2)) ((<= hp 1.5) (setq amps 6.0)) ((<= hp 2.0) (setq amps 6.8)) ((<= hp 3.0) (setq amps 9.6)) ((<= hp 5.0) (setq amps 15.2)) ((<= hp 7.5) (setq amps 22.0)) ((<= hp 10.0)(setq amps 28.0)) ((<= hp 15.0)(setq amps 42.0)) ((<= hp 20.0)(setq amps 54.0)) ((<= hp 25.0)(setq amps 68.0)) ((<= hp 30.0)(setq amps 80.0)) ((<= hp 40.0)(setq amps 104.0)) ((<= hp 50.0)(setq amps 130.0)) ((<= hp 60.0)(setq amps 154.0)) ((<= hp 75.0)(setq amps 192.0)) ((<= hp 100.0)(setq amps 248.0)) ((<= hp 125.0)(setq amps 312.0)) ((<= hp 150.0)(setq amps 360.0)) ((<= hp 200.0)(setq amps 480.0)) ) ) ((AND (>= volts 460)(<= volts 480)) ; 460 VOLT 3-PHASE MOTOR DATA (cond ((<= hp 0.5) (setq amps 1.1)) ((<= hp 0.75)(setq amps 1.6)) ((<= hp 1.0) (setq amps 2.1)) ((<= hp 1.5) (setq amps 3.0)) ((<= hp 2.0) (setq amps 3.4)) ((<= hp 3.0) (setq amps 4.8)) ((<= hp 5.0) (setq amps 7.6)) ((<= hp 7.5) (setq amps 11.0)) ((<= hp 10.0)(setq amps 14.0)) ((<= hp 15.0)(setq amps 21.0)) ((<= hp 20.0)(setq amps 27.0)) ((<= hp 25.0)(setq amps 32.0)) ((<= hp 30.0)(setq amps 40.0)) ((<= hp 40.0)(setq amps 52.0)) ((<= hp 50.0)(setq amps 65.0)) ((<= hp 60.0)(setq amps 77.0)) ((<= hp 75.0)(setq amps 96.0)) ((<= hp 100.0)(setq amps 124.0)) ((<= hp 125.0)(setq amps 156.0)) ((<= hp 150.0)(setq amps 180.0)) ((<= hp 200.0)(setq amps 240.0)) ((<= hp 250.0)(setq amps 302.0)) ((<= hp 300.0)(setq amps 361.0)) ((<= hp 350.0)(setq amps 414.0)) ((<= hp 400.0)(setq amps 477.0)) ((<= hp 450.0)(setq amps 515.0)) ((<= hp 500.0)(setq amps 590.0)) ) ) ) amps ; return FLA or nil if not found ) ; -- (defun do_lookup_nema_size ( volts hp / size ) (setq size nil) ; default return (if NEMA size not found) (cond ((AND (>= volts 230)(<= volts 240)) ; 230 VOLT NEMA SIZE DATA (cond ((<= hp 1.5)(setq size "00")) ((<= hp 3.0)(setq size "0")) ((<= hp 7.5)(setq size "1")) ((<= hp 15.0)(setq size "2")) ((<= hp 30.0)(setq size "3")) ((<= hp 50.0)(setq size "4")) ((<= hp 100.0)(setq size "5")) ((<= hp 200.0)(setq size "6")) ((<= hp 300.0)(setq size "7")) ) ) ((AND (>= volts 460)(<= volts 575)) ; 230 VOLT NEMA SIZE DATA (cond ((<= hp 2.0)(setq size "00")) ((<= hp 5.0)(setq size "0")) ((<= hp 10.0)(setq size "1")) ((<= hp 25.0)(setq size "2")) ((<= hp 50.0)(setq size "3")) ((<= hp 100.0)(setq size "4")) ((<= hp 200.0)(setq size "5")) ((<= hp 400.0)(setq size "6")) ((<= hp 600.0)(setq size "7")) ) ) ) size ; return NEMA size text string or nil if not found ) ; -- (defun do_lookup_wire_size ( amps / wsize ) ; NEC table 310.16 (setq wsize nil) ; default return if wire size not found (cond ; 60 degree C (140 F), types TW, UF ((<= amps 20.0)(setq wsize "14")) ((<= amps 25.0)(setq wsize "12")) ((<= amps 30.0)(setq wsize "10")) ((<= amps 40.0)(setq wsize "8")) ((<= amps 55.0)(setq wsize "6")) ((<= amps 70.0)(setq wsize "4")) ((<= amps 95.0)(setq wsize "2")) ((<= amps 110.0)(setq wsize "1")) ((<= amps 125.0)(setq wsize "1-0")) ((<= amps 145.0)(setq wsize "2-0")) ((<= amps 165.0)(setq wsize "3-0")) ((<= amps 195.0)(setq wsize "4-0")) ((<= amps 215.0)(setq wsize "250MCM")) ((<= amps 240.0)(setq wsize "300MCM")) ((<= amps 260.0)(setq wsize "350MCM")) ((<= amps 280.0)(setq wsize "400MCM")) ((<= amps 320.0)(setq wsize "500MCM")) ) wsize ; return wire size text string or nil if not found ) ; -- (defun do_format_wire_type ( wire_size / ) ; Format the "wire_size" text string into an appropriate wire layer name (setq layername (strcat "BLK_" wire_size "_AWG")) layername ; return layer name ) ; -- (defun do_wire_layer_change ( newlayername / edd enn x xit old_lay) ; prompt user to pick wires to flip to wire layer "newlayername" (setq xit nil) (while (not xit) (setq xit T) ; default exit loop if user doesn't pick something (princ (strcat "\nSelect wire to flip to " layername)) ; Get complete wire network tied to the picked wire segment. First ; element of the return will be the list of wire LINE segment entity ; names (setq x (c:wd_get_wire_netlst (car (entsel)) 0)) (if (setq wire_segment_lst (car x)) ; some data returned (progn ; data returned, process each wire segment in the picked ; wire network. (setq xit nil) ; flag to stay in the loop (foreach wire_en wire_segment_lst ; Open this wire segment entity. Get layer info. (setq edd (entget wire_en)) ; Adjust layer name if it is different from what is needed (setq old_layer (cdr (assoc 8 edd))) (if (/= old_lay newlayername) (progn ; prepare to modify the LINE entity (setq newedd (subst (cons 8 newlayername)(assoc 8 edd) edd)) ; write out new version of the entity's record (entmod newedd) (entupd wire_en) ) ) ) ) ) ) ) ; -- main program starting here -- (setq xitflg nil) (while (not xitflg) (setq kw_units nil) (setq motor_hp nil) (setq motor_FLA nil) (setq voltage nil) (setq xitflg T) ; default to exit loop (setq x (entsel "\nSelect motor:")) (if x (progn (setq en (car x)) ; entity name of picked object ; open it up (setq ed (entget en)) ; Make sure it is a block insert instance (if (= (cdr (assoc 0 ed)) "INSERT") (progn ; so far, so good. Now see if can extract some ; existing attribute values to get horsepower ; and voltage. ; HP or KW value (setq str (c:wd_getattrval en "RATING2")) (if (AND str (/= str "")) (progn ; try to extract numerical value from the string (setq motor_hp (atoi str)) ; Look for HP or KW as part of the string. If not found, ; assume HP (setq kw_units (wcmatch (strcase str) "*KW*,*K.W.*")) (if kw_units (progn ; convert to HP units (setq motor_hp (/ motor_hp 0.746)) ) ) ) ) ; Incoming Line voltage (setq str (c:wd_getattrval en "RATING3")) (if (AND str (/= str "")) (progn (setq voltage (atoi str)) ) ) ; Display values to command window. (princ "\n HP: ") (princ motor_hp) (princ "\n Volts: ") (princ voltage) ) ) ; If either HP or Voltage is blank, pop open dialog and prompt for info (if (OR (not motor_hp)(not voltage) (= motor_hp "")(= voltage "")) (progn ; prompt user to enter HP and voltage values (if (setq dclfnam (c:ace_find_file "motwire.dcl" 0)) (progn ; located DCL file name, open up dialog (setq dcl_id (load_dialog dclfnam)) (if (new_dialog "motwire_hp_volts" dcl_id) (progn (if (AND motor_hp (/= motor_hp "")) (set_tile "hp" (rtos motor_hp 2 2))) (if voltage (set_tile "volts" (itoa voltage))) (action_tile "hp" "(setq motor_hp (atof $value))") (action_tile "volts" "(setq voltage (atoi $value))") (start_dialog) (unload_dialog dcl_id) ) ) ) ) ) ) ; Have HP and VOLTS. Now look up FLA from NEC table 430-150 (setq motor_FLA (do_lookup_FLA voltage motor_hp)) (if motor_FLA (progn ; Have a FLA value. Okay to continue! ; write full load amp value out to RATING1 attribute (setq str (strcat (rtos motor_FLA 2 1) " FLA")) (c:wd_modattrval en "RATING1" str nil) ; Also display in command window (princ "\n FLA: ") (princ str) ; If blank motor HP attribute (RATING2), then write out the ; horsepower value. (if (= (c:wd_getattrval en "RATING2") "") (progn (setq str (rtos motor_hp 2 2)) (cond ((= (substr str (- (strlen str) 2)) ".00") (setq str (substr str 1 (- (strlen str) 3))) ) ((= (substr str (strlen str)) "0") (setq str (substr str 1 (- (strlen str) 1))) ) ) (c:wd_modattrval en "RATING2" str nil) ) ) ; If blank voltage attribute (RATING3), then write out the ; voltage value (if (= (c:wd_getattrval en "RATING3") "") (c:wd_modattrval en "RATING3" (strcat (rtos voltage 2 0) " VAC") nil) ) ; Figure out appropriate NEMA starter size based upon ; motor HP and incoming line voltage value. (setq nema_size (do_lookup_NEMA_size voltage motor_hp)) (if nema_size (progn ; write NEMA size out to attribute RATING4 on the ; motor symbol. (setq str (strcat "SIZE " nema_size)) (c:wd_modattrval en "RATING4" str nil) ; Also display in command window (princ "\n NEMA SIZE: ") (princ nema_size) ) ) ; Look up minimum conductor size from NEC table 310.16 ; Use 125% of motor full load amps for the calculation ; per code requirement (setq wire_size (do_lookup_wire_size (* motor_FLA 1.25))) (if wire_size (progn ; Have minimum wire size ; Display in command window (princ "\n Minimum conductor size: ") (princ wire_size) ) ) ) ) (if wire_size (progn ; have calculated wire size, now figure out layer name (setq layername (do_format_wire_type wire_size)) ; Also display in command window (princ "\n Wire Layer: ") (princ layername) ; Now prompt user to pick wires to flip to this layer (do_wire_layer_change layername) ) ) ) ) ) (princ) )