Performance issue Changing Color

Discussion in 'AutoCAD' started by Kblasdel, Feb 7, 2005.

  1. Kblasdel

    Kblasdel Guest

    I am re-writing a program that we use to convert DXF files we get from a client to our standards. This application was originally written for AutoCAD 14, but I have (with some help) re-written it in VB as a stand alone application for 2004. Everything work good accept on part. The intent was to hide AutoCAD and show only a progress bar as the application did it's thing. Loaded some linetypes, converted some of their standard layer names to our using our line types etc. The step I am having problems with is setting all entities color to 'ByLayer'.

    The original simply used a command line method of selecting all objects in the drawing, then doing a 'change' , 'color', 'bylayer' That I ended up porting over like this...

    Dim commandsend As String
    commandsend = "Change" & vbCr & "all" & vbCr & vbCr & "p" & vbCr & "color" & vbCr & "Bylayer" & vbCr & vbCr
    acad.ActiveDocument.SendCommand (commandsend)
    acad.Visible = False

    The issue with this method in the new application is that when sending a line to the command interpreter of AutoCAD it makes AutoCAD visible for some reason (why I had the 'acad.Visible = false' at the end to hide it again). But it's very quick. So you see a flash of AutoCAD as it does this step then its gone.

    So in order to get around that I tried to bypass the command line with this... (Variable definitions not included)

    i = 0
    If sSet.Count > 0 Then
    For Each oEnt In sSet
    oEnt.Color = acByLayer
    i = i + 1
    Form1.Label4.Caption = "Processing: " & i & " of " & sSet.Count
    Form1.Label4.Refresh
    Next
    End If

    This works, but the issue is the process to change color this way takes a very long time in relation to the other.

    Does anyone know a method of changing the color of all objects in a drawing other then using these two ways, or perhaps a flaw in my logic above that would solve my issue. Either making the first example, not show AutoCAD or the 2nd not take 1-2 minutes a drawing (some have 20k entities in them, taking time to loop through).
     
    Kblasdel, Feb 7, 2005
    #1
  2. Comment these lines out and just change the caption once to something
    like "Processing...". Form repaints are not exactly economical.
     
    Frank Oquendo, Feb 7, 2005
    #2
  3. Your problem has nothing to do with form updates.

    You are running an interprocess COM client. Cross-
    process COM calls can take anywhere from 10-50X
    longer than the equivalent from an in-process client
    (e.g., loaded as a DLL in AutoCAD's process space).

    To resolve this, you can do several things. One is
    to build your entire application as an ActiveX DLL
    that can be loaded by AutoCAD into its own process
    space. Or, you can seperate the AutoCAD-intensive
    portions of your application, and make them ActiveX
    components housed in a DLL, that are loaded by the
    main application, or you can go back to the sloppy
    method of driving AutoCAD via the command line.
     
    Tony Tanzillo, Feb 7, 2005
    #3
  4. If you really like the dynamic caption, idea, use this to make it run
    faster....

    i = i + 1
    ' update label only every 100 iterations ... change # to suit your
    taste
    if i mod 100 = 0 then Form1.Label4.Caption = "Processing: " & i &
    " of " & sSet.Count

    James
     
    James Belshan, Feb 8, 2005
    #4
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.