几何尺寸与公差论坛

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

【转帖】not able to get active document using api in case of assemblies

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

本版积分规则

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

GMT+8, 2024-12-23 14:19 , Processed in 0.034177 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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