明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3978|回复: 8

求助:如何读取_massprop命令的结果及自动选择面域

[复制链接]
发表于 2006-6-6 12:07:00 | 显示全部楼层 |阅读模式

我想编一个简单的查询面域的惯性矩的lisp程序,基本流程如下:先运行_massprop命令选择查询要查询的面域,此时坐标点并不在面域的形心点上,设定2个变量分别读取_massprop命令运行结果中的形心坐标x,y 值(eg. Centroid: X: -45.60  Y: 6.56),然后运行ucs命令将坐标原点设定为刚才读取的2个变量值,再次运行_massprop 命令,自动选取刚才查询的面域,显示正确的惯性矩值!

现在遇到了2个问题:一是如何读取_massprop命令的相应的查询结果,另一个就是如何在第二次运行_massprop命令时自动的把第一次运行时选择的面域传递给他.

在下是一新手,恳请各位高人多多指教,谢谢!

发表于 2006-6-6 16:28:00 | 显示全部楼层
使用doslib就可以
 楼主| 发表于 2006-6-6 17:52:00 | 显示全部楼层
2楼的高人能否详细说一下,不胜感激!
发表于 2006-6-7 07:51:00 | 显示全部楼层
;;BY LUCAS
(defun C:TT (/ ENT LST)
  (prompt "\n选取面域: ")
  (if (setq ENT (ssget "+.:E:S" '((0 . "REGION"))))
    (progn
      (setq LST (GETINERTIA (ssname ENT 0)))
      (command "_.POINT" (car LST))
      (alert (strcat "惯性矩=" (rtos (cadr LST) 2 3)))
    )
  )
)
;;(GETINERTIA ENAME)
;;传回值<形心座标> 惯性矩)
;;
(defun GETINERTIA (ENT / LST)
  (vl-load-com)
  (command
    "_.UCS"
    "O"
    (setq LST (vlax-get
  (setq ENT (vlax-ename->vla-object ENT))
  'CENTROID
       )
    )
  )
  (setq LST (list LST (vlax-get ENT 'PRODUCTOFINERTIA)))
  (command "_.UCS" "P")
  LST
)
 楼主| 发表于 2006-6-7 19:32:00 | 显示全部楼层

多谢龙龙仔超级版主,运行了一次,不过我所要的是Moments of inertia的x,y两个值如图所示,我试了一下改代码,但是本人功力太差不成功,到现在连代码都没看懂,真是要好好向各位大侠学习。恳请龙大侠在帮帮忙!感激不尽!另外程序可否在命令行里显示,因为这两个值作结构计算时要复制,弹出的消息框没办法复制,再次感谢龙大侠的帮忙,祝愿明经论坛越办越好!我会永远的支持

 

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2006-6-8 07:51:00 | 显示全部楼层
把'PRODUCTOFINERTIA =====&gt; 'PrincipalMoments
发表于 2006-6-8 07:58:00 | 显示全部楼层

entity

The entity name of a 3-D solid object.

Returns

A list of strings describing the file's details if successful. The information returned is as follows:

volume

The volume of the solid.

centroid

A list containing the centroid of the solid.

momInertia

A list containing the X, Y, and Z moments of inertia of the solid.

prodInertia

A list containing the X, Y, and Z products of inertia of the solid.

prinMoments  

A list containing the X, Y, and Z principal moments of the solid.

prinAxes

A list containing the X, Y, and Z principal axes of the solid.

radiiGyration

A list containing the X, Y, and Z radii of gyration of the solid.

extents

A list containing the extents (bounding box) of the solid.

nil if not successful or on error.

Example

Command: (dos_massprops (car (entsel "\nSelect a solid:")))

(29.7069 (8.38222 3.97879 2.0) (640.888 2273.47 2597.49) (990.758 236.395 498.02) (51.7765 67.3905 39.9486) ((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0)) (4.64475 8.74815 9.35079) ((6.70725 2.87031 0.0) (10.0572 5.08728 4.0)))

下载一个doslib程序

进入CAD,加载doslib,

(setq masp (dos_massprops e))

在变量masp中就是三维实体或面域的各项数据

以下是doslib的说明

(dos_massprops entity)

Parameters

发表于 2006-6-8 15:26:00 | 显示全部楼层

回复

使用doslib的(dos_massprops e)可以得到实体e的各项数据。
 楼主| 发表于 2006-6-9 14:26:00 | 显示全部楼层

问题解决,现把我参考龙龙仔版主的代码后编的东西贴出来,一共2个小工具,分别是:查询面域的惯性矩"am",查询对象的面积和重量(铝型材)"aw",初次编程,请多包涵!再次感谢各位高手指教!回头再把doslib研究一下!

 

;;BY fszs
(defun C:aw ()
 (prompt "\nPLease Select The Object: ")
 (setq ENT (ssget c))
 (setq ent (ssname ent 0))
 (setq ent (vlax-ename->vla-object ent))
 (setq area (vlax-get ent 'area))
 (setq wei (* area 0.0027))
 (setq wei1 (rtos wei 2 3))
 (princ "Area=")
 (princ area)
 (princ " mm^2")
 (princ )
 (princ "  Weight=")
 (princ wei1)
 (princ " kg/m" )
 (princ )
)


;;BY fszs
(defun C:am ()
 (prompt "\nPlease Select The Region: ")
 (setq ENT (ssget c))
 (setq ent (ssname ent 0))
 (setq ent (vlax-ename->vla-object ent))
 (command "_.ucs" "O" (vlax-get ent  'CENTROID))
 (setq lst (vlax-get ENT 'momentofinertia))
 (setq mx (/ (nth 0 lst) 10000))
 (setq my (/ (nth 1 lst) 10000))
 (command "_.ucs" "p")
 (princ "Moments of inertia(X Y):")
 (princ mx)
 (princ " cm^4   ")
 (princ my)
 (princ " cm^4")
 (princ )
)


 

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-28 13:01 , Processed in 0.250267 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表