几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 09:49 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】components - get mass property

components - get mass property
help me!!! in visual basic, how can get mass property about selected components , in a assembly file?
thanks
jacopo
here is the code..
sub main()
application.sldworks.activedoc.toolsmassprops
end sub
make a new macro and put these codes. select your part and run this macro.
p.s: source of macro code
by handleman
thanks for your aswer,
but i need to have mass property like variant or number, as per "get mass property".
i don't' need to view the windows toll mass.
i must to get the mass value as number so i can use that value.
have you same other idea please?
thanks in advance
jacopo
hello jacopo,
have a look in the solidworks api help for:
modeldocextension:: createmassproperty
there are examples of macros there that do exactly what you want.
cheers,
--stav.
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
hi stav!
thanks for your counsel, but i already try that way,
but the macro get -run time error- in this row:
" vbodyarr = swcomp.getbodies2(swsolidbody): debug.assert not isempty(vbodyarr)"
so...i can't' find another way!
are you able to run that code?
(get mass properties of multibody assembly component example)
---------------
p.s. your picture...do you make diving?
i make apnea in sardinia , corse and red sea, because i live in milan
have a nice day!
jacopo
hi iacopo,
i have written a small macro that will extract the mass properties of the selected component (or multibodied component) in an assembly.
have a look below and change it to work as required.
dim swapp as sldworks.sldworks
dim modeldoc as sldworks.modeldoc2
dim selmgr as sldworks.selectionmgr
dim comp as sldworks.component2
dim massprop as sldworks.massproperty
dim bodiesv as variant
dim boolstatus as boolean
dim mass as double, volume as double
sub main()
set swapp = application.sldworks
set modeldoc = swapp.activedoc
set selmgr = modeldoc.selectionmanager
if selmgr.getselectedobjectcount2(0) <> 1 then
exit sub
end if
set comp = selmgr.getselectedobjectscomponent3(1, 0)
bodiesv = comp.getbodies2(swbodytype_e.swallbodies)
set massprop = modeldoc.extension.createmassproperty
boolstatus = massprop.addbodies(bodiesv)
massprop.usesystemunits = false
mass = massprop.mass
volume = massprop.volume
end sub
cheers,
--stav.
p.s yes i do both scuba diving and apnea. mainly in cyprus .
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
hi stav!
thanks for your assistance!
the code you suggest me is similar to
"get mass properties using massproperty object example (vb)"
i already try to use it. if the component is a part the macro is ok.
but if the component, like mt project, is an assembly,
the row "bodiesv = comp.getbodies2(swbodytype_e.swallbodies) " failed
because -getbodies2- or - getbody- function accept only part component ,
don't accept assemblly component.
that is also written in api help
"remarks
this method returns a valid body2 object only for fully resolved components that reference a partdoc. for the root component, lightweight components or components that reference an assemblydoc, this method returns a null body object. however, if a component is in a multibody part, then this method returns the first body."
have you some other idea?
thanks
p.s. attacched please find ...photo of dugongo ...beautiful mammal live in red sea.
nice day!
ja
hello iacopo,
how about this:
when you make a selection check to see if its a part or assembly( sub-assembly).
if its a part you use what you already have to get the mass properties.
if its an assembly try doing the following:
use the
assemblydoc::getcomponents
this will return a variant array of components pointers.
then for each component in the variant array use component2::getbodies to get the bodies and calculate the mass properties that you want.
hope this helps.
--stav.
nice picture by the way. i have only seen one of those on tv...
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
ok! i'll try this way!
really thanks !
p.s. another images about another beautiful resident of red sea, named "eagle of sea"
good jobs!
click for full image
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】pipe length property yang686526 SolidWorks二次开发 0 2009-04-12 10:03 PM
【转帖】linked sketch text now possible1 9sort of0 yang686526 SolidWorks二次开发 0 2009-04-12 09:34 PM
【转帖】how do i overwrite an existing custom property value yang686526 SolidWorks二次开发 0 2009-04-12 09:10 PM
【转帖】mass properties breakdown for assy yang686526 SolidWorks二次开发 0 2009-04-12 06:58 PM


所有的时间均为北京时间。 现在的时间是 06:08 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多