(defun *error* (msg)
    (princ "程序取消 ")
    (princ msg)    
    (command "ucs"  "w" )
    (setvar "osmode" 135)
    )


(defun C:fg(/ size dd dd1 color auto a3qty a4qty)
  (setvar "cmdecho" 0)
  (command "UCS" "w")
  (setq dd (load_dialog "fg.dcl"))
  (if (< dd 0)  (exit))
  (if (not (new_dialog "fg" dd))
      (exit)
    )
  (set_tile "auto" "1")
  (mode_tile "A2" 1)
  (mode_tile "A1" 1)
  (mode_tile "color" 1)
  (setq size "A3" color "black" wh "L")
  (set_tile "A3" "1")
  (mode_tile "A3" 1)
  (mode_tile "A4" 1)
  (set_tile "black" "1")


  (action_tile "auto" "(autoset)")
  (action_tile
    "A4" "(setq size \"A4\")(done_dialog 1)")
  (action_tile
    "A3" "(setq size \"A3\")(done_dialog 1)")
  (action_tile
    "A2" "(setq size \"A2\")")
  (action_tile
    "A1" "(setq size \"A1\")")
  (action_tile
    "black" "(setq color \"black\")")
  (action_tile
    "color" "(setq color \"color\")")
  (action_tile "accept" "(setq auto (get_tile \"auto\"))(done_dialog 1)")
  (action_tile "cancel" "(done_dialog 0)")
  (setq dd1 (start_dialog))
  (unload_dialog dd)
  (if (= dd1 1)
      (fg2))   
  )


(defun autoset()
  (if (= (get_tile "auto") "1")
    (progn
      (mode_tile "A3" 1)
      (mode_tile "A4" 1))
    (progn
      (mode_tile "A3" 0)
      (mode_tile "A4" 0))

)
  )
    

(defun fg2(/ sss sss_data sss-int sss-scc sss-ang x y minp maxp maxp_x maxp_y minp_x minp_y
	   sss-int_x sss-int_y ot-pt ang wh ss1 m n sss-name size1)
  (setvar "cmdecho" 0)
  (command "-layer" "lw" 0.13 "DIM" "")
  (setq sss (ssget (list (cons 0 "INSERT") (cons 2 "A3,1001,bombb,bomaa,A4,a4,a3,A3A,A3_B,A33,1"))))
  (setvar "osmode" 0)
  (setq size1 size a4qty 0 a3qty 0)
  (if (/= sss nil)
    (progn
     (setq ssl (sslength sss) m 0 n 0)
     (repeat ssl
     (setq ss1 (ssname sss m))
     (setq sss-name (cdr (assoc 2 (entget ss1))))
     (vla-getboundingbox (vlax-ename->vla-object ss1) 'minp 'maxp)
     (setq minp (vlax-safearray->list minp))
     (setq maxp (vlax-safearray->list maxp)) 

     (setq minp_x (car minp)
           minp_y (cadr minp))
     (setq maxp_x (car maxp)
           maxp_y (cadr maxp))
     (if (> (- maxp_x minp_x)  (- maxp_y minp_y) ) 
         (setq wh "L" )
         (setq wh "P" ))

     (if (= auto "1")
        (progn
               (if (>= (* (- maxp_x minp_x)  (- maxp_y minp_y) ) 226000)
                (setq size1 "A3" )
                 (setq size1 "A4" ))	
        )
       )
     
     
     (if (or(= sss-name "bombb")(= sss-name "bomaa"))         	         
	 (setq wh "P" size1 "A4" n (1+ n))    
      )
  
  
  
  (command "-plot"
	   "Y"
	   "Model"
	   "HP LaserJet 8000 Series PCL"
	   size1
	   "M"
	   wh
	   "N"
	   "W"
	   minp
	   maxp
	   "F"
	   "C"
	   "Y"
	   "monochrome.ctb"
	   "Y"
	   "A"
	   "N"
	   "N"
	   "y")
     ; (command "circle" minp 50)     (command "circle" maxp 50)
      (setq m (1+ m))
      (setq size1 size)
       (if (= size1 "A4")(setq a4qty (1+ a4qty)))
       (if (= size1 "A3")(setq a3qty (1+ a3qty)))
       
    );end repeat
  );end progn
 );end if
  (setvar "osmode" 7)
  (princ "正在打印模具图," )
  ;(princ (rtos (- ssl n)2 2))
  (princ "其中A3<" )
  (princ (rtos a3qty 2 2))
  (princ ">张,A4<")
  (princ (rtos a4qty 2 2))
  (princ ">张.")
  (if (> n 0)
      (progn
      (princ "物料清单")
      (princ (rtos n 2 2))
      (princ "张<A4>," )
      ))
  (princ "共" )
  (princ (rtos ssl 2 2))
  (princ "张.打印机 HP LaserJet 8000 Series PCL 正在打印,请稍等.....")
  (princ)
  )

;;;;;;;;;;;;;;;;;;;;
