几何尺寸与公差论坛

 找回密码
 注册
查看: 914|回复: 0

【转帖】components - get mass property

[复制链接]
发表于 2009-4-13 09:49:04 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-24 09:26 , Processed in 0.036925 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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