Running into trouble when converting vba code Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Running into trouble when converting vba code

07 May 2021, 10:33

I am converting this vba code to run in ahk.

Code: Select all

Set swApp = Application.SldWorks
'Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Set pg = swModel.Extension.GetPackAndGo
So far I've been able to convert most of my macros over to ahk, but this one is giving me trouble. It seems that the line "Set pg = swModel.Extension.GetPackAndGo" fails unless swModel is defined ahead of time by "Dim swModel As SldWorks.ModelDoc2". This is the first time I've ran across this in their api, usually you can skip the definition but in this case it seems like it is required. Am I SOL or is there a way to initialize as that type in autohotkey?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Running into trouble when converting vba code  Topic is solved

08 May 2021, 09:47

u dont have to declare types in ahk. ur problem is caused due to something else
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: Running into trouble when converting vba code

07 Sep 2021, 15:44

For anyone else interested in this, I found that you have to pass comvar element to this function. It is not documented this way, and the returned object is empty. But it does not crash ahk now. Probably need to pass it a specific object...

Code: Select all

swModel := swApp.activeDoc
pgOut := comVar(varType:=9)
swPackAndGo := swModel.Extension.GetPackAndGo(pgOut.ref) ;seems to run correctly with long delay but return value is empty
swPackAndGo.GetDocumentNamesCount ;empty
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: Running into trouble when converting vba code

15 Jul 2022, 00:42

Solidworks support told me that some of their functions don't work when using late binding. This read helped me understand better https://nolongerset.com/early-binding-vs-late-binding/. I bet their object does not have the IDispatch, causing it to fail. I guess this function is unusable until they update their code?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Running into trouble when converting vba code

15 Jul 2022, 04:18

no, the function is usable. u just have to find a way to call it. if they didnt bother implementing IDispatch, then ud have to call it by the method's address/position in the object's vtable(ie use ComCall if ure using v2, or check out this example if u arent https://www.autohotkey.com/docs/commands/ComObjQuery.htm#ExClassName). of course, to do that ud have to know the internal structure of the object ure working with(IModelDocExtension or IPackAndGo, depending on which call u figured out was erroring out) and to know that, ud need to have either:
  • some .header files
  • a .tbl of the object
  • or figure the object's layout by trial & error, gl doing that

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CrowexBR and 276 guests