几何尺寸与公差论坛------致力于产品几何量公差标准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-12, 06:58 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】mass properties breakdown for assy

mass properties breakdown for assy
i am trying to iterate over a largish (216 parts, 37 assy) assy and get information about each part, specifically i need the parts mass, and the parts center of gravity coordinates in the assy. i have experience with vb and sw but not the api until now. i have disected the assembly transversal example and the mass properties example and frankenstiened them together. i think either my ancient vb experience or my lack of sw api experience is getting in the way
having problems addressing my part's model object:
set partmodel = partcomp.getmodeldoc2
set swdocext = partmodel.extension
i am apparently not using the getmodeldoc2 function correctly, i have attached the whole .bas if someone wants to give it a shot
my machine:
sw 2009 64 bit, xp 64, 12 gb ram, nvidia quadro fx 3700
-doug
edited: 11/07/2008 at 02:23 pm by douglas johnson
i'm not using 2009, so i'm not sure if they changed it, but on 2008 the call is 'getmodeldoc'
assemblydoc::getcomponents
component2::getmodeldoc
i have tried it both ways, getmodeldoc and getmodeldoc2 work in parrallel i get the same error either way.
see the following code for a running mass total of assembly components.
dim swapp as sldworks.sldworks
dim swcomps as variant
dim swassy as sldworks.assemblydoc
dim swpart as sldworks.modeldoc2
dim swcompcount as long
dim masstotal(0 to 1) as double
dim swdocext as sldworks.modeldocextension
dim swmass as sldworks.massproperty
dim bret as boolean
sub main()
set swapp = application.sldworks
set swassy = swapp.activedoc
bret = swassy.resolvealllightweightcomponents(false)
swcompcount = swassy.getcomponentcount(false)
swcomps = swassy.getcomponents(false)
masstotal(0) = 0
for i = lbound(swcomps) to ubound(swcomps)
set swpart = swcomps(i).getmodeldoc
if swpart.gettype = swdocpart then
set swdocext = swpart.extension
set swmass = swdocext.createmassproperty
masstotal(1) = masstotal(0) + (swmass.mass * 2.2046226)
debug.print "running mass: " & round(masstotal(0), 2) & " lbs. + " & round(swmass.mass * 2.2046226, 2) & " lbs. = " & round(masstotal(1), 2) & " lbs."
masstotal(0) = masstotal(1)
end if
next
debug.print "total mass: " & round(masstotal(1), 2) & " lbs. "
end sub
edited: 11/10/2008 at 02:32 pm by blake dahle
so i got the model doc thing working using your code but now i am discovering that all of my cg coordinates aren't in the assembly coordinates system but in the individual part coordinate system, is there some way around this?
blake,
i was looking for something exactly like the code you posted..here is my dilema...i do not know how to create a macro using this code!
i thought i could mearly copy this code create a new macro in sw and paste it and try and run it and voila! but no such luck, i get the following error:
run-time error '91':
object variable or with block variable not set
and then when i click the debug button it highlights in yellow:
if swpart.gettype = swdocpart then
below is exactly how i have the macro:
sub main()
set swapp = application.sldworks
dim swcomps as variant
dim swassy as sldworks.assemblydoc
dim swpart as sldworks.modeldoc2
dim swcompcount as long
dim masstotal(0 to 1) as double
dim swdocext as sldworks.modeldocextension
dim swmass as sldworks.massproperty
dim bret as boolean
set swapp = application.sldworks
set swassy = swapp.activedoc
bret = swassy.resolvealllightweightcomponents(false)
swcompcount = swassy.getcomponentcount(false)
swcomps = swassy.getcomponents(false)
masstotal(0) = 0
for i = lbound(swcomps) to ubound(swcomps)
set swpart = swcomps(i).getmodeldoc
if swpart.gettype = swdocpart then
set swdocext = swpart.extension
set swmass = swdocext.createmassproperty
masstotal(1) = masstotal(0) + (swmass.mass * 2.2046226)
debug.print "running mass: " & round(masstotal(0), 2) & " lbs. + " & round(swmass.mass * 2.2046226, 2) & " lbs. = " & round(masstotal(1), 2) & " lbs."
masstotal(0) = masstotal(1)
end if
next
debug.print "total mass: " & round(masstotal(1), 2) & " lbs. "
end sub
am i even on the right track here?
thanks,
rodney peterson
if at first you don't suceed, get a big hammer and smash your computer into bits and pieces.
i'm not sure why you would be getting that error, on that line. can you send me the files you are using and i will look at it? i was unable to re-create that error with that code.
sure, which files are you referring too?
the assembly and all the parts or the macro i created?
thanks
if at first you don't suceed, get a big hammer and smash your computer into bits and pieces.
all the referenced files, assy/parts and macro. also what version are you running?
ok, i have attached a zip file with everything in it and we are using sw2008 sp4.
tanks!
if at first you don't suceed, get a big hammer and smash your computer into bits and pieces.
the assembly contains toolbox items which pull in the api code as component2 objects, but are not converted to modeldoc2 objects. that is what is causing the error. if you change the code to the following it will ignore the toolbox items, and get all the other components.
dim swapp as object
sub main()
set swapp = application.sldworks
dim swcomps as variant
dim swassy as sldworks.assemblydoc
dim swpart as sldworks.modeldoc2
dim swcompcount as long
dim masstotal(0 to 1) as double
dim swdocext as sldworks.modeldocextension
dim swmass as sldworks.massproperty
dim bret as boolean
set swapp = application.sldworks
set swassy = swapp.activedoc
bret = swassy.resolvealllightweightcomponents(false)
swcompcount = swassy.getcomponentcount(false)
swcomps = swassy.getcomponents(false)
masstotal(0) = 0
for i = lbound(swcomps) to ubound(swcomps)
set swpart = swcomps(i).getmodeldoc
if not swpart is nothing then
if swpart.gettype = swdocpart then
set swdocext = swpart.extension
set swmass = swdocext.createmassproperty
masstotal(1) = masstotal(0) + (swmass.mass * 2.2046226)
debug.print "running mass: " & round(masstotal(0), 2) & " lbs. + " & round(swmass.mass * 2.2046226, 2) & " lbs. = " & round(masstotal(1), 2) & " lbs."
masstotal(0) = masstotal(1)
end if
end if
next
debug.print "total mass: " & round(masstotal(1), 2) & " lbs. "
end sub
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】is it possible to edit custom properties with a script outside of sw yang686526 SolidWorks二次开发 0 2009-04-12 06:45 PM
【转帖】how to get weldment cutlist properties document manager api yang686526 SolidWorks二次开发 0 2009-04-12 06:35 PM
【转帖】document manager - add set custom properties yang686526 SolidWorks二次开发 0 2009-04-12 06:00 PM
【转帖】custom properties calls yang686526 SolidWorks二次开发 0 2009-04-12 05:56 PM


所有的时间均为北京时间。 现在的时间是 02:37 AM.


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