;|
2  ______ 3
   |    |
   |    |
   |    |
   |    |
   |    |
   |    |
   |    |
   |    | 4
   |    |_______ 5
   |            |
1  |____________| 6
;|;


(apply
	'(lambda( / x )
		(or mai_pile_text
			(not (setq x (mai_panel_search "谜你结构专业设置文件[mini_jiegou_config].lsp")))
			(load x)
		)
	)
	nil
)


 ;画椭圆桩，迷你建筑工具修改版
(defun c:mini_htyz ( / ss n zqdis2 zqdis6 old_pwidth old_cmd  panduandingdian drawpile ent
						qcdis2 zcdis2 qcdis6 zcdis6 zhuangjing ctpyz5 ctpyz1 zhuangchangquzheng
					)

	(mai_last_com "mini_htyz")
	(mai_get_scale)

	(setq
		qcdis2 100            ;承台距墙初设距离
		zcdis2 300            ;桩距承台边距离
		qcdis6 75            ;承台距墙初设距离
		zcdis6 150            ;桩距承台边距离
		zhuangjing 900            ;桩直径
		ctpyz5 150            ;承台直线距桩直线距离（点5向）
		ctpyz1 150            ;承台直线距桩直线距离（点1向）
		zhuangchangquzheng 200           ;桩直线段长度取整
	)

(defun panduandingdian ( pl_data / p1 p2 p3 p4 p5 p6 positation lens)
	(setq
		lens (mapcar '(lambda (x) (distance (car x) (cadr x))) pl_data)
		positation (- (length lens) (length (mai_member (apply 'max lens) lens)))
		lens (append pl_data pl_data)
	)
	(mapcar
		'set
		'(p1 p2 p3 p4 p5 p6)
		(mapcar '(lambda (x) (nth (+ positation x) lens)) (list 0 1 2 3 4 5))
	)
	(if (> (distance (car p2) (cadr p2)) (distance (car p6) (cadr p6)))
		(mapcar 'car (list p1 p2 p3 p4 p5 p6))
		(mapcar 'cadr (list p1 p6 p5 p4 p3 p2))
	)
)

(defun drawpile ( ename / p1 p2 p3 p4 p5 p6 p2mp4 p1mp5 pmlist pc2 pc6
						cen len yuan2yx yuan6yx yuan2c0 yuan6c0 yuan2c1 yuan6c1
						yuan2c5  yuan6c5 pc21 pc61 pc25 pc65 ang1 ang2 ang3 rad
				)
	(setq pmlist (panduandingdian ename))
	(mapcar 'set '(p1 p2 p3 p4 p5 p6) pmlist)
	(setq
		p2mp4 (mai_divide_point p2 p4 0.5)
		p1mp5 (mai_divide_point p1 p5 0.5)
		pmlist (mapcar '(lambda(x) (mai_point_per2line x p2mp4 p1mp5)) pmlist); p1~p6在中线上的垂足列表
		pmlist (vl-sort pmlist '(lambda (e1 e2) (< (car e1) (car e2))))
		pc2 (car pmlist)
		pc6 (last pmlist)
		ang1 (angle pc6 pc2)
		ang2 (+ ang1 (/ pi 2))
		rad (/ zhuangjing 2)
		cen (mai_divide_point (polar pc2 ang1 (- zqdis2)) (polar pc6 ang1 zqdis6) 0.5) ;桩中点
		len (- (distance pc2 pc6) zqdis2 zqdis6 rad rad);桩直线段长
		len (* (1+ (fix (/ len zhuangchangquzheng))) zhuangchangquzheng 0.5);桩直线段长取50整数,半长
		yuan2yx (polar cen ang1 len)
		yuan6yx (polar cen ang1 (- len))
		yuan6c0 (+ len rad)
		yuan2c0 (polar cen ang1 yuan6c0)
		yuan6c0 (polar cen ang1 (- yuan6c0))
		yuan2c1 (polar yuan2yx ang2 rad)
		yuan6c1 (polar yuan6yx ang2 rad)
		yuan2c5 (polar yuan2yx ang2 (- rad))
		yuan6c5 (polar yuan6yx ang2 (- rad))
	)
	(setvar "plinewid" 0)
	(apply 'mai_create_layer mai_pile_layer)
	(command "_.pline" "non" yuan2c1 "a" "s" "non" yuan2c0 "non" yuan2c5 "l" "non" yuan6c5 "a" "s" "non" yuan6c0 "non" yuan6c1 "l" "c")

	;桩心画十字
	(setvar "plinewid" 20)
	(mai_entmake "lwpolyline" (list (mai_point_offset yuan2yx 75 0) (mai_point_offset yuan2yx -75 0)))
	(mai_entmake "lwpolyline" (list (mai_point_offset yuan2yx 0 75) (mai_point_offset yuan2yx 0 -75)))
	(mai_entmake "lwpolyline" (list (mai_point_offset yuan6yx 75 0) (mai_point_offset yuan6yx -75 0)))
	(mai_entmake "lwpolyline" (list (mai_point_offset yuan6yx 0 75) (mai_point_offset yuan6yx 0 -75)))

	(setq
		pc2 (polar yuan2c0 ang1 zcdis2) ;承台在中线上的外围点
		pc6 (polar yuan6c0 ang1 (- zcdis6)) ;承台在中线上的外围点
		pc61 (+ rad ctpyz1)
		pc21 (polar pc2 ang2 pc61)
		pc61 (polar pc6 ang2 pc61)
		pc65 (- (+ rad ctpyz5))
		pc25 (polar pc2 ang2 pc65)
		pc65 (polar pc6 ang2 pc65)
	)
	(apply 'mai_create_layer mai_chengtai_layer)
	(mai_entmake "lwpolyline" (list pc21 pc25 pc65 pc61 pc21))

	;承台标注点计算、承台标注
	(setq
		p3 (mai_point_per2line yuan2c5 pc25 pc65)
		p5 (mai_point_per2line yuan6c5 pc25 pc65)
		p1 (polar pc2 ang1 (* mai_scale2 6))
		p2 (polar pc25 (angle yuan2yx yuan2c5) (* mai_scale2 6))
	)
	(apply 'mai_create_layer mai_chengtai_layer)
	(command "_.dimlinear" "non" pc21 "non" pc2 "r" "non" pc21 "non" pc2 "non" p1)
	(command "_.dimlinear" "non" pc2 "non" pc25 "r" "non" pc2 "non" pc25 "non" p1)
	(command "_.dimlinear" "non" pc25 "non" p3 "r" "non" pc25 "non" p3 "non" p2)
	(command "_.dimlinear" "non" p3 "non" p5 "r" "non" p3 "non" p5 "non" p2)
	(command "_.dimlinear" "non" p5 "non" pc65 "r" "non" p5 "non" pc65 "non" p2)
)


	(mini_start nil)
	(setq
		old_pwidth (getvar "plinewid")
		zqdis2 (- zcdis2 qcdis2)
		zqdis6 (- zcdis6 qcdis6)
		ss (mai_select_first '((0 . "LWPOLYLINE")) "选择需要画椭圆桩的多段线:<退出>" "没有找到多段线.")
	)
	(setvar "plinewid" 0)
	(foreach n (mai_ssget_2_list ss)
		(mai_clean_pline n) ;清理多段线
		(setq n (mai_data_entget2pline n))
		(if (= (length n) 6) (drawpile n))
	)
	(mai_end)
)
