|
declaring objects and setting objects
hi all,
i should probably know this by now but i am still a little bit uncertain.
when to set and declare objects.
example #1 dim swapp as sldworks.sldworks is used to declare swapp, and at the begining of your macro you set it to "createobject("sldworks.application")" to get the handle on solidworks.
does that need to be done only once in the whole macro and then at the very end of the macro set it to nothing ?
example #2 say i am in a function and i have the handle on the active part now i call another function should i:
a. declare the part again and set it again in the function that i am calling or does it still know which part i am refering to.
b. pass the handle to the function i am calling then once the function is complete it will be passed back to the function it was called from.
i hope this is not too confusing. i am just a little bit undecided as to how often i need to declare objects.
any help is great. thanks
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
hi ben,
it all depends where you declare your objects.
if you declare them globally in your module or class then you only have to set them once (unless for example if you have your modeldoc and change the active document then you will have to re-capture the new modeldoc).
so for example #1
doing it once is sufficient
example #2: if your functions are in the same module/class and the part is declared globally thwn once should be sufficient.
hope this helped,
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 stavros,
thanks. that makes sence to declare something globally and have it work for all the functions, what about setting the part ?
i have a module in which i have 2 functions in the first function i am setting swapp and swpart then in that function i am calling the second function that is in the same module as the one that i am calling it from and in there i am setting swfeature but i get an error unless i set swpart again. but i did not need to set swapp again.
can you explain to me a little why i have to reset it or why i don't need to reset it ?
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
hi ben,
try making your subroutines or functions public
i.e
public sub mysub()
end sub
by doing so what you set within the sub will be visible for the whole macro and then you can re-use it.
let me know if it works.
--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
yes that works good, thank you.
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
quick |
|