几何尺寸与公差论坛

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

【转帖】declare sw doc

[复制链接]
发表于 2009-4-13 10:12:39 | 显示全部楼层 |阅读模式
declare sw doc
when working with a solidworks drawing, should i delare
dim swmodel as as sldworks.modeldoc2
dim swdrawing as sldworks.drawingdoc
and
set swmodel = swapp.activedoc
set swdrawing= swmodel
or
dim swdrawing as sldworks.drawingdoc
and
set swdrawing = swapp.activedoc
the second one seems to be simple, however, i got errors sometimes
could anyone please explain this to me
thx, chris
solidworks 2007 (office pro.) sp5.0
testing solidworks 2009 (pro) sp0.0
dell precision t3400
2 cpu (8500) 3.16 ghz, 3.25 gb of ram
window xp pro sp2
nvidia fx 570 6.14.11.6262
i always do the first as sometimes you may want to have access to the modeldoc2 object directly and it doesn't take much to do it that way. also if you want to test to make sure a drawing is the active doc you can use the modeldoc2:gettype method before you cast the modeldoc2 into a drawingdoc.
if swmodel.gettype = swconst.swdocumenttypes_e.swdocdrawing then
set swdrawing = swmodel
else...
depends on what functions you need. i usually start w/ modeldoc and then set specfic doc type as needed.
all that is happening here is vba does an explicit conversion behind the scenes from a modeldoc2 to a drawingdoc.
the only error you would get it both cases is if the active doc is not a drawing, and you should check for this in your code before hand anyway.
the above steps are not even technically required for vba, you could do this for example:
dim swmodel as as sldworks.modeldoc2
set swmodel = swapp.activedoc
swmodel.currentsheet()
calling a drawing function from a modeldoc2 object. all vba would do is look at all possible conversions and attempt to find the function. the only drawback here apart from bad coding practise is that you will not get the intellisense options.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-24 09:51 , Processed in 0.036770 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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