;封闭曲线内文字排版并居中[mini_qzwz].lsp
(defun c:mini_qzwz ( / old_cmd mai_bak_osmode e cen ss fen ent del len )
	(mai_start nil)
	(mai_last_com "mini_qzwz")
	(setq
		ss (mai_select_firsts
				'((0 . "circle,*polyline,spline,ellipse"))
				"选择要范围内文字排版或其他实体居中的封闭曲线:<回车点选范围>"
				"没有找到曲线."
				nil
			)
	)
	(if ss
		;(setq ss (vl-remove-if-not 'mai_curve_isclosed (mai_ssget_2_list SS)))
		(mai_zoom2ssget ss T)
		(progn
			(setq mai_bak_osmode (getvar "osmode"))
			(setvar "osmode" 0)
			(setq ss (getpoint "\n选取封闭域内一点:<回车退出>"))
			(setvar "osmode" mai_bak_osmode)
			(if ss
				(setq del T ss (mai_ssget_2_list (mai_bo_point1 ss nil nil)))
			)
		)
	)
	(or ss (exit))
	(foreach e ss
		(and del 
			(setq cen (mai_obj_offset e -0.0001 nil nil))
			(progn
				(entdel e)
				(setq e (ssname cen 0))
				(mai_entdel cen e)
			)
		)
		(setq
			fen (mai_curve_fence e)
			cen (caddr (mai_getboundingbox e))
		)
		(if del (entdel e))
		(and
			(setq ent (ssget (if del "wp" "cp") fen))
			(progn
				(foreach e ss (ssdel e ent))
				(> (setq len (sslength ent)) 0)
			)
			(progn
				(and
					(> len 1)
					(vl-every '(lambda(x) (wcmatch (mai_dxf 0 x) "*TEXT")) (mai_ssget_2_list ent))
					(setq ent (mai_text_reorder ent nil (if (= (sslength ent) 1) "S" "Z")))
				)
				(setq
					e (mai_ss_rectangle ent)
					e (mai_divide_point (car e) (caddr e) 0.5)
				)
				(command "_.move" ent "" "non" e "non" cen)
			)
		)
	)
	(mai_end)
)


(defun c:mini_stjz ( / old_cmd mai_bak_osmode e cen ss fen ent del len view )
	(mai_start nil)
	(mai_last_com "mini_stjz")
	(setq
		ent (mai_select_firsts
				nil
				"选择要范围内居中的实体:<回车点选范围,范围内实体居中>"
				"没有找到实体."
				nil
			)
	)
	(if ent
		(progn
			(mai_zoom2ssget ent T)
			(setq
				view (mai_get_viewpt)
				ss (ssget "c" (car view) (cadr view))
				cen (mai_ss_rectangle ent)
				cen (mai_divide_point (car cen) (caddr cen) 0.5)
			)
			(foreach e (mai_ssget_2_list ent) (ssdel e ss))
			(setq ss (mai_ssget_2_list (mai_bo_point1 cen ss nil)))
			(or ss (exit))
			(setq cen (caddr (mai_getboundingbox (car ss))))
			(mai_entdel ss nil)
			(and
				(> (sslength ent) 1)
				(vl-every '(lambda(x) (wcmatch (mai_dxf 0 x) "*TEXT")) (mai_ssget_2_list ent))
				(setq ent (mai_text_reorder ent nil (if (= (sslength ent) 1) "S" "Z")))
			)
			(setq
				e (mai_ss_rectangle ent)
				e (mai_divide_point (car e) (caddr e) 0.5)
			)
			(command "_.move" ent "" "non" e "non" cen)
		)
		(and
			(progn
				(setq mai_bak_osmode (getvar "osmode"))
				(setvar "osmode" 0)
				(setq ss (getpoint "\n选取封闭域内一点:<回车退出>"))
			)
			(progn
				(setvar "osmode" mai_bak_osmode)
				(setq ss (mai_ssget_2_list (mai_bo_point1 ss nil nil)))
			)
			(progn
				(and
					(setq cen (mai_obj_offset (car ss) -0.0001 nil nil))
					(progn
						(mai_entdel ss nil)
						(setq e (ssname cen 0))
						(mai_entdel cen e)
					)
				)
				(setq
					fen (mai_curve_fence e)
					cen (caddr (mai_getboundingbox e))
				)
				(entdel e)
				(and
					(setq ent (ssget "wp" fen))
					(progn
						(and
							(> (sslength ent) 1)
							(vl-every '(lambda(x) (wcmatch (mai_dxf 0 x) "*TEXT")) (mai_ssget_2_list ent))
							(setq ent (mai_text_reorder ent nil (if (= (sslength ent) 1) "S" "Z")))
						)
						(setq
							e (mai_ss_rectangle ent)
							e (mai_divide_point (car e) (caddr e) 0.5)
						)
						(command "_.move" ent "" "non" e "non" cen)
					)
				)
			)
		)
	)
	(mai_end)
)
