几何尺寸与公差论坛

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

【转帖】declaring objects and setting objects

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

本版积分规则

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

GMT+8, 2024-12-23 04:30 , Processed in 0.035555 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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