- (setvar "cmdecho" 0)
- (defun c:tx (/ region pointregion Moment
- minp maxp newminp newmaxp Yx
- Yy
- )
- (print "Select a region:")
- (setq region (car (entsel)));_选择面域
- (while (or (null region);_空选
- (/= (cdr (assoc '0 (entget region))) "REGION");_非面域
- )
- (print "Select a region:")
- (setq region (car (entsel)));_重新点选
- );_循环直至点选的实体为面域
- (command "ucs" "W");_转为世界坐标
- (SETQ vlaregion (vlax-ename->vla-object region));_转化为 Object
- (setq pointregion
- (vlax-safearray->list
- (vlax-variant-value (vla-get-Centroid vlaregion));_质心
- )
- )
- (command "osnap" "none")
- (command "ucs" "m" pointregion);_设置UCS
- (setq
- Moment (vlax-safearray->list
- (vlax-variant-value (vla-get-MomentOfInertia vlaregion))
- )
- )
- (vla-getboundingbox vlaregion 'minpoint 'maxpoint);_包围盒
- (setq minp (vlax-safearray->list minpoint))
- (setq maxp (vlax-safearray->list maxpoint))
- (setq newminp (list (- (car minp) (car pointregion))
- (- (cadr minp) (cadr pointregion))
- )
- )
- (setq newmaxp (list (- (car maxp) (car pointregion))
- (- (cadr maxp) (cadr pointregion))
- )
- )
- (setq Yx (max (abs (cadr newminp)) (abs (cadr newmaxp))))
- (setq Yy (max (abs (car newminp)) (abs (car newmaxp))))
- (princ "\n")
- (princ "\nArea=:")
- (princ (vla-get-Area vlaregion));_面积
- (princ "\nIx=:")
- (princ (car Moment))
- (princ "\nIy=:")
- (princ (cadr Moment))
- (princ "\nYx=:")
- (princ Yx)
- (princ "\nYy=:")
- (princ Yy)
- (princ "\nWx=:")
- (princ (/ (car Moment) Yx))
- (princ "\nWy=:")
- (princ (/ (cadr Moment) Yy))
- (princ "\n")
- (command "OSMODE" "16383")
- (command "massprop" region "")
- )
|