Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Closing DocumentProjects in VB(A)

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
200 Views, 4 Replies

Closing DocumentProjects in VB(A)

To all VB(A) guru's,

I am having trouble with my code, and I could really use some help!

How can I close the DocumentProjects of parts/sub-assemblies, after they
have been deleted from an Assembly? I can only get this to work by closing
and re-open the entire Assembly, and than it still needs a MsgBox to get it
all working!

Can anyone please take a look at the code (see IVCF)?
Just open the "Opstart.ipt" and run the "Start" macro.

Try to get this code to work WITHOUT the MsgBox (and be able to run it as
often as you like)

Thanks,

Teun
4 REPLIES 4
Message 2 of 5
avbuiten
in reply to: Anonymous

As stated before use DOEVENTS. The following code fragment solved you're problem on my system.

Dim docs As Documents
Set docs = ThisApplication.Documents
Call OpenDeleteAllSaveClose(AssemblyName)
Debug.Print docs.Count
DoEvents
'MsgBox "Click OK to continue(" & docs.Count, vbInformation 'Why do I need this freaking MsgBox???
'Sleep 1000

Anton
Message 3 of 5
Anonymous
in reply to: Anonymous

Thanks Anton, this little example was what I
needed!

 

I asked this again, because the other thread was
getting old. Also, you replied there that "I
already looked at the "still opened" inventor documents problem, but couldn't
solve it".

 

Thanks again!


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
As
stated before use DOEVENTS. The following code fragment solved you're problem
on my system.

Dim docs As Documents
Set docs = ThisApplication.Documents
Call
OpenDeleteAllSaveClose(AssemblyName)
Debug.Print docs.Count
DoEvents

'MsgBox "Click OK to continue(" & docs.Count, vbInformation 'Why do I
need this freaking MsgBox???
'Sleep 1000

Anton

Message 4 of 5
avbuiten
in reply to: Anonymous

Sorry about that. I thought you was trying the DOEVENTS suggestion, and solved it. This may be not the best but it is a work around. I (or we) do not know exactly why the DOEVENTS statement solve this problem, but i quess it is processing all windows events/queues, and by doing that synchronize (multi threaded) events of Inventor as well.
Anton
Message 5 of 5
Anonymous
in reply to: Anonymous

Exactly 🙂

 

I also don't know what DoEvents really does, but it
did solved my problem 😄

 

From the VBA Help:

 


DoEvents Function


Yields execution so that the operating system can process other
events.


Syntax


DoEvents( )


Remarks


The DoEvents function returns an
href="javascript:hhobj_4.Click()">Integer
representing the number of open
forms in stand-alone versions of Visual Basic, such as Visual Basic,
Professional Edition. DoEvents returns zero in all other
applications.


DoEvents passes control to the operating system. Control is
returned after the operating system has finished processing the events in its
queue and all keys in the SendKeys queue have been sent.


DoEvents is most useful for simple things like allowing a user
to cancel a process after it has started, for example a search for a file. For
long-running processes, yielding the processor is better accomplished by using a
Timer or delegating the task to an ActiveX EXE component.. In the latter case,
the task can continue completely independent of your application, and the
operating system takes case of multitasking and time slicing.


Caution   Any time you temporarily yield the
processor within an event procedure, make sure the
href="javascript:hhobj_5.Click()">procedure
is not executed again from a
different part of your code before the first call returns; this could cause
unpredictable results. In addition, do not use DoEvents if other
applications could possibly interact with your procedure in unforeseen ways
during the time you have yielded control.



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Sorry
about that. I thought you was trying the DOEVENTS suggestion, and solved it.
This may be not the best but it is a work around. I (or we) do not know
exactly why the DOEVENTS statement solve this problem, but i quess it is
processing all windows events/queues, and by doing that synchronize (multi
threaded) events of Inventor as well.
Anton

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report