I tried to prevent user closing dgn file if a certain task hasn't been finished using C#.
Is there an event handler on file closing and some parameter can be set so that the closing action can be canceled?
Gang
Hi Jan,
I really appreciate your help on it. I think that should be the only solution to our case.
Best,
Hi Gang,
Unknown said:Can that be implemented in C#?
I don't think so, I see no wrapper for mdlInput_setMonitorFunction in MDL help file. In the past (I am not sure if in this forum or in BDN community) alternatives what to do if a wrapper is missing were discussed, but it's not an easy way and it requires deep knowledge from more areas.
You have to accept today C# API (which is not "true NET API" but VBA/COM) is limited and C/C++ is the only way to receive maximum functionality. What about to create small MDL app, which will be loaded and controled (using key-ins) by your add-in and which will block a file unloading process?
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: Gang
Chris,
Thanks for your coding using MDL. Can that be implemented in C#? Since our current Add-in is written in C#.
Thanks Jan.
I am using it to monitor it, but didn't find a way to stop it.
In C (aka MDL):
Private int queueMonitor (Inputq_element *qeP /* <=> pointer to queue element */) { if ( qeP->hdr.cmdtype == CMDNUM ) { switch ( qeP->u.cmd.command ) { case CMD_EXIT: case CMD_NEWFILE: case CMD_CREATE_DRAWING: case CMD_DIALOG_OPENFILE: case CMD_EXCHANGEFILE: case CMD_CLOSE_DESIGN:
if ( cancelDrawingClose ) return INPUT_REJECT;
break; } } return INPUT_ACCEPT; }// establish hook mdlInput_setMonitorFunction ( MONITOR_ALL, queueMonitor );
break; } } return INPUT_ACCEPT; }
}
// establish hook
mdlInput_setMonitorFunction ( MONITOR_ALL, queueMonitor );
Cheers,
/Chris Z.
Unknown said:I didn't find the exact place for handling the closing event.
In you addin inherited from Addin class a delegate NewDesignFileEventHandler exists, so in e.g. Run method use:
this.NewDesignFileEvent += UDialog_NewDesignFileEvent;
and the method should be like this:
void UDialog_NewDesignFileEvent(Bentley.MicroStation.AddIn sender, Bentley.MicroStation.AddIn.NewDesignFileEventArgs eventArgs){ if (eventArgs.WhenCode == NewDesignFileEventArgs.When.BeforeDesignFileClose) { // do what you need here }}
The problem is you can use this code to monitor that the file will be closed but there is no a way (I am not aware about any) how to close the running closing process from the method. Maybe somebody else know how to do it.
But in general existing NET API (which is VBA/COM API) is not the good tool for such close integration with MicroStation and as Robert wrote, C MDL API or C++ MicroStationAPI provide more options.
Thanks Bob.
It's in-process. I didn't find the exact place for handling the closing event. Would you please provide more information about it? Your help are appreciated.
Your options will vary based on how you choose to implement a solution and whether your C# code is in-process (MDL Addin), or out-of-process (limited mostly to MicroStation VBA's COM methods).
HTH,Bob