GetInterfaceObject Help

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

  1. Jason Smith

    Jason Smith Guest

    Newbie here...

    I had written a routine in vb that enable the user to select a list of files
    to be modified. The program would then cycle through each selected file,
    clean the drawing up for our standards, then save it in a new location. The
    only problem was the speed of the app. My previous posts indicated that it
    had to do with the fact it was a stand alone vb and not running in the
    AutoCAD memory (or whatever). I have been trying to create the exe/dll
    combination that I have found references to in this news group but have hit
    a road block. My scenario is as follows:

    The following are my two vb projects associated with this. The CleanUp.exe
    has a userform that passes a file list to the sub. My problem appears to be
    where I have shown ??? I do not completely understand what these two values
    should be. Again, I am a novice so be gentle!

    CleanUp.exe file is as follows:

    Public Sub CleanUp()

    On Error Resume Next

    Set AcadApp = GetObject(, "AutoCAD.Application")
    If Err Then
    Err.Clear
    Set AcadApp = CreateObject("AutoCAD.Application")
    End If

    Set DwgClean = AcadApp.GetInterfaceObject("CleanUp.Clean") '???

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

    For Each oFile In CleanFileList

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

    Call DwgClean.Clean(AcadApp)


    Next oFile

    End Sub


    The CleanUp.dll file contains:

    Public Sub Clean(App As AcadApplication)

    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)

    End Sub


    I appreciate any help anyone can provide.

    Jason Smith
     
    Jason Smith, Feb 17, 2004
    #1
  2. I remember your last post, Jason. If all you are attempting to do is
    what you list here, the in-process/out-process scenario isn't your
    problem - your problem is your coding approach. NEVER use:

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

    Whether you do in- or out- process, your app is going to crawl if you
    are iterating everythhing in model space. Try thhis approach instead -

    1. Change all the layers
    2. Create a selection set using a filter to find all entities that are
    not BYLAYER colored. Then just change them.
    3. Continue with the dimension stuff

    As to the getinterface, you need to do something like this:

    Dim VB6DLL As Object
    'Connect to the class containing the external function
    Set VB6DLL = ThisDrawing.Application.GetInterfaceObject("MyDLL.MyClass")

    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 17, 2004
    #2
  3. Hey there Mike. While I agree, in principle, with what you are saying,
    Jason did mention in his previous post that the same code in VBA was
    significantly faster than its VB counterpart. That would certainly
    seem to indicate that moving the code into an ActiveX DLL could offer a
    healthy performance boost.
     
    Chuck Gabriel, Feb 17, 2004
    #3
  4. GetInterfaceObject is used to load in-process servers, i.e. dynamic link
    libraries, not executables.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Feb 17, 2004
    #4
  5. Jason Smith

    Jason Smith Guest

    The speed in vba is not bad at all. On a healthy sized floor plan it only
    takes 10 to 20 seconds for each file. In vb it takes almost 5 minutes. I
    will look into the adjustments in the selections and see what it does.

    I am not very literate with how visual basic is structured so I still have
    some questions related to the GetInterfaceObject. Specifically for my code,
    what woulr the MyDLL.MyClass be? CleanUp.Clean? Right now the code only
    opens the drawing files selected and does not execute the sub in the
    CleanUp.dll...

    Thanks again for the help.

    Jason
     
    Jason Smith, Feb 17, 2004
    #5
  6. Hey Chuck! I agree until you look at the code. The faster performance
    could have been due to the amount of entities within the file - not vb
    vs. vba. Simply, he tried it on smaller files, or by luck only hit
    smaller files.
    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 17, 2004
    #6
  7. Impossible! That would mean I was wrong, and I simply can't accept
    that. :)

     
    Chuck Gabriel, Feb 18, 2004
    #7
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.