; 选边局部调整三角网[mini_triangle_chg].lsp

(or mai_cehui_gcd_blk
   (mai_load_files (mai_panel_search "谜你测绘功能设置文件.lsp"))
)



(defun c:mini_triangle_chg ( / old_cmd ent pts  pt lay p1 p2 p3 p4 p5 p6 obj_sty
                           )
  (mai_start nil)
  (mai_last_com "mini_triangle_chg")
  (while (setq ent (mai_Entsel nil "选择3dface,单选要调整边的三角网triangle:<回车退出>" "没有找到任何3dface." '((0 . "polyline,3dface")) nil))
     (setq pt (mai_3p_2p (cadr ent))
           ent (car ent)
           pts (entget ent)
           lay (assoc 8 pts)
           obj_sty (assoc 0 pts)
           pts (mai_get_face_points ent)
           pts (mai_m_trans pts 0 1)
     )
     (if (= 3 (length pts))
         (progn
              (mapcar 'set '(p1 p2 p3) pts)
              (setq pts (list (list (mai_dist_to_line pt (mai_3p_2p p1) (mai_3p_2p p2)) p1 p2 p3)
                              (list (mai_dist_to_line pt (mai_3p_2p p1) (mai_3p_2p p3)) p1 p3 p2)
                              (list (mai_dist_to_line pt (mai_3p_2p p2) (mai_3p_2p p3)) p2 p3 p1)
                        )
                    pts (cdar (vl-sort pts '(lambda(x y) (< (car x) (car y)))))
              )
              (mapcar 'set '(p1 p2 p3) pts)
              (setq p4 (mapcar 'min p1 p2 p3)
                    p5 (mapcar 'max p1 p2 p3)
                    pts (mai_divide_point p4 p5 0.5)
                    p4 (mai_divide_point pts p4 1.01)
                    p5 (mai_divide_point pts p5 1.01)
                    pts (ssget "c" p4 p5 (list obj_sty lay))
                    p6 nil
              )
              (ssdel ent pts)
              (vl-some '(lambda(x / y)
                           (setq y (vl-remove-if '(lambda(x)(mai_member x (list p1 p2))) (mai_get_face_points x)))
                           (if (= 1 (length y))
                               (setq p6 (cons x y))
                           )
                        )
                        (mai_ssget_2_list pts)
              )
              (if p6
                  (progn
                       (entdel ent)
                       (entdel (car p6))
                       (setvar "clayer" (cdr lay))
                       (mai_entmake (cdr obj_sty) (list p3 p1 (cadr p6)))
                       (mai_entmake (cdr obj_sty) (list p3 p2 (cadr p6)))
                  )
              )
         )
     )
  )
  (mai_end)
)
