马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- (defun c:centroid ( / v^v unit ucs x y ss ent enta n p )
- (vl-load-com)
- (defun v^v ( u v )
- (mapcar '(lambda ( s1 s2 a b ) (+ ((eval s1) (* (nth a u) (nth b v))) ((eval s2) (* (nth a v) (nth b u))))) '(+ - +) '(- + -) '(1 0 0) '(2 2 1))
- )
- (defun unit ( v )
- (mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
- )
- (if (/= (getvar 'worlducs) 1)
- (command "_.ucs" "_w")
- )
- (setq ss (ssget "_+.:E:S" '((0 . "3DSOLID,REGION"))))
- (setq ent (ssname ss 0))
- (setq enta (vlax-ename->vla-object ent))
- (if
- (eq (cdr (assoc 0 (entget ent))) "REGION")
- (progn
- (setq n (vlax-safearray->list (vlax-variant-value (vla-get-normal enta))))
- (if (equal (v^v n '(0.0 0.0 1.0)) '(0.0 0.0 0.0) 1e-6)
- (setq x '(1.0 0.0 0.0) y '(0.0 1.0 0.0))
- (setq x (unit (v^v n '(0.0 0.0 1.0))) y (unit (v^v n x)))
- )
- (command "_.explode" ent)
- (while
- (> (getvar 'cmdactive) 0)
- (command "")
- )
- (setq p (vlax-curve-getstartpoint (entlast)))
- (command "_.undo")
- (while
- (> (getvar 'cmdactive) 0)
- (command "")
- )
- (setq ucs (vla-add (vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point p) (vlax-3d-point (mapcar '+ p x)) (vlax-3d-point (mapcar '+ p y)) "{ UCS }"))
- (vla-put-activeucs (vla-get-activedocument (vlax-get-acad-object)) ucs)
- (command "_.UCS" "_D" "{ UCS }")
- (vlax-release-object ucs)
- (setq cent (trans (vlax-safearray->list (vlax-variant-value (vla-get-centroid enta))) 1 0))
- (command "_.ucs" "_p")
- )
- (setq cent (vlax-safearray->list (vlax-variant-value (vla-get-centroid enta))))
- )
- (prompt "\nCentroid : ") (princ cent)
- (prompt "\nVariable is called \"cent\" - you call it with !cent")
- (princ)
- )
|