VB Performance issues

Discussion in 'AutoCAD' started by Martin Duke, Jun 25, 2003.

  1. Martin Duke

    Martin Duke Guest

    Hello,

    My colleague and I have an application we developed in VBA, having sorted it
    out and tracked down the bugs we then ported it over to VB6 using the VBADEV
    manual for guidance. the application compiles and runs OK except for one
    thing, it is dead slow. If for example in VBA it would run in 30seconds it
    now takes 5 minutes. The application basically sets two
    document/application variables AcadApp and AcadDoc as per the manual and
    uses them like this.

    Set TextObj = AcadDoc.ModelSpace.AddText(TextVal, ptb, tsize)

    All this is as per the manual. Can anyone suggest what could be wrong and
    hopefully suggest a fix for us.

    Thanking you un advance for any help you can offer

    Regards


    Martin Duke
     
    Martin Duke, Jun 25, 2003
    #1
  2. Martin Duke

    Tim Arheit Guest


    Are you using late bound or early bound objects?

    ie.

    ' Late bound: The application must look up the
    ' property/function each time it is called at run time
    ' (slower)
    Dim TextObj as Object

    ' Early bound: the application knows at compile time
    ' what the object is. (= faster)
    Dim TextObj as AcadText


    Even using early bound objects, calls to autocad will typically be
    slower as it is out of process and vb must communicate between process
    boundaries. However, I wouldn't expect it to be that slow unless
    there are lots of repeated calls to autocad objects.

    Tips:

    1. Use early bound instead of late.

    2. Use the With statement when making many calls to the same object,
    especially when you are not referencing the object directly. ie.

    With AcadDoc.ModelSpace
    Loop
    Set TextObj = .AddText(TextVal,ptb,tsize)
    TextObj.Alignment = acAlignmentBottomCenter
    etc...
    End Loop
    End With

    3. Avoid unnecessary calls/references to autocad objects. ie.
    Instead of repeatedly referencing TextObj.TextString, save it to a
    local variable, do the processing, then copy it back..

    ie.
    Dim sTemp As String

    sTemp = TextObj.TextString
    'Processing..(Change references from TextObj.TextString to sTemp)
    TextObj.TextString = sTemp


    4. Determine which parts of your code are causing the most problems
    and focus on optimizing them. If you find a particular routine is
    unexpectedly slow and you can't solve it, the post the specific
    problem area.

    -Tim
     
    Tim Arheit, Jun 26, 2003
    #2
  3. Martin Duke

    Martin Duke Guest

    Tim,

    Thank you for those suggestions. We are definitely using early binding, so
    I think we can eliminate that. The use of the With statement is something
    we will implement, but as for the rest we pretty much work as you suggest.
    I was wondering if there was a way to halt autocad doing anything while the
    App is doing it's work. I think that because the app is running
    independantly it takes too long to pass an instruction to AutoCAD.


    Anyway thank you for all your help

    Kind Regards



    Martin Duke
     
    Martin Duke, Jun 26, 2003
    #3
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.