Detecting doc close event?

Discussion in 'SolidWorks' started by What-a-Tool, Nov 3, 2004.

  1. What-a-Tool

    What-a-Tool Guest

    Is there a way to detect the closing of a drawing document? I am able to
    finagle my way around and get what I want done with these two following
    events, but thing would be so much easier if there was some sort of document
    close event. Is there something that I haven't found?

    Public Function SldApp_ActiveDocChangeNotify()
    Public Function ThisDoc_NewSelectionNotify()

    Thanks

    --

    / Sean the Mc /


    "I have not failed. I've just found 10,000 ways that won't work."
    - Thomas Alva Edison (1847-1931)
     
    What-a-Tool, Nov 3, 2004
    #1
  2. it is the
    DestroyNotify Event

    This is triggered before a document is closed.


    Corey
     
    Corey Scheich, Nov 3, 2004
    #2
  3. What-a-Tool

    What-a-Tool Guest

    Thanks - Maybe you could give a suggestion on another problem I'm having.

    I have a collection filled with paths to SLDDRW docs. I want to iterate thru
    each of these items, open then in SW one at a time, and do some work on it.
    When I close the document, I want a form to appear.
    In other words - doc open, code execution halt, doc close, code execution
    resume.

    Now, I am calling a form from a module, opening the doc from within the
    form, which is hidden until the ActiveDocChangeNotify shows the form as
    modal. However, I can't get my code execution to stop with the form because
    at this point it is not modal, and when it goes modal, I can't work on my
    drawing. I've tried stopping execution with a timer and DOEVENTS, but this
    works very poorly.
    Maybe I've just been looking at it to long and can't see the obvious.

    Any suggestions - please ?

    Thanks again.

    --

    / Sean the Mc /

    "Opinions are like flatulence - everyone loves the sound of their own,
    but anyone else's usually just stinks !"
    -anonymous
     
    What-a-Tool, Nov 4, 2004
    #3
  4. Events will work.
    try something like this. Mind you I haven't tested it so you will have to
    do some foot work.

    Dim WithEvents swDrw as DrawingDoc

    Sub OpenDrawingFromCollection (Index as long)
    opendoc6 Collection(Index)..........'meaning I am not going to look into
    the whole line
    set swDrw = swApp.ActiveDoc
    userform.hide
    end sub

    Private Function swDrw_DestroyNotify() As Long
    userform.show
    End Function

    regards,

    Corey
     
    Corey Scheich, Nov 4, 2004
    #4
  5. What-a-Tool

    rocheey Guest

    I have a collection filled with paths to SLDDRW docs. I want
    So you already have a list/array/collection, and already have a loop
    coded?

    The key here is that the code never gets 'halted'... it sits around
    waiting for something to do.

    And since you have 2 simultaneous classes running (SWX events, form
    module)
    they may run when THEY feel its right.

    You can either:

    1) Poll: Run a DO-LOOP within your drawing loop, waiting for the Form
    to end up in the right state, most likely with a public Variable.
    Easier to implement, but more CPU intensive.

    2) Events: re-write your Drawing loop to do ONE drawing, move it to
    its own sub/function. Every time the routine is called, it works on
    the first drawing in the collection, removes the drawing from the
    collection, and exits the function.

    Kind of like making a "Close Form" button actually being a "Close SWX
    drawing and open another, if there is still one available" button.
     
    rocheey, Nov 4, 2004
    #5
  6. What-a-Tool

    What-a-Tool Guest

    This is what I have working now:

    Private SldApp As SldWorks.SldWorks
    Private WithEvents ThisModalDoc As SldWorks.DrawingDoc

    Sub UserForm_Initialize()
    'Form wants to be hidden, to be shown only when current doc is
    closed
    Me.Hide
    Set SldApp = Application.SldWorks

    Sub DocStart()
    strCurrDoc = colSWDrawFiles(1)
    colSWDrawFiles.Remove (1)
    Set swDrawDoc = PartOpen(strCurrDoc, "SLDDRW")
    SldApp.ActivateDoc2 strCurrDoc, True, lngwarnings
    Set ThisModalDoc = SldApp.ActiveDoc
    'Cant get this line to work - toolbars are inactive for some reason
    swDrawDoc.Toolbars True, False, True, True, False, False, False
    Call DelayTime(conDelay)

    Part open is a function that uses :
    Set swModel = swApp.OpenDocSilent(strMyFile, _
    swDocDRAWING, lngwarnings)

    DelayTime is a sub containing:
    Dim Start As Double
    Start = Timer ' Set start time.
    Do While Timer < Start + T
    DoEvents ' Relinquish control to the processor
    Loop
    If blnDestroyed Then 'Document closed if true - set in
    ThisModalDoc_DestroyNotify()
    'Show form as modal to stop code
    Me.Show
    Else 'Document is still open
    Call DelayTime(conDelay)
    End If

    A button_Click event calls DocStart() all over again

    This actually works pretty smoothly - in spite of being rather processor
    intensive.
    Only problem now is that my application toolbars are all de-activated for
    some reason.

    --

    / Sean the Mc /

    "Opinions are like flatulence - everyone loves the sound of their own, but
    anyone else's usually just stinks !"
    -anonymous
     
    What-a-Tool, Nov 5, 2004
    #6
  7. What-a-Tool

    What-a-Tool Guest

    A little too processor intensive - time to re-think what it is that I'm
    trying to do, and come up with another way I guess. Shee-it!

    Worked on the first PC I ran it on. Second one, all my toolbars were
    de-activated. Third one, my document interactions were all screwy
    (dimensioning, drawing, ect..)

    Back to the drawing board (so to speak)
    --

    / Sean the Mc /

    "Opinions are like flatulence - everyone loves the sound of their own, but
    anyone else's usually just stinks !"
    -anonymous
     
    What-a-Tool, Nov 6, 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.