Hi All,
I should probably know this by now but I am still a little bituncertain.
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 onsolidworks.
Does that need to be done only once in the whole macro and then atthe very end of the macro set it to nothing ?
Example #2 Say I am in a function and i have the handle on theactive part now i call another function should I:
A. declare the part again and set it again in the function that iam calling or does it still know which part i am refering to.
B. pass the handle to the function i am calling then once thefunction is complete it will be passed back to the function it wascalled from.
I hope this is not too confusing. I am just a little bit undecidedas to how often I need to declare objects.
Any help is great. ThanksSolidworksApi macros
I should probably know this by now but I am still a little bituncertain.
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 onsolidworks.
Does that need to be done only once in the whole macro and then atthe very end of the macro set it to nothing ?
Example #2 Say I am in a function and i have the handle on theactive part now i call another function should I:
A. declare the part again and set it again in the function that iam calling or does it still know which part i am refering to.
B. pass the handle to the function i am calling then once thefunction is complete it will be passed back to the function it wascalled from.
I hope this is not too confusing. I am just a little bit undecidedas to how often I need to declare objects.
Any help is great. ThanksSolidworksApi macros

It all depends where you declare your objects.
If you declare them globally in your module or class then you onlyhave to set them once (unless for example if you have your modeldocand change the active document then you will have to re-capture thenew modeldoc).
So for example #1
Doing it once is sufficient
Example #2: If your functions are in the same module/class and thepart is declared globally thwn once should be sufficient.
Hope this helped,
Cheers,
--Stav.
Thanks. That makes sence to declare something globally and have itwork for all the functions, what about setting the part ?
I have a module in which i have 2 functions in the first function Iam setting swApp and swPart then in that function i am calling thesecond function that is in the same module as the one that i amcalling it from and in there I am setting swFeature but I get anerror unless i set swPart again. But i did not need to set swAppagain.
Can you explain to me a little why I have to reset it or why Idon't need to reset it ?
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 thewhole macro and then you can re-use it.
Let me know if it works.
--Stav.