(defun mp ()
  (setvar "cmdecho" 0)
  (command "ucs" "w")
  (setq i 0)
  (winwin)
  (win)
  (vl-load-com)
  (setq	acadobj	 (vlax-get-acad-object)
	acadpro	 (vla-get-preferences acadobj)
	acaddis	 (vla-get-output acadpro)
	acadtool (vla-get-defaultoutputdevice acaddis)
	output	 (vla-get-defaultplotstyletable acaddis)
  )
  (setq	*acadobject*   (vlax-get-acad-object)
	*acaddocument* (vla-get-activedocument *acadobject*)
	*mspace*       (vla-get-modelspace *acaddocument*)
  )
  (setq pop_list (list acadtool))
  (setq	pop1_list '("acad.ctb"
		    "acad.stb"
		    "Add-A-Plot Style Table Wizard"
		    "Fill Patterns.ctb"
		    "Grayscale.ctb"
		    "monochrome.ctb"
		    "monochrome.stb"
		    "Sample Floor Plan_Architectural.stb"
		    "Sample Floor Plan_Base.stb"
		    "Sample Floor Plan_Electrical.stb"
		    "Sample Floor Plan_Lighting.stb"
		    "Screening 25%.ctb"
		    "Screening 50%.ctb"
		    "Screening 75%.ctb"
		    "Screening 100%.ctb"
		   )
  )
  (dcl)
  (setq sss (ssget))
  (setq n 0)
  (setq i 0)
  (repeat (sslength sss)
    (setq en (ssname sss n))
    (setq vl-en (vlax-ename->vla-object en))
    (vla-getboundingbox vl-en 'minext 'maxext)
    (setq point1 (vlax-safearray->list minext))
    (setq point2 (vlax-safearray->list maxext))
    (setq en_date (entget en))
    (setq ABC (strcase (cdr (assoc 0 en_date))))
    (if	(= ABC "INSERT")
      (liling)
    )

    (setq n (1+ n))
  )
  (cond	((= data "0")
	 (princ (strcat "\n共打印了" (itoa i) "張模具圖紙"))
	)
	((= data "1")
	 (princ (strcat "\n 僕湖荂賸" (itoa i) "耀撿芞祧"))
	)
  )
  (princ)
)


(defun acad1 ()
  (command "-plot"	 "Y"	""     acadtool	     siz2   ""
	   fang	  ""	 "w"	point1 point2 ""     ""	    ""
	   output ""	 ""	""     ""     ""
	  )
  (setq i (1+ i))
)


(defun acad2 ()
  (command "-plot"	 "Y"	""     acadtool	     siz1   ""
	   fang	  ""	 "w"	point1 point2 ""     ""	    ""
	   output ""	 ""	""     ""     ""
	  )
  (setq i (1+ i))
)


(defun acad3 ()
  (command "-plot"	 "Y"	""     acadtool	     siz1   ""
	   fang	  ""	 "w"	point1 point2 ""     ""	    ""
	   output ""	 ""	""     ""     ""
	  )
  (setq i (1+ i))
)


(defun acad4 ()
  (command "-plot"	 "Y"	""     acadtool	     siz1   ""
	   fang	  ""	 "w"	point1 point2 ""     ""	    ""
	   output ""	 ""	""     ""     ""
	  )
  (setq i (1+ i))
)

(defun acad5 ()
  (command "-plot"	 "Y"	""     acadtool	     siz2   ""
	   fang	  ""	 "w"	point1 point2 ""     ""	    ""
	   output ""	 ""	""     ""     ""
	  )
  (setq i (1+ i))
)

(defun winwin ()
  (setq dat_file (findfile "Big5orGB.dat"))
  (setq ff (open dat_file "r"))
  (setq data1 (read-line ff))
  (setq data (substr data1 1 1))
  (close ff)
  (princ)
)

(defun liling ()
  (setq size (strcase (cdr (assoc 2 en_date))))
  (cond	((and (= size "A3") (= th "AA")) (acad1))
	((and (= size "A4") (= th "AA")) (acad2))
	((and (= size "A4") (= th "BB")) (acad4))
	((and (= size "A3") (= th "BB")) (acad3))
	((and (= size "A3") (= th "CC")) (acad1))
  )
)
(defun win ()
  (setq dat_file (findfile "paper_size.dat"))
  (setq paper (open dat_file "r"))
  (setq siz1 (read-line paper))
  (setq siz2 (read-line paper))
  (close paper)
  (princ)
)

(defun dcl ()
  (setq dcl_id (load_dialog "mp"))
  (cond
    ((= data "0") (new_dialog "mpf" dcl_id))
    ((= data "1") (new_dialog "mpj" dcl_id))
  )
  (action_tile "AA" "(done_dialog 1)")
  (action_tile "BB" "(done_dialog 2)")
  (action_tile "CC" "(done_dialog 3)")
  (show_list "pop" pop_list)
  (show_list "pop1" pop1_list)
  (action_tile "pop" "(sub_pop $value)")
  (action_tile "pop1" "(sub_pop1 $value)")
  (ty_list1)
  (set_tile "LP" "1")
  (set_tile "edit_x" "0.00")
  (set_tile "edit_Y" "0.00")
  (action_tile "LP" "(ty_list1)")
  (action_tile "PL" "(ty_list2)")
  (setq dd (start_dialog))
  (cond	((= dd 1) (setq th "AA"))
	((= dd 2) (setq th "BB"))
	((= dd 3) (setq th "CC"))
  )
)

(defun sub_pop (vvs)
  (set_tile "plotstyle" (nth (atoi vvs) pop_list))
)

(defun sub_pop1	(vvs)
  (set_tile "acadstyle" (nth (atoi vvs) pop1_list))
)
(defun ty_list1	()
  (setq ddtype 1)
  (setq fang "Portrait")
  (show_sld "kimage" "sb")
)

(defun ty_list2	()
  (setq ddtype 2)
  (setq fang "Landscape")
  (show_sld "kimage" "sb1")
)

(defun show_sld	(key sld)
  (setq x (dimx_tile key))
  (setq y (dimy_tile key))
  (start_image key)
  (fill_image 0 0 x y -15)
  (slide_image 0 0 x y sld)
  (end_image)
)
(defun show_list (key newlist)
  (start_list key)
  (mapcar 'add_list newlist)
  (end_list)
)

(vlax-add-cmd "mp" 'mp)