VBA batch process

Discussion in 'AutoCAD' started by Tim Barbour, May 18, 2004.

  1. Tim Barbour

    Tim Barbour Guest

    I am fairly new to AutoCAD VBA and learning as I go. I need to create thousands of small 3d meshes. I use an AutoCAD macro to run 3dmesh commands to create meshes, one at a time or in a large group.

    I may have gotten into the details and missed some of the introduction, but I have a simple question.

    Can I create more than one drawing (ThisDrawing plus others) in any single AutoCAD VBA project? If so, how?

    Can I repeatedly create new drawings (repeat open, modify, and close), using a batch process, from a single VBA project?

    Basically the VBA sub would - open a new drawing, run a script file to create a mesh, and then close the drawing file (or leave open until all meshes have been created) - in a loop. Pointers to example code?

    Thanks for your feedback on this.

    Tim Barbour
     
    Tim Barbour, May 18, 2004
    #1
  2. Tim Barbour

    Ben Rand Guest

    Hi Tim,

    You can definitely run batch processes via VBA, but there are some things
    you have to be careful with.

    1) You can definitely create and process more than one drawing. Here's a
    simple loop example to get you started:

    Public Sub TestBatchProcess()
    Dim oDwg As AcadDocument
    Dim I As Integer

    For I = 0 To 3
    On Error Resume Next
    'Check to see if the drawing is already open
    Set oDwg = Application.Documents.Open("C:\Temp\Drawing " & I & ".dwg")
    'If not, then create it
    If oDwg Is Nothing Then
    Set oDwg = Application.Documents.Add("Drawing " & I)
    End If
    With oDwg
    '---------------------------------
    '...do some batch processing here
    'Use oDwg in place of ThisDrawing
    '---------------------------------
    'Close the drawing and save (full file name only required if you're
    creating/saving for the first time
    'if the drawing already existed, you could just use
    '.Close True
    .Close True, "C:\Temp\Drawing " & I & ".dwg"
    End With
    Next I

    Set oDwg = Nothing
    End Sub

    2) Probably not a good idea to leave drawings open after you finish
    processing...what if your batch involves dozens or hundreds of drawings?
    Eventually you'll consume all memory and Autocad will crash.

    3) Running a script or Autolisp program from VBA is problematic, at best.
    The problem is that you have to use a SendCommand which runs asynchronously
    from VBA--this means that while the script may start, VBA doesn't wait for
    it to finish before going to the next instruction. You'll have to
    experiment, but my guess is that your script may need to be rewritten as a
    VBA app.


    thousands of small 3d meshes. I use an AutoCAD macro to run 3dmesh commands
    to create meshes, one at a time or in a large group.
    AutoCAD VBA project? If so, how?
    using a batch process, from a single VBA project?
    create a mesh, and then close the drawing file (or leave open until all
    meshes have been created) - in a loop. Pointers to example code?
     
    Ben Rand, May 19, 2004
    #2
  3. Tim Barbour

    Tim Barbour Guest

    Hi Ben,

    I'm justing getting around to this batch process. I used your code and modified to meet my needs. I have a SendCommand to run AutoCAD script files (3dmesh script) within the batch loop creating new files. Works just fine.

    Thanks again for your help.

    Tim Barbour
     
    Tim Barbour, Jun 14, 2004
    #3
  4. Tim Barbour

    Tim Barbour Guest

    Hi Ben,

    In putting the finishing touches on the referenced VBA batch process (batch file creation with internal script process).

    Is there a way to reference a template (.dwt) file to be used as the starting point for the batch code you provided previously.

    When I run the batch process, I'm getting a warning the "Template Drawing file is not on file. Using default Regeneration Model"

    My code (your code with my modification on the specifics on the batch processing) runs fine. I get the right results. But, I'm getting this warning during the code run. The warning doesn't effect the results, so I'm OK there. Just wondering about a template specification in the code.

    Thanks again for your excellent advise.

    Tim Barbour
     
    Tim Barbour, Jun 14, 2004
    #4
  5. Tim Barbour

    Ben Rand Guest

    Tim, glad the code was helpful. Documents.Add should accept the full path to
    a template file. Example:

    Set oDwg = Application.Documents.Add("c:\path\mytemplate.dwt")

    Ben

    (batch file creation with internal script process).
    starting point for the batch code you provided previously.
    file is not on file. Using default Regeneration Model"
    processing) runs fine. I get the right results. But, I'm getting this
    warning during the code run. The warning doesn't effect the results, so I'm
    OK there. Just wondering about a template specification in the code.
     
    Ben Rand, Jun 15, 2004
    #5
  6. Tim Barbour

    Tim Barbour Guest

    Ben,

    Thanks again for the help.

    Do you know anything-anyone who knows Discreet MaxScript? I need to do a similar batch file creation routine in 3ds Max - importing DWG files and exporting MAX files.

    Tim Barbour
     
    Tim Barbour, Jun 15, 2004
    #6
  7. This site had quite a few batch import / export scripts:

    http://www.scriptspot.com

    I cobbled one together for my own use... it's VRML files in and DWG files
    out... you can have it if you can't find anything better on the website...
    just e-mail me separately.

    Good luck,

    James
     
    James Belshan, Jun 15, 2004
    #7
  8. Tim Barbour

    Ben Rand Guest

    Flirted with it when I taught Max, but that was back on Max 3-4. There is a
    book, called "Mastering Maxscript and the SDK for 3D Studio Max," by
    Alexander Bicalho and Simon Feltman. The version I have is (c) 2000, but if
    you're planning to do much, it might be worth looking at, even if it is
    dated. I used to participate in a Maxscript newsgroup, and Alex was a heavy
    contributor and eager to help. Maybe check Discreet's web site...

    Ben

    similar batch file creation routine in 3ds Max - importing DWG files and
    exporting MAX files.
     
    Ben Rand, Jun 15, 2004
    #8
  9. Tim Barbour

    Tim Barbour Guest

    Ben,

    I have the book you referenced. I think I can get what I need for the book. I've had it for a while, but I'm just now getting around to looking at it. There is only the one 2000 version.

    I've also posted the MaxScript batch question on a Discreet forum.

    Thanks again for your help.

    Tim Barbour
     
    Tim Barbour, Jun 16, 2004
    #9
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.