|
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. |
|