slow performance with vb6 vs. same code in vba???

Discussion in 'AutoCAD' started by Jason Smith, Feb 16, 2004.

  1. Jason Smith

    Jason Smith Guest

    I am writing a routine that gets a file list from dialog boxes of
    architectural backgrounds that need to be cleaned up and used for our
    engineering drawings. It then loads each file, saves a new copy in a new
    location (specified in the dialogs), runs the clean up process, saves, then
    closes, next file, etc. etc. For some reason this takes an incredible
    amount of time to execute, almost 5 minutes for a basic drawing. If I just
    enter the cleanup portion of the code into vba and run it, it executes in a
    matter of seconds on the same drawing file. Not sure why.

    This is the basic part of the code:

    ..
    ..
    ..
    Set AcadApp = GetObject(, "AutoCAD.Application")
    If Err Then
    Err.Clear
    MsgBox ("AutoCAD is not running. Please exit and start AutoCAD.")
    Else
    Set ThisDrawing = AcadApp.ActiveDocument
    End If

    Dim obj As Object
    Dim lyr As Object
    Dim blk As Object
    Dim piece As Object
    Dim DimSt As Object

    AppActivate AcadApp.Caption

    For Each oFile In CleanFileList

    FileCopy SourceLoc + "\" + oFile, WorkingLoc + "\" + oFile
    AcadApp.Documents.Open (WorkingLoc + "\" + oFile)

    Set ThisDrawing = AcadApp.ActiveDocument

    For Each obj In ThisDrawing.ModelSpace
    obj.Color = acByLayer
    Next obj

    For Each lyr In ThisDrawing.Layers
    lyr.Color = 8
    Next lyr

    For Each blk In ThisDrawing.Blocks
    For Each piece In blk
    piece.Color = acByLayer
    Next piece
    Next blk

    For Each DimSt In ThisDrawing.DimStyles
    ThisDrawing.ActiveDimStyle =
    AcadApplication.ActiveDocument.DimStyles(DimSt.Name)
    ThisDrawing.SetVariable "DIMCLRD", acByLayer
    ThisDrawing.SetVariable "DIMCLRE", acByLayer
    ThisDrawing.SetVariable "DIMCLRT", acByLayer
    Next DimSt
    ThisDrawing.SendCommand ("Dim" & vbCr & "Update" & vbCr & "All" &
    vbCr & vbCr & "Exit" & vbCr)
    ThisDrawing.Save
    ThisDrawing.Close

    Next oFile


    Thanks in advance for any input!!

    Jason Smith
     
    Jason Smith, Feb 16, 2004
    #1
  2. If you do a Google search of this group, using "In Process" as your
    keywords, you will undoubtedly find a trove of data on this subject.

    Basically your performance problem is coming from the fact that you are
    moving data across process boundaries. You can deal with it by
    converting your VB6 Executable to an ActiveX DLL and loading into
    AutoCAD's process space using VBA. There is another method, which I am
    not familiar with, that involves moving only the AutoCAD-centric code
    from your EXE into a DLL. You might find more information about that
    in your Google search.

    Good luck in your endeavor.
     
    Chuck Gabriel, Feb 16, 2004
    #2
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.