Lisp lệnh HA trong chủ đề “Lisp tinh toan momen quan tinh xoan(J) cua tiet dien bat ky”
Tôi nhớ đã post cái này 1 lần, nhưng giờ quên link nên đành post lại. Hy vọng đúng ý bạn. Và nếu đúng thì xin nhận hậu tạ bằng LIKE cho gọn.
;Doan Van Ha - CADViet.com
;Tinh cac dac trung hinh hoc cua Polyline kin hoac Region.
(defun C:HA()
(setq obj (vlax-ename->vla-object (car (entsel "\Chon doi tuong kin (Polyline hoac Region): "))))
(VxGetMassProps Obj))
(defun VxGetMassProps (Obj / DelFlg ResLst TmpObj)
(or Gb:AcO (setq Gb:AcO (vlax-get-acad-object)))
(or Gb:AcD (setq 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 (list Obj) vlax-vbObject))) 0))
(setq TmpObj Obj))
(setq ResLst (append
(list
(vlax-get TmpObj 'Centroid)
(vlax-get TmpObj 'RadiiOfGyration)
(setq a (vlax-get TmpObj 'PrincipalDirections))
(vlax-get TmpObj 'PrincipalMoments)
(vlax-get TmpObj 'MomentOfInertia))
(if (= (vla-get-ObjectName TmpObj) "AcDbRegion")
(list
(vla-get-ProductOfInertia TmpObj)
(vla-get-Area TmpObj)
(vla-get-Perimeter TmpObj))
(list
(vlax-get TmpObj 'ProductOfInertia)
(vla-get-Volume TmpObj)
nil))))
(if DelFlg (vla-delete TmpObj))
(princ "\n\nKET QUA TINH: ")
(princ "\n1). Centroid: ")
(princ "\n X: ") (princ (car (nth 0 Reslst)))
(princ "\n Y: ") (princ (cadr (nth 0 Reslst)))
(princ "\n2). Radii Of Gyration: ")
(princ "\n X: ") (princ (car (nth 1 Reslst)))
(princ "\n Y: ") (princ (cadr (nth 1 Reslst)))
(princ "\n3). Principal Directions: ")
(princ "\n ") (princ (car (nth 2 Reslst)))
(princ "\n ") (princ (cadr (nth 2 Reslst)))
(princ "\n ") (princ (caddr (nth 2 Reslst)))
(princ "\n ") (princ (nth 3 (nth 2 Reslst)))
(princ "\n4). Principal Moments: ")
(princ "\n I: ") (princ (car (nth 3 Reslst)))
(princ "\n J: ") (princ (cadr (nth 3 Reslst)))
(princ "\n5). Moment Of Inertia: ")
(princ "\n X: ") (princ (car (nth 4 Reslst)))
(princ "\n Y: ") (princ (cadr (nth 4 Reslst)))
(princ "\n6). Product Of Inertia: ")
(princ (nth 5 Reslst))
(princ "\n7). Area: ")
(princ (nth 6 Reslst))
(princ "\n8). Perimeter: ")
(princ (nth 7 Reslst))
(textpage))
; (princ))
; ResLst=((70.5309 25.7049) (25.7963 70.5906) (0.966567 0.256415 -0.256415 0.966567) (285.635 561.65) (42933.0 321491.0) 116901.0 64.5172 37.4259)
;-----
(defun VxListToArray (Lst Typ)
(vlax-make-variant (vlax-safearray-fill (vlax-make-safearray Typ (cons 0 (1- (length Lst)))) Lst)))
- Tải lisp
- 240790_ha.lsp
Cách dùng
- Tải tệp 240790_ha.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh HA để chạy lisp.
Mã nguồn 240790_ha.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/73362-lisp-tinh-toan-momen-quan-tinh-xoanj-cua-tiet-dien-bat-ky/
;Doan Van Ha - CADViet.com
;Tinh cac dac trung hinh hoc cua Polyline kin hoac Region.
(defun C:HA()
(setq obj (vlax-ename->vla-object (car (entsel "\Chon doi tuong kin (Polyline hoac Region): "))))
(VxGetMassProps Obj))
(defun VxGetMassProps (Obj / DelFlg ResLst TmpObj)
(or Gb:AcO (setq Gb:AcO (vlax-get-acad-object)))
(or Gb:AcD (setq 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 (list Obj) vlax-vbObject))) 0))
(setq TmpObj Obj))
(setq ResLst (append
(list
(vlax-get TmpObj 'Centroid)
(vlax-get TmpObj 'RadiiOfGyration)
(setq a (vlax-get TmpObj 'PrincipalDirections))
(vlax-get TmpObj 'PrincipalMoments)
(vlax-get TmpObj 'MomentOfInertia))
(if (= (vla-get-ObjectName TmpObj) "AcDbRegion")
(list
(vla-get-ProductOfInertia TmpObj)
(vla-get-Area TmpObj)
(vla-get-Perimeter TmpObj))
(list
(vlax-get TmpObj 'ProductOfInertia)
(vla-get-Volume TmpObj)
nil))))
(if DelFlg (vla-delete TmpObj))
(princ "\n\nKET QUA TINH: ")
(princ "\n1). Centroid: ")
(princ "\n X: ") (princ (car (nth 0 Reslst)))
(princ "\n Y: ") (princ (cadr (nth 0 Reslst)))
(princ "\n2). Radii Of Gyration: ")
(princ "\n X: ") (princ (car (nth 1 Reslst)))
(princ "\n Y: ") (princ (cadr (nth 1 Reslst)))
(princ "\n3). Principal Directions: ")
(princ "\n ") (princ (car (nth 2 Reslst)))
(princ "\n ") (princ (cadr (nth 2 Reslst)))
(princ "\n ") (princ (caddr (nth 2 Reslst)))
(princ "\n ") (princ (nth 3 (nth 2 Reslst)))
(princ "\n4). Principal Moments: ")
(princ "\n I: ") (princ (car (nth 3 Reslst)))
(princ "\n J: ") (princ (cadr (nth 3 Reslst)))
(princ "\n5). Moment Of Inertia: ")
(princ "\n X: ") (princ (car (nth 4 Reslst)))
(princ "\n Y: ") (princ (cadr (nth 4 Reslst)))
(princ "\n6). Product Of Inertia: ")
(princ (nth 5 Reslst))
(princ "\n7). Area: ")
(princ (nth 6 Reslst))
(princ "\n8). Perimeter: ")
(princ (nth 7 Reslst))
(textpage))
; (princ))
; ResLst=((70.5309 25.7049) (25.7963 70.5906) (0.966567 0.256415 -0.256415 0.966567) (285.635 561.65) (42933.0 321491.0) 116901.0 64.5172 37.4259)
;-----
(defun VxListToArray (Lst Typ)
(vlax-make-variant (vlax-safearray-fill (vlax-make-safearray Typ (cons 0 (1- (length Lst)))) Lst)))
Thảo luận gốc
Lisp được chia sẻ trong chủ đề Lisp tinh toan momen quan tinh xoan(J) cua tiet dien bat ky. Xem đúng bài viết #240790 để đọc hướng dẫn và trao đổi thêm.