(defun c:parts (/ a_list d sel dcl l nd no n_list ocm oco obl olderr size size1 size2 size3 size4
			size5 size6 size7 x)
  (defun sub () 
	(start_image "ima_parts")
  	(fill_image 0 0 (dimx_tile "ima_parts") (dimy_tile "ima_parts") 0)
  	(slide_image 0 0 (dimx_tile "ima_parts") (dimy_tile "ima_parts") 
	 	(strcat "c:/Autolisp/lisp.slb(p_" sel ")"))
  	(end_image)
	(start_list "size_parts")  
	(mapcar 'add_list a_list)
	(end_list)
	(if (or (= sel "3") (= sel "5") (= sel "6") (= sel "7") (= sel "8"))
		(mode_tile "rota" 1) (mode_tile "rota" 0))
	(if (or (= sel "1") (= sel "7") (= sel "8"))
		 (mode_tile "len_parts" 1) (mode_tile "len_parts" 0)))


  (defun cs (/ d1 d2 h no p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 pt1 pt2 ss s1 s2 s3 s4 s5 s6 s7 s8
		 s9)
	(setvar "cecolor" "1")
  	(setq no (strcat "cs" (rtos nd))
	      d1 (findp no 1)
	      d2 (findp no 2)
	       h d
	      p1 (list (+ (car pt) (/ d1 2)) (cadr pt))
	      p2 (list (- (car pt) (/ d1 2)) (- (cadr pt) h))
	      p3 (list (- (car pt) (/ d 2)) (cadr p2))
	      p4 (list (+ (car pt) (/ d 2)) (- (cadr p3) (- l (/ (- d d2) 2))))
	      p5 (list (car p4) (- (cadr p3) (/ l 2)))
	      p6 (list (car p3) (cadr p5))
	      p7 (list (- (car pt) (/ d2 2)) (cadr p6))
	      p8 (list (+ (car pt) (/ d2 2)) (- (cadr p3) l))
	      p9 (list (car p4) (- (cadr p8) 5))
	     p10 (list (car p8) (cadr p9))
	     p11 (list (car p7) (cadr p9))
	     p12 (list (car pt) (- (cadr p9) (* d2 0.3)))
	     pt1 (list (- (car p1) 0.5) (cadr p1))
	     pt2 (list (+ (car p2) 0.5) (cadr p2)))
	(rectang pt1 pt2)
	(setq ss (entlast))
        (rectang p1 p2)
	(setq s1 (entlast))
	(rectang p3 p4)
	(setq s2 (entlast))
	(command "line" p5 p6 "")
	(setq s3 (entlast))
	(rectang p7 p8)
	(setq s4 (entlast))
	(command "line" p4 p8 "")
	(setq s5 (entlast))
	(command "mirror" s5 "" pt (list (car pt) 0) "")
	(setq s6 (entlast))
	(rectang p6 p9)
	(setq s7 (entlast))
	(rectang p7 p10)
	(setq s8 (entlast))
	(command "pline" p10 p11 p12 "c")
	(setq s9 (entlast))
	(if (= x "1") (command "rotate" ss s1 s2 s3 s4 s5 s6 s7 s8 s9 "" pt "180"))
  )

  (defun eb (/ d1 h p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 no ol s1 s2 s3 s4)
	(setvar "cecolor" "2")
	(setq 	no (strcat "eb" (rtos nd))
		 h (findp no 1)
		d1 (findp no 2)
		p1 (list (car pt) (+ (cadr pt) (/ d 2)))
		p2 (list (+ (car pt) (- h (/ (- d d1) 2))) (- (cadr pt) (/ d 2)))
		p3 (list (car pt) (+ (cadr pt) (/ d1 2)))
		p4 (list (+ (car pt) h) (- (cadr pt) (/ d1 2)))
		p6 (list (+ (car p4) 5) (cadr p4))
		p7 (list (+ (car p6) (* 0.3 d1)) (cadr pt))
		p8 (list (car p6) (cadr p3))
		p9 (list (car pt) (- (cadr pt) (/ d1 2)))
		p10 (list (car p2) (cadr p1))
		p11 (list (car p4) (cadr p3))
		ol (getvar "celtype"))
	(command "celtype" "hidden" )
	(rectang p1 p2)
	(setq s1 (entlast))
	(command "pline" p3 p8 p7 p6 p9 "")
	(setq s2 (entlast))
	(command "pline" p4 p2 p10 p11 "c")
	(setq s3 (entlast))
	(command "pline" p6 p8 "")
        (setq s4 (entlast))
	(if (= x "1") (command "rotate" s1 s2 s3 s4 "" pt "180"))
	(setvar "celtype" ol)
  )

  (defun gp (/ d1 h no p pt1 pt2 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 r s1 s2 s3 s4 s5 s6 s7
		 s8 s9 s10 s11 ss w)
	(setvar "cecolor" "3")
	(setq 	no (strcat "gp" (rtos nd))
		d1 (findp no 1)
		 h (findp no 2)
		 r (findp no 3)
		 w (findp no 4)
		 p (findp no 5)
		p1 (list (+ (car pt) (/ d1 2)) (cadr pt))
		p2 (list (- (car pt) (/ d1 2)) (- (cadr pt) h))
		p3 (list (+ (car pt) (/ d 2)) (cadr p2))
		p4 (list (- (car pt) (/ d 2)) (- (cadr pt) (- l (+ (* 2 p) (/ w 2)))))
		p5 (list (car p4) (- (cadr p4) w))
		p6 (list (car p3) (- (cadr p5) p))
		p7 (list (car p6) (- (cadr p6) w))
		p8 (list (car p7) (- (cadr pt) l))
		p9 (list (car p5) (cadr p8))
	     	p10 (list (car p5) (cadr p7))
		p11 (list (car p9) (- (cadr p9) 5))
		p12 (list (car pt) (- (cadr p11) (* d 0.3)))
		p13 (list (car p8) (cadr p11))
		pt1 (list (- (car p2) 0.5) (cadr pt))
		pt2 (list (+ (car p1) 0.5) (cadr p3)))
	(rectang pt1 pt2)
	(setq ss (entlast))
	(rectang p1 p2)
	(setq s1 (entlast))
	(rectang p3 p4)
	(setq s2 (entlast))
	(rectang p5 p6)
	(setq s3 (entlast))
	(command "pline" p7 p8 p9 p10 "")
	(setq s4 (entlast))
	(command "fillet" "r" r "fillet" "p" s4)
	(setq s5 (entlast))
	(command "line" p7 p10 "")
	(setq s6 (entlast))
	(command "arc" p4 "e" p5 "a" "-180")
	(setq s7 (entlast))
	(command "arc" p6 "e" p7 "a" "180")
	(setq s8 (entlast))
	(command "mirror" s7 "" pt (list (car pt) 0) "")
	(setq s9 (entlast))
	(command "mirror" s8 "" pt (list (car pt) 0) "")
	(setq s10 (entlast))
	(command "pline" p3 p13 p12 p11 p4 p11 p13 "")
	(setq s11 (entlast))
	(if (= x "1") (command "rotate" ss s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 "" pt "180"))
  )

  (defun gb (/ d1 p1 p2 s1 s2)
	(setvar "cecolor" "4")
	(setq d1 (findp (strcat "gb" (rtos nd)) 1)
		p1 (list (- (car pt) (/ d1 2)) (cadr pt))
		p2 (list (- (car pt) (/ d 2)) (+ (cadr pt) l)))
	(rectang p1 p2)
	(setq s1 (entlast))
	(command "hatch" "ANSI31,N" (/ l 2) "" "l" "")
	(setq s2 (entlast))
	(command "mirror" s1 s2 "" pt (list (car pt) 0) "")
  )

  (defun sgb (/ d1 d2 h no p1 p2 p3 p4 p5 p6 pt1 pp ss s0 s1 s2 s3 s4)
	(setvar "cecolor" "141")
	(setq no (strcat "gb" (rtos nd)) 
		d1 (findp no 1)
		d2 (findp no 2)
		 h (findp no 3)
		p1 (list (- (car pt) (/ d 2)) (cadr pt))
	 	p2 (list (- (car pt) (/ d2 2)) (cadr pt))
		p3 (list (car p2) (- (cadr pt) h))
		p4 (list (- (car pt) (/ d1 2)) (cadr p3))
		p5 (list (car p4) (- (cadr pt) l))
		p6 (list (car p1) (cadr p5))
		pt1 (list (- (car p3) 0.5) (cadr p3))
		pp (list (car pt) 0))
	(command "pline" p1 p2 p3 p4 p5 p6 "c")
	(setq s1 (entlast))
	(command "hatch" "ANSI31,N" (/ l 2) "" "l" "")
	(setq s2 (entlast))
	(command "mirror" s1 "" pt pp "")
	(setq s3 (entlast))
	(command "mirror" s2 "" pt pp "")
	(setq s4 (entlast))
	(rectang p2 pt1)
	(setq ss (entlast))
	(command "mirror" ss "" pt pp "")
	(setq s0 (entlast))
	(if (= x "1") (command "rotate" ss s0 s1 s2 s3 s4 "" pt "180"))
  )

  (defun sp (/ d1 d2 d3 d4 h h1 h2 l1 l2 no ol p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17
		 p18 p19 p20 p21 p22 p pt1 pt2 r s ss s1 s2 s3 s4 w)
	(setvar "cecolor" "6")
	(setq no (strcat "sp" (rtos nd))
		d1 (findp no 1)
		d2 (findp no 4)
		d3 (findp no 6)
		d4 (findp no 7)
		h1 (findp no 2)
		h2 (findp no 3)
		l1 (findp no 5)
		l2 d2
		r (findp no 8)
		w (findp no 9)
		p (findp no 10)
		p1 (list (- (car pt) (/ d1 2)) (cadr pt))
		p2 (list (+ (car pt) (/ d1 2)) (- (cadr pt) h1))
		p3 (list (- (car pt) (/ d 2)) (cadr p2))
		p4 (list (+ (car pt) (/ d 2)) (- (cadr pt) (- l (+ (* 3 p) (/ w 2)))))
		p5 (list (car p4) (- (cadr p4) w))
		p6 (list (car p3) (- (cadr p4) p))
		p7 (list (car p6) (- (cadr p6) w))
		p8 (list (car p5) (- (cadr p6) p))
		p9 (list (car p8) (- (cadr p8) w))
		p10 (list (car p9) (- (cadr pt) l))
		p11 (list (car p7) (cadr p10))
		p12 (list (car p7) (cadr p9))
		p13 (list (car p1) (cadr p11))
		p14 (list (car p2) (- (cadr p10) h2))
	 	p15 (list (- (car pt) (/ d3 2)) (cadr p14))
		p16 (list (+ (car pt) (/ d3 2)) (- (cadr p15) l2))
		p17 (list (+ (car pt) (/ d4 2)) (cadr p14))
		p18 (list (- (car pt) (/ d4 2)) (+ (cadr p15) l1))
		p19 (list (+ (car pt) (/ d2 2)) (cadr p14))
		p20 (list (- (car pt) (/ d2 2)) (- (cadr p18) (/ (- d2 d4) 2)))
		p21 (list (car p17) (cadr p18))
		p22 (list (car pt) (+ (cadr p18) (* d4 0.3)))
		pt1 (list (- (car p1) 0.5) (cadr p1))
		pt2 (list (+ (car p2) 0.5) (cadr p2)))
	(rectang pt1 pt2)
	(rectang p1 p2)
	(rectang p3 p4)
	(rectang p5 p6)
	(rectang p7 p8)
	(rectang p13 p14)
	(rectang p15 p16)
  	(setq s (entlast))
	(command "hatch" "ANSI37,N" d3 "" s "" "pline" p9 p10 p11 p12 "")
	(setq ss (entlast))
	(command "fillet" "r" r "fillet" "p" ss "line" p9 p12 "")
	(command "arc" p4 "e" p5 "a" "180")
	(setq s1 (entlast))
	(command "arc" p7 "e" p6 "a" "180")
	(setq s2 (entlast))
	(command "arc" p8 "e" p9 "a" "180" )
	(setq s3 (entlast))
	(setq ol (getvar "celtype"))
	(setvar "celtype" "hidden")
	(rectang p17 p18)
	(rectang p19 p20)
	(command "line" p18 p22 p21 "" "line" p18 p20 "")
	(setq s4 (entlast))
	(command "mirror" s1 s2 s3 s4 "" pt (list (car pt) 0) "")
	(setvar "celtype" ol)
  )

  (defun rp (/ d1 p1 p2 p3 p4 pt1 pt2)
	(setvar "cecolor" "21")
	(setq d1 (+ d 5)
		p1 (list (- (car pt) (/ d1 2)) (cadr pt))
		p2 (list (+ (car pt) (/ d1 2)) (+ (cadr pt) 8))
		p3 (list (- (car pt) (/ d 2)) (cadr p2))
		p4 (list (+ (car pt) (/ d 2)) (+ (cadr pt) l))
		pt1 (list (- (car p1) 0.5) (cadr p1))
		pt2 (list (+ (car p2) 0.5) (cadr p2)))
	(rectang pt1 pt2)
	(rectang p1 p2)
	(rectang p3 p4)
  )

  (defun egb (/ d1 d2 l1 l2 h no ss s1 s2 p1 p2 p3 p4 p5 p6 p7 p8 pt1)
	(setvar "cecolor" "31")
	(setq no (strcat "egb" (rtos nd))
		d1 (findp no 1) 
		d2 (findp no 2)
		h (findp no 3)
		l2 (findp no 4)
		l1 (findp no 5)
		p1 (list (- (car pt) (/ d 2)) (+ (cadr pt) l1))
		p2 (list (- (car pt) (/ d1 2)) (cadr p1))
		p3 (list (car p2) (cadr pt))
		p4 (list (- (car pt) (/ d2 2)) (cadr p3))
		p5 (list (car p4) (- (cadr pt) h))
		p6 (list (car p3) (cadr p5))
		p7 (list (car p6) (- (cadr p6) l2))
		p8 (list (car p1) (cadr p7))
		pt1 (list (- (car p5) 0.5) (cadr p5)))
	(command "pline" p1 p2 p3 p4 p5 p6 p7 p8 "c")
	(setq s1 (entlast))
	(command "hatch" "ANSI31,N" l2 "" "l" "")
	(setq s2 (entlast))
	(rectang p4 pt1)
	(setq ss (entlast))
	(command "mirror" ss s1 s2 "" pt (list (car pt) 0) "")
  )

  (defun ori (/ ce1 ce2 ds d1 d2 d3 d4 d5 dd2 dd3 dd4 dd5 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16
		 p17 s1 s2 no)
	(setq	no (strcat "ORI" (rtos nd))
		ds (getvar "dimscale")
		dd2 (findp no 1)
		dd3 (findp no 2)
		dd4 (findp no 3)
		dd5 (findp no 4)
		d1 (* ds 1.5) 
		d2 (* (/ dd2 d) d1)
		d3 (* (/ dd3 d) d1)
		d4 (* (/ dd4 d) d1)
		d5 (* (/ dd5 d) d1)
		p1 (polar pt 3.1415926 (* d1 0.5))
		p2 (polar pt 3.1415926 (* d4 0.5))
		p3 (polar p2 4.7123889 d2)
		p4 (polar p3 3.1415926 d5)
		p5 (polar p4 1.5707963 d2)
		p6 (polar p5 3.1415926 d5)
		p9 (polar p6 0 (+ d3 (* 3 d5)))
		p10 (polar p9 3.1415926 d5)
		p11 (polar p10 4.7123889 d2)
		p12 (polar p11 3.1415926 d5)
		p13 (polar pt 0 (* d4 0.5))
		p14 (polar pt 0 (* d1 0.5))
		p15 (polar p14 4.7123889 (* 3 d2))
		p16 (polar p15 3.6651914 (* d1 0.577))
		p17 (polar p15 3.1415926 d1)
		p7 (list (car p6) (- (cadr p16) d2))
		p8 (polar p7 0 (+ d3 (* 3 d5)))
		ce1 (list (+ (car p5) (* d5 0.5)) (+ (cadr p5) (* ds 0.18)))
		ce2 (polar ce1 0 (+ d4 d5)))
	(command "cecolor" "4"
		"pline" p9 "w" "0" "" p10 p11 p12 p13 p14 p15 p16 p17 p1 p2 p3 p4 p5 p6 "")
	(setq s1 (entlast))
	(command "pline" p6 p7 p8 p9 "")
	(setq s2 (entlast))
	(command "line" p5 p10 "" "line" p15 p17 ""
		"cecolor" "3" "celtype" "center" 
		"line" ce1 (polar ce1 4.7123889 (+ d2 (* ds 0.6))) ""
		"line" ce2 (polar ce2 4.7123889 (+ d2 (* ds 0.6))) ""
		"cecolor" "2" "celtype" "CONTINUOUS"
		"dim" "horizontal" ce1 ce2 (polar p1 1.5707963 (* ds 0.8)) (rtos dd3)
		      "horizontal" p2 p13 (polar p2 1.5707963 (* ds 0.5)) (rtos dd4)
		      "horizontal" p1 p14 ce1 (rtos d)
		      "horizontal" p4 p3 (polar p3 4.7123889 d2) (rtos dd5)
		      "vertical" p11 p9 p9 (rtos dd2)
		      "vertical" p9 p15 (polar p9 0 (* ds 0.3)) "5" "e"
		"cecolor" "4"
		"hatch" "ANSI31,N" (* ds 1.5) "" s1 s2 ""
		"erase" s2 ""
	)
  )

  (setq olderr *error* *error* ai_abort 
	ocm (getvar "cmdecho") obl (getvar "blipmode")
	oco (getvar "cecolor")
	n_list '("SocketHeadCapScrews" "EyeBolt" "GuidePin" "GuideBushing" "ShouldGuideBushing" "SupportPin" "ReturnPin" "EjectorGuideBushing" "O-RING")
	size1 '("3" "4" "5" "6" "8" "10" "12" "14" "16" "20" "24" "30" "36")
	size2 '("12" "16" "20" "24" "36" "42")
	size3 '("12" "16" "20" "25" "30" "35" "40" "45" "50" "60" "70")
	size4 '("16" "20" "25" "30" "35" "40" "45" "50" "60" "70")
	size5 '("12" "15" "16" "20" "25" "30" "35" "40")
	size6 '("20" "25" "30" "35" "40" "50" "60")
	size7 '("4" "6" "8" "10" "12" "18" "20" "25" "30")
	size (list size1 size2 size3 size4 size4 size4 size5 size6 size7))
  (setq dcl (load_dialog "c:/Autolisp/lisp.dcl"))
  (if (not (new_dialog "parts" dcl)) (exit))
  (start_list "list_parts")
  (mapcar 'add_list n_list)
  (end_list)
  (set_tile "list_parts" " 0")
  (setq sel "0" a_list size1) (sub)
  (action_tile "list_parts" "(setq sel $value  a_list (nth (atoi sel) size))(sub)")
  (action_tile "rota" "(setq x $value)")
  (action_tile "size_parts" "(setq nd (atoi $value))") 
  (action_tile "len_parts" "(setq l (atof $value))") 
  (action_tile "accept" "(done_dialog)")
  (action_tile "cancel" "(exit)")
  (start_dialog)                                     (unload_dialog dcl)

  (setvar "blipmode" 0)	(setvar "cmdecho" 0) (command "_.UNDO" "_GROUP") (setvar "celtype" "CONTINUOUS")
  (initget 1)
  (setq pt (getpoint "\n²åÈëüc: "))
  (if (= nd nil) (setq nd 0))
  (if (= d nil) (setq d (atof (nth nd a_list))))
  (cond ((= sel "0") (cs))
	((= sel "1") (eb))
	((= sel "2") (gp))
	((= sel "3") (gb))
	((= sel "4") (sgb))
	((= sel "5") (sp))
	((= sel "6") (rp))
	((= sel "7") (egb))
	((= sel "8") (ori)))
  (redraw)
  (setq *error* olderr)
  (setvar "cmdecho" ocm) (setvar "blipmode" obl) (setvar "cecolor" oco)
  (command "_.UNDO" "_E")
  (princ)
)