Opening Drawing

Discussion in 'AutoCAD' started by Lenny Louque, Feb 25, 2004.

  1. Lenny Louque

    Lenny Louque Guest

    I have the following code in an Active X DLL:

    Dim i As Integer
    Dim ActiveDoc As AcadDocument
    Dim BlockedDWG As Variant
    Dim Mode As Variant

    Set ThisDrawing = AcadApplication.ActiveDocument

    For i = 1 To lvFiles.ListItems.Count

    Set ActiveDoc = ThisDrawing.Application.ActiveDocument

    BlockedDWG = lvFiles.ListItems.Item(i).Text

    MsgBox BlockedDWG

    Mode = ThisDrawing.GetVariable("sdi")

    MsgBox Mode

    If Mode = 1 Then
    ThisDrawing.Open BlockedDWG
    ElseIf Mode = 0 Then
    ThisDrawing.Application.Documents.Open BlockedDWG
    ThisDrawing.Application.ActiveDocument = ActiveDoc
    ThisDrawing.Close
    End If
    Next i


    The new drawing never gets set to active. The new drawing is opened and
    then drawing1.dwg is set active, but never gets closed.

    Any help would be appriciated

    Lenny
     
    Lenny Louque, Feb 25, 2004
    #1
  2. You have to set the active document whenever you want it - not early on and
    expect it to auto-update. You also have some other issues with your coding
    logic...

    Dim oApp as AcadApplication
    Set oApp = GetObject(, "AutoCAD.Application.15")
    'or Application.16 [2004] or Application.16.1[2005]
    'how you connect to AAutoCAD wasn't shown so
    'be sure to check if a command is active or not
    Dim i As Integer
    Dim ActiveDoc As AcadDocument
    Dim BlockedDWG As Variant
    Dim Mode As Integer
    'mode is an integer and system wide, so grab it here before the loop
    Mode = oApp.ActiveDocument.GetVariable("sdi")
    MsgBox Mode
    'loop your listview control
    For i = 1 To lvFiles.ListItems.Count
    BlockedDWG = lvFiles.ListItems.Item(i).Text
    MsgBox BlockedDWG
    'use an If..Else --- ElseIf is not required since
    'mode can only be 1 or 0 and if it was more,
    'you're better off using a Select Case clause
    If Mode = 1 Then
    'grab active document NOW since SDI is active
    Set ActiveDoc = oApp.ActiveDocument
    'always issue a save first if unsure whether file requires saving
    ActiveDoc.Save
    'always open the file from the active document in SDI mode
    Set ActiveDoc = ActiveDoc.Open(BlockedDWG)
    Else
    'no need to save or use active document to open another file
    'if MDI is active
    Set ActiveDoc = oApp.Documents.Open BlockedDWG
    'wasn't sure which you were closing so this assumes the one
    'you just opened since there is reallly no need to close Drawing1
    ActiveDoc.Close False 'false is for saving or not in 2004+
    End If
    Next

    This should get you moving in the right direction
    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 25, 2004
    #2
  3. Thanks Mike for the help. I understand what you said about logic issues.

    I am still having ACAD hang up between drawing. When a drawing is opened
    acad hangs up. If I hit esc. the routine will continue; until the next
    drawing is opened then hangs up again. Do you have an idea what might be
    causing this?

    Thanks;
    Lenny
     
    jollyjimpoppy, Feb 26, 2004
    #3
  4. If you want to, email me your program at [work
    email is down til Monday] and I'll look at it for you. Other than that,
    check to see what else you have loading - lisps, etc., that may be clogging
    things up.
    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 26, 2004
    #4
  5. Lenny Louque

    Lenny Louque Guest

    Mike

    Thanks for the offer. One thing that is weird is that everything works fine if I use the program as a Standard EXE file. when I use it as an ActiveX DLL that is when Acad hangs up.

    Lenny
     
    Lenny Louque, Feb 26, 2004
    #5
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.