Cancel a command

Cancel a command

Anonymous
Not applicable
1,359 Views
5 Replies
Message 1 of 6

Cancel a command

Anonymous
Not applicable
I want to cancel every edit command when a inventor document is read-only and give the user a message. (such as ESC) The message i get but the command isn't cancelled. (wrong commandname "FDTrasparentCancel" ?)
How can I do this?

Code:
Private Sub mobjUserInputEvents_OnActivateCommand(ByVal CommandName As String, ByVal Context As NameValueMap)
On Error GoTo Errorhandler
Dim fs As New FileSystemObject
Dim oFile
Dim oINVDoc As Inventor.Document
Set oINVDoc = objInventorApp.ActiveDocument

If UCase(Left(oINVDoc.FullDocumentName, 3)) = "T:\" Then
'check of is file read_Only
Set oFile = fs.GetFile(oINVDoc.FullDocumentName)
If oFile.Attributes = 1 Or oFile.Attributes = 33 Then
objInventorApp.CommandManager.PromptMessage "Let op Command: " & oINVDoc.DisplayName & " is Read_Only en kan niet gewijzigd worden!", vbExclamation
'Cancel edit command
Dim oControlDef As ControlDefinition
Set oControlDef = objInventorApp.CommandManager.ControlDefinitions.Item("FDTrasparentCancel")
oControlDef.Execute
End If
End If

Exit Sub

Errorhandler:
GeneralErrorHandler "mobjUserInputEvents_OnActivateCommand"

End Sub
0 Likes
1,360 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
I just found how to cancel every command

'Cancel edit command
objInventorApp.CommandManager.StopActiveCommand

but I want only to stop the edit commands.
Is that possible?
0 Likes
Message 3 of 6

Anonymous
Not applicable
I just made a workaround to cancel the invoked command.
I hope there is a better (easier) way, so if anyone has a idea?

Now I've just one little problem with my code (see below)
When the command is cancelled the button in the panelbar stays pressed and my cursor has a plus sign to it.
I assume that the command isn't cancelled completly?
How can i make that the buttons aren't pressed? See attachment.

Code: This is a snippset of my previous code mobjUserInputEvents_OnActivateCommand

'close command
Dim oCancelCommand As clsCancelCommand
Set oCancelCommand = New clsCancelCommand
oCancelCommand.Initialize
oCancelCommand.SetTrigger
Set oCancelCommand = Nothing

Code in class -> clsCancelCommand
Option Explicit
Private WithEvents oInteractionEvents As InteractionEvents

Public Sub Initialize()
On Error GoTo Errorhandler
Set oInteractionEvents = objInventorApp.CommandManager.CreateInteractionEvents
oInteractionEvents.Start
Exit Sub

Errorhandler:
GeneralErrorHandler "Initialize-CancelCommand"
End Sub
Public Function SetTrigger() As Boolean
Dim strCommandName As String

On Error Resume Next
Do While LCase(strCommandName) = "interactionevents" Or strCommandName = ""
DoEvents
Loop
'Stop event
oInteractionEvents.Stop
End Function

Private Sub oInteractionEvents_OnTerminate()
'sluit active commando af
objInventorApp.CommandManager.StopActiveCommand
'Refresh panelbar!


End Sub
0 Likes
Message 4 of 6

maxim.teleguz
Advocate
Advocate

add the following to your code: 

System.Windows.Forms.SendKeys.SendWait("{ESC}")
ThisApplication.UserInterfaceManager.DoEvents
0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Actually, that might not work if the proper window/dialog does not have top system focus at that moment.  Using SendKeys can be tricky.  You could try adding something like AppActivate(ThisApplication.Caption) on the line above the SendKeys line, but no guarantees.  A better option might be to execute one of Inventor's built-in commands for exiting out of an active dialog/command.  Something like "AppContextual_CancelCmd".  There are other more specific commands for canceling out of other more specific actions/commands, but that is about the most generic one.

To use it, the line of code would look similar to this:

ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_CancelCmd").Execute

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

maxim.teleguz
Advocate
Advocate
AppContextual_ApplyCmd                        Apply

AppContextual_BackCmd                        &Back

AppContextual_CancelCmd                        Cancel (ESC)

AppContextual_ContinueCmd                        &Continue

AppContextual_CreateCmd                        &Create

AppContextual_DoneCmd                        &Done [ESC]

AppContextual_OKCmd                        OK (Enter)

AppContextual_RemoveCmd                        &Remove

AppContextual_RestartCmd                        &Restart

AppContinueCmd                        Continue to next step

AppExitCmd                        Quit the application; prompts to save documents

FeaExResultsCmd                        Exit Results

HSL:Cable:End_Command                        Create current segment and exit the command

Archon:Done                        End current command

DragAndDrop.Popup.CancelCommand                        End the command without applying changes

DragAndDrop.Popup.EndCommand                        Complete the command and commit changes

AppCGUCS_CreateCmd                        
AppCGUCS_DoneCmd                        
AppCGUCS_RestartCmd                        
AppCleanScreenCmd                        
AppCloseAllCmd                        Close all the documents

AppNavigationBarCloseCmd 
0 Likes