Switching active document

Discussion in 'AutoCAD' started by Tom Roberts, Oct 21, 2004.

  1. Tom Roberts

    Tom Roberts Guest

    I would like to allow my Users to select an entity in a open drawing, switch
    to another open drawing, pick an entity in the second drawing and transfer
    some properties from the first ent to the second.

    Is this possible...?
    I got as far as bringing up a msgbox to pause the macro and allow the User
    to switch drawings.
    Then found that msgboxes are modal (of course)
    Then found a way to show modeless msgboxes via the windows API

    However, what I am finding is that I seems the ThisDrawing and
    Application.ActiveDocument is set when the macro begins as they are not
    updated when the User switches to the second drawing

    Does anyone have a clue what I am on about and can give me some assistance
    Example of code below
    --
    Regards
    Tom Roberts
    __________________________
    MechWest Design & Drafting
    Perth, Western Australia


    '*********** START OF VBA CODE ************
    Private Declare Function MsgBoxX _
    Lib "User32" Alias "MessageBoxA" _
    (Optional ByVal hWnd As Long, _
    Optional ByVal prompt As String, _
    Optional ByVal title As String, _
    Optional ByVal buttons As Long) _
    As Long

    Sub Adopt()

    Dim Ent As AcadEntity
    Dim BlkRef As AcadBlockReference
    Dim ret As Integer
    Dim vPnt As Variant
    Dim vAtts As Variant

    ret = MsgBoxX(&O0, "Pick source object", "Adopt Prosteel Properties",
    vbOKCancel + vbSystemModal)

    If ret = vbCancel Then
    Exit Sub
    End If

    ThisDrawing.Utility.GetEntity Ent, vPnt

    ret = MsgBoxX(&O0, "Pick part titleblock", "Adopt Prosteel Properties",
    vbOKCancel + vbSystemModal)
    If ret = vbCancel Then
    Exit Sub
    End If

    PICK_AGAIN:
    ThisDrawing.Utility.GetEntity BlkRef, vPnt '<--------macro hangs
    here. Doesn't honour new active document
    If BlkRef.HasAttributes Then
    vAtts = BlkRef.GetAttributes
    Else
    MsgBox "Not a valid titleblock", vbInformation + vbOKOnly, "Adopt
    Prosteel Properties"
    GoTo PICK_AGAIN
    End If

    End Sub

    '*********** END OF VBA CODE ************
     
    Tom Roberts, Oct 21, 2004
    #1
  2. Tom Roberts

    Kevin Terry Guest

    Dim acTempFile As AcadDocument
    Set acTempFile = ThisDrawing.Application.ActiveDocument

    Now you have a reference to the parent file. So instead of this:
    you can use this:
    HTH,
    Kevin
     
    Kevin Terry, Oct 21, 2004
    #2
  3. Tom Roberts

    Tom Roberts Guest

    Thanks, but as I stated in the original message
    I am finding that ThisDrawing and Application.ActiveDocument is set when the
    macro begins and they are not updated when the User switches to the second
    drawing.

    Is this the correct behaviour, or have I stuffed something up

    --
    Regards
    Tom Roberts
    __________________________
    MechWest Design & Drafting
    Perth, Western Australia
     
    Tom Roberts, Oct 22, 2004
    #3
  4. Tom Roberts

    Kevin Terry Guest

    I guess I wouldn't trust thisdrawing to work in any setting other than a
    single macro running in a single file. Since assigning both/any/all open
    drawings to separate variables is an easy option, I see that as a more
    robust and recommended design.

    Kevin
     
    Kevin Terry, Oct 23, 2004
    #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.