Message 1 of 6
Prevent user to start other command while executing a macro

Not applicable
02-21-2013
06:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I have a macro that automatically creates a Detailed view on a sheet. It works on 2 input's:
- mouse click 1 (set's the target to be detailed)
- mouse click 2 (set's the location where the balloon should be)
The code works fine. But sometimes the user will start another command, or restart the same command, while it is still running. This off course gives all kinds of problems.
Is there a possibility in VBA to prevent the user to start another command while this command is running?
Or is this problem a part of the clicking itself?
Thanks,
Chris,
Here is my code: (it uses a Class Module called: clsGetPoint, see code below)
Sub AutoDetailedView() On Error GoTo ErrorManagment '(error handling 2013/02/18) 'step 0 Create a transaction. -> for 1 undo command Dim oTransMgr As TransactionManager Set oTransMgr = ThisApplication.TransactionManager Dim oTrans As Transaction Set oTrans = oTransMgr.StartTransaction(ThisApplication.ActiveDocument, "AutoDetailedView") 'step 1 Select a drawingView 'Set a reference to the drawing document. Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument 'Set a reference to the active sheet. Dim oSheet As Sheet Set oSheet = oDrawDoc.ActiveSheet ' Select a drawing view Dim oDrawingView As DrawingView Set oDrawingView = oSheet.DrawingViews.Item(1) 'select the below if you want the user to choose a drawing view, else the above will select the first drawingview on the active sheet 'Set oDrawingView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a drawing view.") 'step 2 Select the center of the circular fence Dim getPoint As New clsGetPoint Dim oCenterPoint As Point2d Set oCenterPoint = getPoint.GetDrawingPoint("Select the area to be detailed", kLeftMouseButton, kCursorBuiltInCursorSelTrail) 'step 3 Select the place where the detailed view need to be placed Dim oPoint As Point2d Set oPoint = getPoint.GetDrawingPoint("Select the location of the detailed view", kLeftMouseButton, kCursorBuiltInPushpinCursor) ' Get any linear curve from the base view Dim oCurve As DrawingCurve For Each oCurve In oDrawingView.DrawingCurves If oCurve.CurveType = kLineSegmentCurve Then Exit For Next ' Create an intent object Dim oAttachPoint As Point2d Set oAttachPoint = oDrawingView.Center 'step 4 Create the detail view Dim oDetailView As DetailDrawingView Set oDetailView = oSheet.DrawingViews.AddDetailView(oDrawingView, oPoint, kShadedDrawingViewStyle, True, oCenterPoint, 0.5, , 0.25, False, " ") 'Set breakline to smooth oDetailView.IsBreakLineSmooth = True 'Show full detail boundary oDetailView.DisplayFullBoundary = True 'Show connection line oDetailView.DisplayConnectionLine = True 'set detailview to "Parts" ' this assumes that there is an detailview called "Parts", if not, delete this line 'On Error Resume Next 'Call oDetailView.SetDesignViewRepresentation("Parts", False) 'step 5 Active top level of drawing (error handling 2013/02/18) ErrorManagment: '(error handling 2013/02/18) oSheet.Activate 'step 6 End the transaction. oTrans.End End Sub
and now the code for the clsGetPoint (Put it onder Class Modules)
Private WithEvents m_interaction As InteractionEvents Private WithEvents m_mouse As MouseEvents Private m_position As Point2d Private m_button As MouseButtonEnum Private m_continue As Boolean Public Function GetDrawingPoint(Prompt As String, button As MouseButtonEnum, m_Cursor As CursorTypeEnum) As Point2d Set m_position = Nothing m_button = button Set m_interaction = ThisApplication.CommandManager.CreateInteractionEvents Set m_mouse = m_interaction.MouseEvents m_interaction.StatusBarText = Prompt m_interaction.SetCursor (m_Cursor) m_interaction.Start m_continue = True Do ThisApplication.UserInterfaceManager.DoEvents Loop While m_continue m_interaction.Stop Set GetDrawingPoint = m_position End Function Private Sub m_mouse_OnMouseClick(ByVal button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) If button = m_button Then Set m_position = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.x, ModelPosition.Y) End If m_continue = False End Sub