					;************defun change_prop start*******
(defun change_prop (sel layer color line /)
  ;(setq sel_ent (ssget "p"))
  (if sel
    (progn
      (if (/= layer "")
	(command "change" sel "" "p" "la" layer "")
      )
      (if (/= color "")
	(command "change" sel "" "p" "c" color "" )
      )
      (if (/= line "")
	(command "change" sel "" "p" "lt" line "")
      )
    )
  )
)


(defun mxb_head	()
  (command "ucs" "w")
  (setq old_epmxb (ssget "X" '((0 . "INSERT") (2 . "epid_head"))))
  (if (= nil old_epmxb)
    (progn
      (setq mxb_cso (getpoint "选取明细表的位置："))

      (command "insert" "epid_head.dwg" mxb_cso "" "" "")
      (command "ucs" "o" mxb_cso)
      (setq mxb_x1 (car mxb_cso))
      (setq mxb_y1 (car (cdr mxb_cso)))
    )
    (if	(= 1
	   (sslength old_epmxb)
	)
      (progn
	(print "!!!图形中已 明细表")
	(setq temp_cso (assoc '10 (entget (ssname old_epmxb 0))))
	(setq mxb_x1 (car (cdr temp_cso)))
	(setq mxb_y1 (cadr (cdr temp_cso)))
					;(command "ucs" "o" (list mxb_x1 mxb_y1))
      )
      (princ "!!!图形中已有多基准坐标系!!!")


    )
  )
)


(defun cso_tran	(/ cso)
  (command "ucs" "W")
  (setq old_cso (ssget "X" '((0 . "INSERT") (2 . "cso"))))
  (if (= nil old_cso)
    (progn
      (setq cso (getpoint "选取基准点"))

      (command "insert" "cso.dwg" cso "" "" "")
      (command "ucs" "o" cso)
      (setq x1 (car cso))
      (setq y1 (car (cdr cso)))
    )
    (if	(= 1
	   (sslength old_cso)
	)
      (progn
	(print "!!!图形中已有基准坐标系!!!")
	(setq temp_cso (assoc '10 (entget (ssname old_cso 0))))
	(setq x1 (car (cdr temp_cso)))
	(setq y1 (cadr (cdr temp_cso)))
	(command "ucs" "o" (list x1 y1))
      )
      (princ "!!!图形中已有多基准坐标系!!!")


    )
  )
)





					;*************Find ejector /pin/sleeves Flat EJECTOR
(defun find_ej (ej_sel / ej_sel e_tb ej_size_tb dia ej_temp)

  ;find ejector
  (setq	sel_ejold
	 (ssget "x" '((0 . "INSERT") (2 . "EPIN")))
  )
  (if sel_ejold
    (command "erase" sel_ejold "")
    )
  ;(setq	ej_sel
	 ;(ssget "X" '((8 . "ej_old") (0 . "CIRCLE")))
  ;)
  ;(if ej_sel
   ; (progn
					;(if (not (tblsearch "layer" "ej_old"))
					;(command "_.layer"   "_new"	 "ej_old"    "_color"
					;	 "4"	     "ej_old"	 "_ltype"    "continuous"
					;	 "mxb"	     ""
					;	)
					;(command "_.layer" "thaw" "ej_old" "on"	"mxb" "unlock" "mxb" "")
					;)
					;(change_prop ej_sel "ej_old" "" "")
      (setq os_old (getvar "osmode"))
      (setvar "osmode" 0)
      (command "ucs" "")

      (setq ej_tb nil)
      (setq ej_size_tb nil)
      (setq type_num 0)
      (setq dia_num 0)
      (repeat (sslength ej_sel)
	(setq ej_temp nil)
	(setq dia nil
	      cenpt nil
	)
	(setq ej_temp
	       (entget (ssname ej_sel type_num))
	)

	(setq dia (* 2 (cdr (assoc '40 ej_temp))))
	(setq cenpt (cdr (assoc '10 ej_temp)))
	(if (not (member dia ej_size_tb))
	  (progn
	    (setq ej_size_tb
		   (cons dia ej_size_tb)
	    )
	    (setq dia_num (+ 1 dia_num))
	  )
	)
	(setq ej_tb
	       (cons (cons dia cenpt) ej_tb)
	)
	(setq type_num (+ 1 type_num))

      )
      (setq ej_size_tb_ nil)
      (setq num_ 0)
      (foreach dia_ ej_size_tb
	(setq n 0)
	(foreach dia_value ej_size_tb
	  (if (> dia_ dia_value)
	    (setq n (+ 1 n))
	  )
	)
	(setq ej_size_tb_
	       (cons
		 (list n dia_)
		 ej_size_tb_
	       )
	)
      )
;;;;;;;;;;;;;REDEFINE SORT
      (setq n 0)
      (setq ej_tb_ nil)

      (repeat (- dia_num 1)
	(setq dia_value (* 2 (car (cdr (assoc n ej_size_tb_))))) ;ok
	(setq n1 0)
	(setq ej_pos_tb nil)
	(setq ej_pos_ nil)
	(repeat	(- type_num 1)		;ok
	  (if (= dia_value (car (nth n1 ej_tb)))
	    (progn
					;(print dia_value)
					;(print (car (nth n1 ej_tb)))
					;(print "sfdf")
	      (setq ej_pos_
		     (cons (cdr (nth n1 ej_tb))
			   ej_pos_
		     )
	      )
	    )
	  )
	  (setq n1 (+ 1 n1))
	)
	(setq ej_pos_tb (list dia_value ej_pos_))
	(setq ej_size_pos_tb
	       (cons
		 ej_pos_tb
		 ej_size_pos_tb
	       )
	)
	(setq n (+ 1 n))

      )
      ;(print ej_size_pos_tb)
      (setq dd ej_size_pos_tb)
      (setq epid 0)
      (foreach ej_data_temp ej_tb
	(setq ej_dia_temp    (car ej_data_temp)
	      ej_center_temp (cdr ej_data_temp)
	)
	;(print "!!!\n")
	;(print ej_dia_temp)
	;(print ej_center_temp)
	(if (not (tblsearch "layer" "ejpin"))
	  (command "_.layer"   "_new"	   "ejpin"     "_color"
		   "4"	       "ejpin"	   "_ltype"    "continuous"
		   "ejpin"     "set"	   "ejpin"     ""
		  )
	  (command "_.layer"  "thaw"	 "ejpin"    "on"
		   "ejpin"    "unlock"	 "ejpin"    "set"
		   "ejpin"    ""
		  )

	)
					;(change_prop ej_sel "ej_old" "" "")
	(command "insert"      "EPIN.dwg"    ej_center_temp
		 ej_dia_temp   ""	     ""
		)
      )

	(setvar "osmode" os_old)
   ; )
  ;)
					;(setq ej_total_tb (list  ej_size_tb_ ej_size_pos_tb  ))
)



					;find sleeves ejector
(defun find_es_pin (/)
 ;es_sel es_tb es_size_tb dia cenpt es_temp n n1)
(setq sel_pinold
       (ssget "x" '((0 . "INSERT") (2 . "PIN")))
)
(if sel_pinold
  (command "erase" sel_pinold "")
)
(setq sel_esold
       (ssget "x" '((0 . "INSERT") (2 . "ES*")))
)
(if sel_esold
  (command "erase" sel_esold "")
)
  ;(setq	es_sel
;	 (ssget "X" '((8 . "ej_old") (0 . "ARC")))
  ;)
  (if es_sel
    (progn
      (setq os_old (getvar "osmode"))					;(change_prop es_sel "ej_old" "" "")
      (setvar "osmode" 0)
      (command "ucs" "")
      (setq es_tb nil)
      (setq es_size_tb nil)
      (setq es_cenpt_tb nil)
      (setq cir_tb nil)
      (setq type_num 0)
      (setq point_num 0)
					;*******GEt ES_cenpt_tb**************
      (repeat (sslength es_sel)
	(setq es_temp nil)
	(setq dia nil
	      cenpt nil
	)
	(setq es_temp
	       (entget (ssname es_sel type_num))
	)
	(setq arc_start (cdr (assoc '50 es_temp)))
	(setq arc_end (cdr (assoc '51 es_temp)))
	(if (= "3.14159" (rtos (abs (- arc_start arc_end)) 2 5))
	  (progn
	    (setq dia (* 2 (cdr (assoc '40 es_temp))))
	    (setq cenpt (cdr (assoc '10 es_temp)))

	    (if	(not (member cenpt es_cenpt_tb))
	      (progn
		(setq es_cenpt_tb	;get cenpt_point 
		       (cons cenpt es_cenpt_tb)
		)
		(setq point_num (+ 1 point_num))
	      )
	    )
	    (setq cir_tb		;get all half circle data
		   (cons (cons dia cenpt) cir_tb)
	    )
	  )
	)
	(setq type_num (+ 1 type_num))	;round es_sel data
      )
					;**************************************
      (setq es_size_tb	 nil
	    es_total_tb	 nil
	    pin_total_tb nil
	    pin_dia_tb	 nil
      )

      (setq n 0)
      (while (< n point_num)
	(setq cir_point (nth n es_cenpt_tb))
					;GEt point from center position table 
	(setq n1 0)
	(setq _num 0)
	(setq cir_dia_tb nil)
					;(princ "sfskfl\n\n")
	(while (< n1  type_num )
	  (setq cir_data (nth n1 cir_tb)) ;search data in same postion
					;(princ cir_data)
	  (setq n1 (+ 1 n1))
					;(princ "XXX")
	  (setq _cenpt (cdr cir_data))
	  (setq cir_dia nil)
					;Get single point data
	  (if (and (= (car _cenpt) (car cir_point))
		   (= (car (cdr _cenpt)) (car (cdr cir_point)))
	      )				;Check point X value and Y value  from center position table
	    (progn

	      (setq cir_dia (car cir_data))
					;(princ cir_dia)
					;(princ _cenpt)
					;(princ "number ***\n")
					;(princ "\n")
	      (if (not (member cir_dia cir_dia_tb)) ;
		(progn
		  ;(princ "Find es_cir\n")
		  (setq cir_dia_tb (cons cir_dia cir_dia_tb))
		  
		  (setq _num (+ 1 _num)) ;get number of same point
		)
	      )				;add cir_dia end
	    )
					;(progn
					;(princ "afsdf\n")
					;)
	  )
	)				;search same postion end
	(setq n (+ 1 n))
					;add sleeves_type to es_size_tb and add sleeves_data to add
	(if (= _num 2)
	  (progn
	    (setq d1 nil
		  d2 nil
	    )
	    (setq d1 (nth 0 cir_dia_tb)
		  d2 (nth 1 cir_dia_tb)
	    )
	    (if	(< d1 d2)
	      (progn
		(setq cir_dia_tb (cons d2 d1))
	      )
	    )
	    (if	(not (member cir_dia_tb es_size_tb))
	      (setq es_size_tb (cons cir_dia_tb es_size_tb))
					;Add sleeve_type to es_size_tb
	    )
	    (setq es_total_tb
		   (cons (list cir_dia_tb cir_point) es_total_tb)
	    )
	  )
	)
	(if (= 1 _num)
	  (progn
					;(alert "Find one circle in same postion only")
	    (setq pin_dia (car cir_dia_tb))
	    (if	(not (member pin_dia pin_dia_tb))
	      (setq pin_dia_tb (cons pin_dia pin_dia_tb))
					;Add sleeve_type to es_size_tb
	    )
	    (setq pin_total_tb
		   (cons (cons pin_dia cir_point) pin_total_tb)
	    )
	  )
	  (if (< _num 2)
	    (progn
	      (alert "Find more than two circle in same postion ")
	    )
	  )
	)
      )
      (if (and es_total_tb es_size_tb)
	(progn
	  (setq es_tb (cons es_size_tb es_total_tb))
	  (foreach es_data_temp	es_total_tb

	    (setq es_od_temp (car (car ES_data_temp)))
	    (setq es_id_temp (cdr (car ES_data_temp)))
	    (if (listp es_id_temp)
	      (setq es_id_temp (car es_id_temp))
	      )
	    (setq es_pos_temp (car (cdr es_data_temp)))	
	    (if	(not (tblsearch "layer" "espin"))
	      (command "_.layer"   "_new"      "espin"	   "_color"
		       "6"	   "espin"     "_ltype"	   "continuous"
		       "espin"	   "set"       "espin"	   ""
		      )


	      (command "_.layer"  "thaw"     "espin"	"on"
		       "espin"	  "unlock"   "espin"	"set"
		       "espin"	  ""
		      )


	    )
	    
					;(change_prop ej_sel "ej_old" "" "")


	    (command "insert" "ES.dwg" es_pos_temp es_od_temp es_od_temp 0 )
	    (setq dd (command  "insert" "ESPIN.dwg" es_pos_temp es_id_temp es_id_temp 0))
	    
	  )
	)
      )
      (if (and pin_total_tb pin_dia_tb)
	(progn
	  (setq pin_tb (cons pin_dia_tb pin_total_tb))
	  (foreach pin_data_temp pin_total_tb

	    (setq pin_dia_temp (car pin_data_temp))
	    (setq pin_pos_temp (cdr pin_data_temp))

	    (if	(not (tblsearch "layer" "pin"))
	      (command "_.layer"  "_new"     "pin"	"_color"
		       "3"	  "pin"	     "_ltype"	"continuous"
		       "pin"	  "set"	     "pin"	""
		      )
	      (command "_.layer"	 "thaw"	  "pin"	   "on"
		       "pin"	"unlock" "pin"	  "set"	   "pin"
		       ""
		      )

	    )
					;(change_prop ej_sel "ej_old" "" "")

	    (command "insert" "PIN.dwg" pin_pos_temp pin_dia_temp "" "")
	    (setq epid (+ 1 epid))

	  )
	)
      )
      (setvar "osmode" os_old)
    )
					;(princ "hav't sleeve in drawing!")
  )


)








(defun insert_id (/)
  (setq	sel_ej
	 (ssget "x" '((0 . "INSERT") (2 . "EPIN")))
  )
  (setq	sel_pin
	 (ssget "x" '((0 . "INSERT") (2 . "PIN")))
  )
  (setq	sel_es
	 (ssget "x" '((0 . "INSERT") (2 . "ES")))
  )
  (setq	sel_espin
	 (ssget "x" '((0 . "INSERT") (2 . "ESPIN")))
  )
  (setq sel_id
	 (ssget "x" '((0 . "INSERT") (2 . "ep_pos")))
	)
  (setq sel_idtext
	 (ssget "x" '((0 . "TEXT") (8 . "mxb") (7 . "lxy2")))
	)
  (if (or (and sel_es sel_espin) sel_pin sel_ej)
    (progn
      (if sel_id
	(command "erase" sel_id "")
	)
      (if sel_idtext
	(command "erase" sel_idtext "")
	)
      (if (not (tblsearch "layer" "mxb"))
	  (command "_.layer"   "_new"	   "mxb"     "_color"
		   "1"	       "mxb"	   "_ltype"    "continuous"
		   "mxb"     "set"	   "mxb"     ""
		  )
	  (command "_.layer"  "thaw"	 "mxb"    "on"
		   "mxb"    "unlock"	 "mxb"    "set"
		   "mxb"    ""
		  )

	)
      (mxb_head)
      (cso_tran)
      (setq os_old (getvar "osmode"))
      (setvar "osmode" 0)
      (setq mxb_num 0)
      (setq num_ini (- mxb_num 1))
      (setq mxb_x1 (- mxb_x1 x1)
	    mxb_y1 (- mxb_y1 y1)
	    
      )
      
      (if (and sel_es sel_espin)
	(es_id)
      )
      ;(setq  num_ini mxb_num)
      (if sel_ej
	(ej_id sel_ej "EJPIN" "E")
      )
      ;(setq num_ini mxb_num)
      (if sel_pin
	(ej_id sel_pin "PIN" "P")
      )
      (setvar "osmode" os_old)
    )
					;(ini_user)  ;get ES_NUM PIN_NUM EPIN_NUM NUMBER
  )
					;es_sel
)










(DEFUN ES_ID (/)

  
   
      (setq es_data_tb nil)
      (setq es_dia_tb nil)
      (setq es_data_tb nil)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ES  start
      (setq n 0)
      (setq es_total_tb
			nil
	    es_size_tb	nil
      )
      (repeat (sslength sel_es)
	(setq es_data (entget (ssname sel_es n)))
	(setq es_dia   (cdr (assoc '41 es_data))
	      es_cenpt (cdr (assoc '10 es_data))
	)
					;(print es_cenpt)
					;(print "YYY\n")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ESPIN  start
	(setq espin_num 0)

	(repeat	(sslength sel_espin)
	  (setq espin_data (entget (ssname sel_espin espin_num)))
	  (setq espin_num (+ 1 espin_num))
	  (setq espin_cenpt (cdr (assoc '10 espin_data)))
					;(print  espin_cenpt)
					;(print "\n")
	  (if (and
		(= (car es_cenpt) (car espin_cenpt))
		(= (cadr es_cenpt) (cadr espin_cenpt))
	      )


	    (progn

	      (setq espin_dia (cdr (assoc '41 espin_data)))
	      (setq es_size_tb_temp (list es_dia espin_dia))
	      (if (not (member es_size_tb_temp es_size_tb))
		(progn

		  (setq es_size_tb (cons es_size_tb_temp es_size_tb))
		)
	      )
	      (setq es_total_tb
		     (cons
		       (cons es_size_tb_temp espin_cenpt)
		       es_total_tb
		     )
	      )
	    )
	  )
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ESPIN  END 

	(setq n (+ 1 n))
      )


;;;;;;;;;;;;:::::::::::::::::es_size_tb  es_total_tb:::::::::::::::::::::::::::::::::::::;ES end check ok


;;;;;;;;;;;;;;;;;;;;;;;;;sort es_size_tb;;;;;;;;;;;;;;start
      (setq es_size_tb_ nil)
      (setq od_temp_tb nil)
      (foreach es_size_tb_temp es_size_tb
	(setq od_dia_temp (car es_size_tb_temp))


	(if (not (member od_dia_temp od_temp_tb))
	  (progn
	    (setq od_temp_tb (cons od_dia_temp od_temp_tb))
	    (setq es_size_tb_s nil)
	    (foreach es_size_tb_temp__ es_size_tb
					;(print es_size_tb_temp__)
	      (if (= od_dia_temp (car es_size_tb_temp__))
		(setq es_size_tb_s
		       (cons es_size_tb_temp__
			     es_size_tb_s
		       )
		)
	      )
	    )


	    (if	es_size_tb_
	      (progn
		(setq es_size_tb_
		       (append es_size_tb_s
			       es_size_tb_
		       )
		)
					;(print es_size_tb_)
	      )
	      (progn
					;(print "es_null")
		(setq es_size_tb_ es_size_tb_s)
					;(print es_size_tb_)
	      )
	    )				;


	  )
	)
      )





;;;;;;;;;;;;;;;;;;;;;;;;;sort es_size_tb;;;;;;;;;;;;;;END  check ok    

      (setq n 0)
      ;(setq mxb_num 0)
      (setq es_tb_ nil
	    es_size_pos_tb
	     nil
      )
      (foreach es_size_tb_temp es_size_tb_
					;(alert "xxx")
	(setq OD_value (car es_size_tb_temp))
	(setq ID_value (cadr es_size_tb_temp))
	(setq es_pos_tb nil)
	(setq es_pos_ nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;each size add ID ADD START
	(foreach es_data_temp es_total_tb ;ok
	  (if (and
		(= od_value (car (car es_data_temp)))
		(= id_value (cadr (car es_data_temp)))
	      )




	    (progn
					;(print dia_value)
					;(print es_size_tb_temp)

					;(alert "sfdf")
	      (setq es_x (- (car (cdr es_data_temp)) x1))
	      (setq es_y (- (cadr (cdr es_data_temp)) y1))
	      (setq cenpt (list
			    es_x
			    es_y
			  )
	      )


	      (if (not (tblsearch "style" "lxy2"))
		(command "-style" "lxy2" "txt" "" 0.6 "" "" "" "")
		(setvar "textstyle" "lxy2")
	      )
	      (setq
		textpt (polar cenpt
			      (* (/ pi 4) 1)
			      (+ (/ OD_VALUE 2) 2.5)
		       )
	      )
	      (setq
		textpt_	(polar textpt
			       (* (/ pi 2) -1)
			       2.5
			)
	      )
	      (setq num_id (strcat "#"
				   (strcat "s"
					   (itoa (- mxb_num num_ini))
				   )


			   )
	      )
	      (command "text"
		       "j"
		       "TL"
		       textpt
		       2.5
		       0
		       (strcat "S"(itoa (+ 1 n)))   
	      )
	      (command "text"
		       "j"
		       "TL"
		       textpt_
		       2
		       0
		      num_id
	      )

	      (setq es_pos_ (cons cenpt es_pos_))
	      (setq mxb_num (+ 1 mxb_num))
	      (setq mxb_y1 (+ mxb_y1 (* 1 8)))
	      (command
		"insert"
		"ep_pos.dwg"
		(list mxb_x1 mxb_y1)
		""
		""
		""
		(strcat "S" (itoa (+ 1 n)))
		num_id
		(rtos es_x 2 3)
		(strcat (rtos od_value 2 3) "/" (rtos id_value 2 3))
		(rtos es_y 2 3)
	      )

	    )

	  )
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;each size id add   END
	(setq es_pos_tb (list od_value es_pos_))
					;(print es_pos_tb)
					;(print "\n")
	(setq es_size_pos_tb
	       (cons
		 es_pos_tb
		 es_size_pos_tb
	       )
	)
	(setq n (+ 1 n))
      )
        
)



;;;;;;;;;;;;;;;;;;;;;;defun ej_id;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;start

(defun ej_id (obj _type _type_id /)
  (if mxb_num
  (setq num_ini (- mxb_num 1))
    (progn
      (setq mxb_num 0)
   (setq num_ini 1)
      )
    )
  (setq sel_ej obj)
  (setq ej_data_tb nil)
  (setq ej_dia_tb nil)
  (setq ej_data_tb nil)
  (setq n 0)
  (repeat (sslength sel_ej)
    (setq ej_data (entget (ssname sel_ej n)))
    (setq ej_dia   (cdr (assoc '41 ej_data))
	  ej_cenpt (cdr (assoc '10 ej_data))
    )
    (if	(not (member ej_dia ej_dia_tb))
      (setq ej_dia_tb (cons ej_dia ej_dia_tb))
    )
    (setq ej_data_tb (cons (cons ej_dia ej_cenpt) ej_data_tb))
    (setq n (+ 1 n))
  )
  (setq ej_dia_tb_ nil)
  (setq num_ 0)
  (foreach dia ej_dia_tb
    (setq n 0)
    (foreach dia_value ej_dia_tb
      (if (> dia dia_value)
	(setq n (+ 1 n))
      )
    )
    (setq ej_dia_tb_
	   (cons
	     (list n dia)
	     ej_dia_tb_
	   )
    )
    (setq num_ (+ 1 num_))
  )
;;;;;;;;;;;;;REDEFINE SORT
  (setq n 0)
  ;(setq mxb_num 0)
  (setq	ej_tb_ nil
	ej_size_pos_tb
	 nil
  )
  (repeat num_
    (setq dia_value (car (cdr (assoc n ej_dia_tb_)))) ;ok
    (setq ej_pos_tb nil)
    (setq ej_pos_ nil)
    (foreach ej_data_temp ej_data_tb	;ok
      (if (= dia_value (car ej_data_temp))
	(progn
					;(print dia_value)
					;(print (car (nth n1 ej_tb)))
					;(print "sfdf")
	  (setq ej_x (- (car (cdr ej_data_temp)) x1))
	  (setq ej_y (- (cadr (cdr ej_data_temp)) y1))
	  (setq	cenpt (list
			ej_x
			ej_y
		      )
	  )

	  (if (not (tblsearch "style" "lxy2"))
	    (command "-style" "lxy2" "txt" "" 0.6 "" "" "" "")
	    (setvar "textstyle" "lxy2")
	  )
	  (setq
	    textpt (polar cenpt
			  (* (/ pi 4) 1)
			  (+ (/ dia_value 2) 2.5)
		   )
	  )
	  (setq
	    textpt_ (polar textpt
			  (* (/ pi 2) -1)
			  2.5
		   )
	  )
	  (setq	num_id (strcat "#"
			       (strcat (strcase _type_id T)
				       (itoa (- mxb_num num_ini))
			       )

		       )
	  )


	  (command "text"
		   "j"
		   "TL"
		   textpt
		   2.5
		   0
		   (strcat _type_id
			   (strcat (itoa (+ 1 n))
				   
			   )
		   )
	  )
	  (command "text"
		   "j"
		   "TL"
		   textpt_
		   2
		   0
		   num_id
	  )
	  

	  (setq ej_pos_ (cons cenpt ej_pos_))
	  (setq mxb_num (+ 1 mxb_num))
	  (setq mxb_y1 (+ mxb_y1 (* 1 8)))
	  (command "insert"
		   "ep_pos.dwg"
		   (list mxb_x1 mxb_y1)
		   ""
		   ""
		   ""
		   (strcat _type_id (itoa (+ 1 n)))
		   num_id
		   (rtos ej_x 2 3)
		   (rtos dia_value 2 3)
		   (rtos ej_y 2 3)
	  )
	)

      )
    )

    (setq ej_pos_tb (list dia_value ej_pos_))
    ;(print ej_pos_tb)
    ;(print "\n")
    (setq ej_size_pos_tb
	   (cons
	     ej_pos_tb
	     ej_size_pos_tb
	   )
    )
    (setq n (+ 1 n))
  )					;ej_sel
)

(defun find_add	(/ )
  (setq obj_sel (ssget))
  (setq n 0)
  (setq ej_sel (ssadd))
  (setq es_sel (ssadd))
  (repeat (sslength obj_sel)
    (setq obj (entget (ssname obj_sel n)))
    (if	(= "CIRCLE" (cdr (assoc '0 obj)))
      (setq ej_sel (ssadd (ssname obj_sel n) ej_sel))
      (progn
	(if (= "ARC" (cdr (assoc '0 obj)))
	  (setq es_sel (ssadd (ssname obj_sel n) es_sel))
	)
      )
    )
    (setq n (+ 1 n))
  )


  (if (> (sslength EJ_sel) 0)
    (progn
      (if
	(not (tblsearch "layer" "ej_old"))
	 (command "_.layer"   "_new"	  "ej_old"    "_color"
		  "4"	      "ej_old"	  "_ltype"    "continuous"
		  "mxb"	      ""
		 )
	 ;(command "_.layer" "thaw" "ej_old" "on" "mxb" "unlock"	"mxb" "")
      )
      (change_prop ej_sel "ej_old" "" "")
      (find_ej ej_sel)
    )
  )

  (if (> (sslength es_sel) 0)
    (progn
      (if
	(not (tblsearch "layer" "ej_old"))
	 (command "_.layer"   "_new"	  "ej_old"    "_color"
		  "4"	      "ej_old"	  "_ltype"    "continuous"
		  "mxb"	      ""
		 )
	 ;(command "_.layer" "thaw" "ej_old" "on" "mxb" "unlock"	"mxb" "")
      )
      (change_prop es_sel "ej_old" "" "")
      (find_es_pin)
    )
  )
)