您的位置:网站首页 > CAD新闻

在cad中求不规则图形的形心

时间:2009-05-27 07:44:45 来源:
一个是可以求某一图层上封闭实体的形心,程序根据你输入的图层自动选择该层上所有实体,
;;;再根据你点取的点求取点所在周边封闭实体的形心并显示在“point”图层上,如下:
(defun ez (/ f xxx xxy xxx1 xxy1 xxx2 xxy2 cep oldom oldcm oldbm oldfd oldlp oldla pt en ptlist ss la enpt)
(prompt "形心求解器修改版 0.2 2004年6月26日")
(command "undo" "group")
(setq oldla (getar "CLAYER"))
(setq oldcm (getar "CMDECHO"))
(setq oldfd (getar "FILEDIA"))
(setq oldlp (getar "LUPREC"))
(setq oldom (getar "OSMODE"))
(setq oldbm (getar "BLIPMODE"))
(setq oldpm (getar "PDMODE"))
(setar "CMDECHO" 0)
(setar "FILEDIA" 0)
(setar "LUPREC" 8)
(setar "OSMODE" 0)
(setar "BLIPMODE" 1)

(if (not laname) (setq laname "c-h"))
(setq la (getstring (strcat "n请输欲求形心的实体所在图层名<" laname "或当前层>:")))
(if (= la "") (setq la laname) (setq laname la))
(if (tblsearch "LAYER" la)
(setq ss (ssget "X" (list (cons 8 la))))
(setq ss (ssget "X"))
)
(while
(setq pt (getpoint "n请点取欲求形心的封闭实体内部点:"))
(setq ptlist (append ptlist (list pt)))
)
(if ss
(progn
(if ptlist
(progn
(foreach pt ptlist
(command "-boundary" "a" "o" "r" "b" "n" ss "" "" pt "")
(setq en (entget (entlast)))
(if (equal (assoc 0 en) '(0 . "REGION"))
(progn
(command "massprop" "l" "" "y" "c:/ZZX.mpr")
(command "_erase" "l" "")
(setq f (open "c:/ZZX.mpr" "r"))
(read-line f)
(read-line f)
(read-line f)
(read-line f)
(read-line f)
(read-line f)
(read-line f)
(setq xxx (read-line f))
(setq xxy (read-line f))
(close f)
(setq xxx1 (substr xxx 25 20))
(setq xxy1 (substr xxy 25 20))
(setq xxx2 (atof xxx1))
(setq xxy2 (atof xxy1))
(setq cep (list xxx2 xxy2 0))
(setq enpt (entmake (list (cons 0 "point")(cons 8 "point") (cons 10 cep))))
);;;end progn
(prompt "n没有选到符合求形心条件的东东,退出!")
);;;end if
);;;end foreach
(if enpt
(progn
(command "-layer" "on" "point" "")
(if (/= (getar "pdmode") 3) (setar "pdmode" 3))
(command "_redraw")
(princ)
(prompt "nn 多义线的形心已用点显示在point图层,如果有必要请定义过点的形式以显示得更好")
);;;end progn
);;;end if
);;;end progn
(prompt "n 没有选到任何点,退出!")
);;;end if ptlist
);;;end progn
(prompt "n没有选到符合求形心条件的东东,退出!")
);;;end if ss
(setar "FILEDIA" oldfd)
(setar "LUPREC" oldlp)
(setar "CMDECHO" oldcm)
(setar "OSMODE" oldom)
(setar "CLAYER" oldla)
(setar "BLIPMODE" oldbm)
(setar "PDMODE" oldpm)
(command "undo" "end")
(princ)
);;;end defun


使用了一下,感觉不错
在材料力学中应该有较大用处