sleep a Macro

Discussion in 'AutoCAD' started by Eduardo Chávez Vallín, Mar 22, 2005.

  1. Hello all

    I'm doing a macro. This Macro must generate a DWF of all files on directory
    given.

    This Macro works good but I need to wait that the DWF is generated to close
    file.

    Is there a Command that sleep until the file is generated??

    I did it

    do until (files.dwf)
    Loop

    But Autocad get blocked

    I need something like it

    do until (files.dwf)
    sleep (10 seconds)
    loop

    thanks
     
    Eduardo Chávez Vallín, Mar 22, 2005
    #1
  2. Hi,

    You can set the time to a variable and loop till the current time minus the
    variable is a suitable value.

    You could also do a file size on the output file and not exit the loop till
    the file size was stable.

    These may be kludgy, but should work.

    Or alternatively you could attempt to do it without "Sendcommand" so the
    code runs synchronously.


    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Mar 23, 2005
    #2
  3. What kind of DWF are you producing? There is no need for a sleep command.,
    just follow the paths below:

    If it s a single page, then PLOT the dwf and there is no need to wait.

    If it is a multi-page and you are using sendcommand with Publish, set a
    variable equal to the number of pages the dwf will have. Then have a global
    counter that is incremented on every End_Plot event. Keep checking for the
    two variables to be equal.

    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 23, 2005
    #3
  4. Eduardo Chávez Vallín

    Matt W Guest

    KLUDGY. Now there's a word I haven't seen in quite some time.
     
    Matt W, Mar 23, 2005
    #4
  5. Hi MIke

    I am producing a single page. these are steps I'm doing:

    1. The user give a path where there are X drawings.
    2. I Open drawing and I send to Plot DWF.
    3. Close Drawing and repeat step 2 until last drawing
    3. I get only the first file DWF, the others were not generated
    4. I tried to sleep before to plot next drawing until the dwf exist and it's
    working but Autocad seems blocked.

    Can you help me?

    this is the code

    For I = 1 To lstArchivo.ListCount
    lstArchivo.ListIndex = I - 1
    Set oDocAct = Application.Documents.Open(txtFolder.Value & "\" &
    lstArchivo.Value, True)
    cUltimo = txtFolder.Value & "\" & Left(lstArchivo.Value,
    Len(lstArchivo.Value) - 4) & "-model.DWF"
    oDocAct.Activate
    nListo = 1
    Do While nListo
    ExportaDWF.GlobalDWF 'Procedure that generate a DWF
    nVeces = 0
    Do While nVeces < 5
    Start = Timer
    Do While Timer < Start + 3
    Loop
    If oSistema.FileExists(cUltimo) Then
    nListo = 0
    Else
    pgrBar.Value = 1 / lstArchivo.ListCount
    Me.Repaint
    pgrBar.Refresh
    End If
    nVeces = nVeces + 1
    Loop
    Loop
    End If
    oDocAct.Close False
    Next I

    Thanks for your time
     
    Eduardo Chávez Vallín, Mar 23, 2005
    #5
  6. A loop that contains nothing but a call to sleep()
    is going block AutoCAD until the looping condition
    has been met.

    The other suggestions you've gotten do not
    address that issue.

    To allow AutoCAD to continue processing windows
    notifications and not appear to be 'blocked', you
    can try placing a call to DoEvents() in your loop:

    do until (files.dwf)
    sleep(1 second)
    DoEvents()
    loop
     
    Tony Tanzillo, Mar 23, 2005
    #6
  7. Hi Eduardo,

    Can you post your function ExportaDWF.GlobalDWF?

    Without seeing it, there are two possible problems. First is you are
    reusing the same dwf name which would cause a problem. Second is when you
    plot, you aren't specifying the correct plot command:

    ThisDrawing.Plot.PlotToFile "d:\myfile.dwf", "DWF ePlot.pc3"


    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 23, 2005
    #7
  8. Mike:

    this is my code, but I changed the line:
    .Plot.PlotToDevice "DWF6 ePlot.pc3" 'Manda la
    ventana al archivo
    by:
    .plot.plotofile cfilename,"DWF6 ePlot.pc3"

    and it's generated only the first file.


    With ThisDrawing
    If .ActiveSpace = acPaperSpace Then
    .MSpace = True
    .ActiveSpace = acModelSpace
    End If

    .ActiveLayout.ConfigName = "DWF6 ePlot.pc3"
    .ActiveLayout.PlotType = acWindow 'Plotear una
    ventana
    .ActiveLayout.SetWindowToPlot aInicio, aFin 'Plotea la
    Ventana
    .ActiveLayout.StandardScale = acScaleToFit 'Encaja en la
    Hoja
    .ActiveLayout.StyleSheet = "Monochrome.ctb" 'Plumillas de
    DWF
    .ActiveLayout.CanonicalMediaName =
    "ANSI_expand_B_11.00_x_17.00_Inches)"
    .ActiveLayout.PlotRotation = ac90degrees 'Gira a 90
    Grados
    .ActiveLayout.CenterPlot = True
    .Plot.PlotToDevice "DWF6 ePlot.pc3" 'Manda la
    ventana al archivo

    End With
     
    Eduardo Chávez Vallín, Mar 23, 2005
    #8
  9. Try putting all of this code within your calling procedure and don't loop.
    out. Also make sure you have Option Explicit called out and don't have any
    errant error handlers in place [ie - On Error Resume Next]. Then see what
    happens.

    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 23, 2005
    #9
  10. The other suggestions you've gotten do not
    Hmmmm???? I am saying there is no need for sleep, just a while loop to
    compare 2 variables which works fine as I use it quite frequently.

    Am I missing something, Tony? Or are you saing that sleep is a better
    solution [if implemented appropriately]?

    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 23, 2005
    #10
  11. Doing this without yielding processor time to AutoCAD
    to process windows notifications will cause it to appear
    to be 'locked up'.
     
    Tony Tanzillo, Mar 24, 2005
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.