fango 发表于 2003-3-20 16:39:00

请问如何用VLA-GET-PROPERTY或其他方法获得一实体(SOLID)的质量

请问如何用VLA-GET-PROPERTY或其他方法获得一实体(SOLID)的质量?希望是比较完整的一段代码!谢谢各位!

龙龙仔 发表于 2003-3-21 08:10:00

VxGetMassProps - Returns a list of all mass properties of the object

;;; VxGetMassProps - Returns a list of all mass properties of the object
;;; -- Function VxGetMassProps
;;; Returns a list of all mass properties of the object.
;;; Copyright:
;;;   2001 MENZI ENGINEERING GmbH, Switzerland
;;; Arguments :
;;;   Obj = Object
;;; Return :
;;;   > Mass properties '({Area Perimeter} {Mass Volume}
;;;                            Centroid          MomentOfInertia
;;;                            ProductOfInertiaRadiiOfGyration
;;;                            PrincipalMomentsPrincipalDirections
;;;                     )
;;; Notes:
;;; - VxGetMassProps is designed to handle closed *Polylines,
;;;   Regions and 3dsolids.
;;; - *Polylines and Regions returns 2D-lists in some parameters.
;;; - 2D-objects returns '({Area Perimeter}. . . . . . )
;;; - 3D-objects returns '({Mass Volume}. . . . . . )
;;; - Use a DocManagerReactor with a 'vlr-documentToBeDestroyed'-event
;;;   to release the Gb:AcO and Gb:AcD objects at the end of a
;;;   AutoCAD session - otherwise AutoCAD maybe crashes...
;;; USAGE: (VXGETMASSPROPS (vlax-ename->vla-object (car (entsel))))
;;; Modify By: 龍龍仔(LUCAS)

(defun VXGETMASSPROPS (OBJ / DELFLG RESLST TMPOBJ)
(setq        GB:ACO (cond (GB:ACO)
                     ((vlax-get-acad-object))
             )
        GB:ACD (cond (GB:ACD)
                     ((vla-get-activedocument GB:ACO))
             )
)
(if (member (vla-get-objectname OBJ)
              '("AcDb2dPolyline" "AcDbPolyline")
      )
    (setq DELFLG t
          TMPOBJ (vlax-safearray-get-element
                   (vlax-variant-value
                     (vla-addregion
                     (vla-get-modelspace GB:ACD)
                     (VXLISTTOARRAY vlax-vbobject (list OBJ))
                     )
                   )
                   0
               )
    )
    (setq TMPOBJ OBJ)
)
(setq        RESLST
       (append
           (list
             (if (= (vla-get-objectname TMPOBJ) "AcDbRegion")
             (progn
               (list (vla-get-area TMPOBJ) (vla-get-perimeter TMPOBJ))
             )
             (list (vla-get-volume TMPOBJ) (vla-get-volume TMPOBJ))
             )
             (vlax-safearray->list
             (vlax-variant-value (vla-get-centroid TMPOBJ))
             )
             (vlax-safearray->list
             (vlax-variant-value (vla-get-momentofinertia TMPOBJ))
             )
             (if (= (vla-get-objectname TMPOBJ) "AcDbRegion")
             (list (vla-get-productofinertia TMPOBJ))
             (vlax-safearray->list
               (vlax-variant-value
                   (vla-get-productofinertia TMPOBJ)
               )
             )
             )
             (vlax-safearray->list
             (vlax-variant-value (vla-get-radiiofgyration TMPOBJ))
             )
             (vlax-safearray->list
             (vlax-variant-value (vla-get-principalmoments TMPOBJ))
             )
             (vlax-safearray->list
             (vlax-variant-value
               (vla-get-principaldirections TMPOBJ)
             )
             )
           )
       )
)
(if DELFLG
    (vla-delete TMPOBJ)
)
RESLST
)


; VxListToArray - Converts a list into an array
; -- Function VxListToArray
; Converts a list into an array.
; Copyright:
;   2000 MENZI ENGINEERING GmbH, Switzerland
; Arguments :
;   Lst = Standard list
;   Typ = Datatype
;         Constants:
;         - vlax-vbBoolean
;         - vlax-vbDecimal *)
;         - vlax-vbDouble
;         - vlax-vbInteger
;         - vlax-vbLong
;         - vlax-vbObject
;         - vlax-vbSingle
;         - vlax-vbString
;         - vlax-vbVariant
; Return :
;   > Array
; Notes:
;   *)Missing datatype in Visual LISP, initialize it in your Autoloader.
;   - Can't be used for dotted pair or nested lists.
;

(defun VxListToArray (Typ Lst)
(vlax-make-variant
(vlax-safearray-fill
   (vlax-make-safearray Typ (cons 0 (1- (length Lst))))
   Lst
)
)
)
页: [1]
查看完整版本: 请问如何用VLA-GET-PROPERTY或其他方法获得一实体(SOLID)的质量