Drawing Object

Discussion in 'AutoCAD' started by HJohn, May 19, 2004.

  1. HJohn

    HJohn Guest

    I have an appl. that opens a drawing as read only so users can copyclip some blocks. I need a way of closing this drawing without being prompted to save changes. I thought in saving this document on a variable and then using its EndCommand event, but I can't find a way of achieving it. Can someone give some ideas or a better solution? Thanks in advance.
     
    HJohn, May 19, 2004
    #1
  2. HJohn

    Ed Jobe Guest

    The first arg of the Close method is SaveChanges. Set to False to prevent prompting. The drawing will be closed without saving.
     
    Ed Jobe, May 19, 2004
    #2
  3. HJohn

    HJohn Guest

    Thanks Ed, I could do that if I were to close the opened "Read Only" file from the code. The file is being closed by the user. At this point the code(application) is terminated as soon as the file is opened. I could use thisdrawing object of the project to handle this. Is there a way of saving the drawing object into a variable and then using its events? I want the user to finish the copyclip command and then intersect an event to handle the closing, all of this from the same app. module, without adding additional code to the thisdrawing.
     
    HJohn, May 19, 2004
    #3
  4. HJohn

    Ed Jobe Guest

    The help says that the Close event is initiated as soon as acad recieves a request to close a doc. In my testing, this is not true. If the dwg has changes, you are first prompted to save via a dialog. And the help also states that if there is a modal dialog open, no events are fired. Therfore, events won't work in this case. You could redefine the close command to first check if the dwg is read-only (I havn't tested this). But then you stand the possiblilty of loosing work. You could also create a temporary command via code that would close the doc and train the users to close using this rather than just clicking on the X.
     
    Ed Jobe, May 19, 2004
    #4
  5. HJohn

    HJohn Guest

    Thanks again. I don't want to complicate things. I tried to use the thisdrawing object to handle the closing, I thought it was easy, but I don't know how to do it. How can I prevent the save changes dialog from showing during the closing, since it is a read only drawing?
     
    HJohn, May 19, 2004
    #5
  6. HJohn

    Ed Jobe Guest

    That's what I was trying to say. Using vba, you can't "override" the save change dialog in your situation. The only other thing I can think of is to reset the DBMOD sysvar to 0 in the ObjectModified event. For that, you need askdunsupp200x.arx. Search this ng for a copy for your version of acad. Note again, that this can be dangerous in that users may not be able to save their changes if they really wanted to. I would include a check on the readonly prop to at least limit this behavior to readonly dwgs.
     
    Ed Jobe, May 19, 2004
    #6
  7. HJohn

    HJohn Guest

    Thank you Ed for your help. I don't want to rethink this, so I am going to leave it just the way it is. It is one of those things that seem very easy but turn out to be complicated.
     
    HJohn, May 19, 2004
    #7
  8. HJohn

    Ed Jobe Guest

    I wouldn't mess with redefining the close command either. Give some more thought to popping a toolbar button when the user switches to the read-only dwg. I don't have time to show you how to create a toolbar button, but replace the msgbox code with code that displays a toolbar button in the middle of the screen.

    'Where Doc is a Document variable declared With Events
    Private Sub Doc_Activate()
    If Doc.ReadOnly = True Then
    MsgBox ("This dwg is read-only")
    'Display a 'Close Me' toobar button here
    'that uses the Close method with the SaveChanges arg =False
    End Sub
     
    Ed Jobe, May 19, 2004
    #8
  9. HJohn

    HJohn Guest

    Ed could you see if you could make something like this work. I always get "Drawing is busy". I tried a few things but I don't have much experience with object events. Thanks in advance.

    Option Explicit
    Public WithEvents Dwg As AcadDocument
    Dim DwgName As String
    Dim CurrDwg As String
    Private Sub CmmdCancel_Click()
    Set Dwg = Nothing
    Application.Documents.Item(DwgName).Close False
    Unload Me
    End Sub

    Private Sub UserForm_Activate()
    CurrDwg = ThisDrawing.name
    End Sub

    Private Sub CmmdGetDrawing_Click()
    Dim NewDwg As String

    NewDwg = "C:\Documents and Settings\HJohn\Desktop\Drawing1.dwg"

    Set Dwg = Application.Documents.Open(NewDwg, True)

    DwgName = Dwg.name

    Me.Hide

    End Sub

    Private Sub Dwg_EndCommand(ByVal CommandName As String)

    If CommandName = "COPYCLIP" And Dwg.ReadOnly = True Then
    Application.Documents.Item(CurrDwg).Activate
    Me.Show
    Call CmmdCancel_Click
    End If
    End Sub
     
    HJohn, May 21, 2004
    #9
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.