Pause / wait for a sub before execute

Pause / wait for a sub before execute

joh.richard
Enthusiast Enthusiast
472 Views
1 Reply
Message 1 of 2

Pause / wait for a sub before execute

joh.richard
Enthusiast
Enthusiast

Hi,

I am experiencing an issue with the execution of a vba . This vba is executed each time a drawing is opended.

FileName = ThisDrawing.FullName
    If UCase(FileName) = UCase("C:\Users\xxx\123.dwg") Then
        WaitForAutoCAD
        dsdfile = "C:\Users\xxx\123.dsd"
        Call PrintFromDSD(dsdfile) 'in this sub a send command publish is made


It seem that the "PrintFromDSD(dsdfile)" is execute before the drawing is fully open. 
The subroutine works perfectly when I start it manually.

I added a "wait" ,  with message box to  see if where is the problem,

Sub WaitForAutoCAD()
    Dim State As AcadState
    Dim EndTime As Double
    Dim Seconde As Double
    
    Set State = GetAcadState
    Seconde = 60 'le nombre de seconde de l'attente
    EndTime = Timer + Seconde

    If State.IsQuiescent Then
        MsgBox "AutoCAD is fully open"
    Else
        MsgBox "AutoCAD is not ready."
        Do While Timer < EndTime
            DoEvents 'permet à autocad de contimuer de répondre
        Loop
                'test pour valider qu'il a compte
                If State.IsQuiescent Then
                MsgBox "AutoCAD is fully after timer"
            Else
                MsgBox "AutoCAD is not ready. did not work :(."
            End If
    End If
End Sub

 

But I still receive the MsgBox: "AutoCAD is not ready. did not work :(."

 

Any  suggestion

Thanks

0 Likes
473 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

You would always get "AutoCAD is not ready..." because your code is running!

 

Since you did not show the code in PrintFromDSD(), did you set "BackgroundPlot" system variable to 0? if not, you should do it.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes