|
not able to get "active document" using api in case of assemblies
hi
i have made an application in vc++. in this application you can choose a part or assembly in a browse dialog and then it will launch solidworks(using shellexecute) with the part or assembly chosen.
then i get an instance pointer of solidworks using "cocreateinstance".
then i get the active document using "get_iactivedoc2".
now here is where the issue comes in case i loaded an assembly.
if it is a part then i am able to get the active document pointer instantly. but incase it was a large assembly that requires time loading all the parts that comprise it; then i get a null in the active document pointer.
on the other hand if i introduce some "delay" using sleep, it gives solidworks enough time to load the assembly; and then i can get the active document using get_iactivedoc2.
this is fixed only because i entered some delay. is there any cleaner or more efficient way to get the active document from solidworks only when it is fully loaded and not before? or is there any event by which i can know that the active document is fully loaded in solidworks? or that solidworks is ready for using the api on it to get information ?
hi,
i am not a vc++ programmer but you might want to look this up in api help:
fileopennotify2 - sldworks event
(specifically as it pertains to c++)
~t
no no no... do not use shellexecute that will create an out-of-thread worker. you want to do it through com. by calling cocreateinstance to get a handle to a sldworks object your code should be synchronous and wait for the solidworks to fully initialise before returning execution to your code. so after that line you can then call the sldworks variables opendoc function to open the required document, and then use activedoc to get the active document. doing it in-thread and through com eliminates any issues of returning before completion and the likes. |
|