Detecting doc close event?

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

Reply to
What-a-Tool
Loading thread data ...

it is the DestroyNotify Event

This is triggered before a document is closed.

Corey

Reply to
Corey Scheich

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.

Reply to
What-a-Tool

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

message

Reply to
Corey Scheich

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.

Reply to
rocheey

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.

Reply to
What-a-Tool

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)

Reply to
What-a-Tool

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.