(defun mai_erase_ent_in_lay ( LAY / SS )
	(and
		(setq ss (ssget "x" (list (cons 8 lay))))
		(mai_entdel ss nil)
	)
	(princ)
)
(defun mai_ureal (bit kwd msg def )
	(if def
		(setq
			msg (strcat "\n" msg "<" (rtos def 2 4) ">: ")
			bit (* 2 (fix (/ bit 2)))
		)
		(setq msg (strcat "\n" msg ": "))
	)
	(initget bit kwd)
	(cond ((getreal msg)) (def))
)

(defun mai_ukword (bit kwd msg def / inp)
	(if (mai_not_str def)
		(setq msg (strcat "\n" msg ":"))
		(setq
			msg (strcat "\n" msg ":<" def ">")
			bit (* 2 (fix (/ bit 2)))
		)
	)
	(initget bit kwd)
	(cond ((getkword msg)) (def))
)


;++++++++++++++++++++++
;+ gj=1 加一级钢筋头  +
;++++++++++++++++++++++
;++++++++++++++++++++++
;+ gj=2 加二级钢筋头  +
;++++++++++++++++++++++
(defun mai_rein_tou (p1 p2 p5 gj / p3 p4 p5 p6 ang scale)
	(setq
		p5 (if (= (mai_data_type p5) "POINT")
				p5
				(polar p1 p5 100)
			)
		ang (angle p1 p2)
		p6 (mai_point_per2line p5 p1 p2)
		p5 (if (or (mai_equal p5 p6)
					(mai_equal_angle (angle p6 p5) (+ ang (* 0.5 pi)))
				)
				1
				-1
			)
		scale (/ 100. mai_scale2)
	)
	(if (= gj 2)
		(polar (polar p1 ang (* scale 20)) (+ ang (* p5 0.5 pi)) (* scale 12))
		(progn
			(setq
				p4 (polar (polar p1 ang (* scale 10)) (+ ang (* p5 0.5 pi)) (* scale 25))
				p3 (polar p4 ang (* scale -10.))
			)
			(list p4 p3 p5)
		)
	)
)

(defun mai_make_dmpj ( p1 p2 kujing off_dist / p3 p4 p5 p6 p7 p8 ps old_filletrad scale)
	(setq ps (mai_fence_Offset (mai_data_corner2 "fence" (list p1 p2)) (abs off_dist) (> off_dist 0)))
	(mapcar 'set '(p1 p2 p3 p4) ps)
	(setq
		scale (/ 100. mai_scale2)
		p5 (mapcar '- p3 (list (* scale 32) (* scale 58)))
		p6 (mapcar '- p3 (list 0 (* scale 26)))
		p7 (mapcar '- p3 (list (* scale 26) 0))
		p8 (mapcar '- p3 (list (* scale 58) (* scale 32)))
		old_filletrad (getvar "filletrad")
	)
	(apply 'mai_create_layer mai_rein_layer)
	(setvar "plinewid" (* mai_rein_width scale))
	(mai_entmake "lwpolyline" (list p5 p6 p3 p4 p1 p2 p3 p7 p8))
	(setvar "filletrad" (* scale 15))
	(command "_.fillet" "p" "l")
	(setvar "filletrad" old_filletrad)
	(if kujing
		(mapcar
			'(lambda (x) (mai_entmake "DONUT" (list x 0 (* scale 20))))
			(cdr (mai_fence_Offset ps (* scale 15) T))
		)
	)
	(princ)
) ;defun c:s1 end
;+++++++++++++++++++++
;+  画单根箍筋(S筋)  +
;+++++++++++++++++++++
(defun mai_make_dgsj ( p1 p2 / old_filletrad p1 p2 p3 p4 p5 p6 P7 P8 scale ang p9 p10 ang1 )
	(setq
		ang (angle p1 p2)
		scale (/ 100. mai_scale2)
		ang1 (+ ang (* 0.5 pi))
		p3 (polar (polar p1 ang (* scale -15)) ang1 (* scale -15))
		p4 (polar (polar p1 ang (* scale 5)) ang1 (* scale -15))
		p5 (polar (polar p1 ang (* scale -15)) ang1 (* scale 15))
		p6 (polar (polar p1 ang (* scale 30)) ang1 (* scale 15))
		p7 (polar (polar p2 ang (* scale 15)) ang1 (* scale 15))
		p8 (polar (polar p2 ang (* scale -5)) ang1 (* scale 15))
		p9 (polar (polar p2 ang (* scale 15)) ang1 (* scale -15))
		p10 (polar (polar p2 ang (* scale -30)) ang1 (* scale -15))
		old_filletrad (getvar "filletrad")
	)
	(setvar "filletrad" (* scale 15))
	(apply 'mai_create_layer mai_rein_layer)
	(setvar "plinewid" (* mai_rein_width scale))
	(mai_entmake "lwpolyline" (list p6 p5 p3 p4 p8 p7 p9 p10))
	(command "_.fillet" "p" "l")
	(princ)
) ;defun c:s5 end

(defun mai_select_rein ( ea / p na p1 p2 pa pb pc par)
	(setq
		p1 (trans (cadr ea) 1 0)
		ea (car ea)
		na (vlax-ename->vla-object ea)
	)
	(if (member (vlax-get-property na 'ObjectName) (list "AcDbPolyline" "AcDbLine"))
		(progn
			(setq
				p1 (vlax-curve-getclosestpointto ea p1)
				pa (vlax-curve-getstartparam ea)
				pb (vlax-curve-getendparam ea)
				par (vlax-curve-getparamatpoint ea p1)
				pc (< (abs (- par pa)) (abs (- par pb)))
				p1 (trans (if pc (vlax-curve-getstartpoint ea) (vlax-curve-getendpoint ea)) 0 1)
				p2 (trans (mai_curve_getpointatparam ea (if pc (1+ pa) (1- pb))) 0 1)
			)
			(list p1 p2)
		)
	)
)


;自由翻转mini_gj_flips
(defun mai_gj_flips ( old_ent po ang1 pax pay /  pt pt1 pt2 ppx ppy ddrag go_bg ang2 tt tips px py rotate_ent old_selectioncycling )
	(setq
		ang1 (mai_fix_ang ang1)
		ang1 (- ang1 (if (> (* 1.75 pi) ang1 (* 0.75 pi)) pi 0))
		pt1 (polar po ang1 10)
		pt2 (polar po (+ ang1 (* 0.5 pi)) 10)
		px 1
		py 1
		tt (type old_ent)
	)
	(setq old_selectioncycling (getvar "selectioncycling"))
	(if old_selectioncycling (setvar "selectioncycling" 0))
	(prompt "\r 输入方向:\t")
	(while (not go_bg)
		(redraw)
		(cond ((= tt 'ENAME) (redraw old_ent 3)))
		(setq
			pt (grread 5)
			ddrag (car pt)
			pt (cadr pt)
		)
		(cond
			(	(and rotate_ent (= 2 ddrag) (member pt (list 122 90)))
				(command "_.rotate" old_ent ""  "non" po 90)
				(setq tips px px py py tips)
			)
			
			(	(= (type pt) 'list)
				(grdraw po pt 1 1)
				(setq ang2 (mai_arc_ang ang1 (angle po pt)))
				(cond
					((>= (* 0.5 pi) ang2 0) (setq ppx 1 ppy 1))
					((>=  pi ang2 (* 0.5 pi)) (setq ppx -1 ppy 1))
					((>= (* 1.5 pi) ang2 pi) (setq ppx -1 ppy -1))
					((>= (* 2. pi) ang2 (* 1.5 pi)) (setq ppx 1 ppy -1))
				)
				(if (and pay (/= ppx px)) (command "_.mirror" old_ent "" "non" po "non" pt2 "y"))
				(if (and pax (/= ppy py)) (command "_.mirror" old_ent "" "non" po "non" pt1 "y"))
				(grdraw po pt 1 1)
				(setq px ppx py ppy) 
			)
		)
		(or (and rotate_ent (= 2 ddrag) (member pt (list 122 90)))
			(if (or (= ddrag 3) (/= (type pt) 'list))
				(setq go_bg T)
			)
		)
	)
	(cond ((= tt 'ENAME) (redraw old_ent 4)))
	(redraw)
	(princ)
)


(defun mai_text_replace ( ss han1 han2 zkey / input_op repalce ent ent1 elst ename chm chf txt atts )


(defun input_op ( elst / zpt th zh pt1 pt2 pt3 )
	(setq
		zpt (trans (mai_dxf 10 elst) 0 1) ;取文字插点
		th (mai_dxf 40 elst)
		zh (* 25 th) ;度
		th (* th 3)
		pt1 (mai_point_offset zpt (- th) th)
		pt2 (mai_point_offset zpt (* th -0.26) (* th 0.43))
		pt3 (mai_point_offset zpt (* th -0.43) (* th 0.26))
	)
	(command "zoom" "c" zpt zh)
	(grdraw zpt pt1 1)
	(grdraw zpt pt2 1)
	(grdraw zpt pt3 1)
	(princ "\n请看红色箭头的地方！")
	(initget "Aexit Qexit Cnext Nnext")
	(setq
		zkey
			(getkword
				"\n[全部修改(A)/退出后面不改(Q)/修改并显示下一个(C)/不修改显示下一个(N)]:<修改并显示下一个(C)>"
			)
	)
	(or zkey (setq zkey "Cnext"))
	(redraw)
	(princ)
)

(defun repalce ( txt han1 han2 / chf po )
	(while (setq po (vl-string-search han1 txt))
		(setq
			chf T
			txt (strcat (substr txt 1 po) han2 (substr txt (+ 1 po (strlen han1))))
		)
	)
	(if chf txt)
)



	(if (= 0 (strlen han1)) (setq ss nil))
	(setq
		ss (mai_ssget_2_list ss)
		chm 0
	)
	(while (and ss (/= zkey "Qexit"))
		(setq
			ent (car ss)
			ss (cdr ss)
			elst (entget ent)
			ename (mai_dxf 0 elst)
		)
		(cond
			(	(wcmatch ename "TEXT,MTEXT")
				(and
					(setq chf (repalce (mai_dxf 1 elst) han1 han2))
					(/= zkey "Aexit")
					(input_op elst)
				)
				(and chf
					(member zkey (list "Aexit" "Cnext"))
					(setq chm (1+ chm))
					(entmod (subst (cons 1 chf) (assoc 1 elst) elst))
				)
			)
			
			(	(and
					(= ename "INSERT")
					(setq atts (mai_get_blk_atts ent))
				)
				(while (and atts (/= zkey "Qexit"))
					(setq
						txt (car atts)
						atts (cdr atts)
						ent1 (car txt)
						elst (entget ent1)
						chf (repalce (caddr txt) han1 han2)
					)
					(and
						chf
						(/= zkey "Aexit")
						(input_op elst)
					)
					(and chf
						(member zkey (list "Aexit" "Cnext"))
						(setq chm (1+ chm))
						(progn
							(entmod (subst (cons 1 chf) (assoc 1 elst) elst))
							(entupd ent1)
						)
					)
				)
				(entupd ent)
			)
		)
	)
	(or (= (strlen han1) 0)
		(princ (strcat "\n 修改了【" (itoa chm) " 行】文字，把【" han1 "】修改为【" han2 "】。"))
	)
	zkey
)
