Command "Recognize" and error message
Command "Recognize" and error message
(OP)
Hello All,
I have tried to use command "Recognize" in a VBA scrip (as seen below) to recognize a sheet metal CATPart for unfolding and I get an error message as per below picture.
CATIA.StartCommand "Recognize"
'// Press ALT and N letter to say No to cancel command "Recognize"
SendKeys "{N 1}" '// meaning Press letter N on the keyboard once. This script does not work
Error message:

How can I detect the above error message with a VBA script?
SendKeys "%(N)" '// this script tries to cancel command "Recognize" but it does not work either
In other words, what would be the right script and/or syntax to detect the above error message and cancel command "Recognize" automatically?
Your help is much appreciated.
I have tried to use command "Recognize" in a VBA scrip (as seen below) to recognize a sheet metal CATPart for unfolding and I get an error message as per below picture.
CATIA.StartCommand "Recognize"
'// Press ALT and N letter to say No to cancel command "Recognize"
SendKeys "{N 1}" '// meaning Press letter N on the keyboard once. This script does not work
Error message:

How can I detect the above error message with a VBA script?
SendKeys "%(N)" '// this script tries to cancel command "Recognize" but it does not work either
In other words, what would be the right script and/or syntax to detect the above error message and cancel command "Recognize" automatically?
Your help is much appreciated.





RE: Command "Recognize" and error message
?
RE: Command "Recognize" and error message
RE: Command "Recognize" and error message
RE: Command "Recognize" and error message
RE: Command "Recognize" and error message
Of course, there is WinAPI that can be used. That would be quite easy in your case: find the window with the title "Validation Error" and find the sub-windows corresponding to YES / NO buttons and click them (also by WinAPI function SendMessage).
RE: Command "Recognize" and error message
Could you please be more specific/detailed?
RE: Command "Recognize" and error message
CODE -->
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Long, _ ByVal hwndChildAfter As Long, ByVal lpszClass As Long, _ ByVal lpszWindow As Any) As Long Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As Long Private Const BM_CLICK = &HF5 Private Sub ClickNo() Dim hValidationErrorWnd as long hValidationErrorWnd = FindWindow(CLng(0), "Validation error") Dim hNoWnd As Long'If you want to click Yes, change below to "&Yes" hNoWnd = FindWindowExhValidationErrorWnd, 0, 0, "&No")
SendMessage hNoWnd, BM_CLICK, 0, 0
End Sub RE: Command "Recognize" and error message
Is it VBA code or VB script?
I am busy today...but I will try and let you know its result.
RE: Command "Recognize" and error message
Never tried it in VBScript although it might work (no idea, not a fan of VBScript)
RE: Command "Recognize" and error message
I pasted your code in VBA 6.5 and Visual Studio 2017 and lots of text lines become red as seen on picture below.
DO you have any idea?
I am using Windows 10 and VBA 6.5.
Thanks
RE: Command "Recognize" and error message
If you are on 64-bit Windows architecture you need to add PtrSafe in front of Function
Regards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Command "Recognize" and error message
CODE -->
And, obviously, there is a mistake on the last red line. It should be:
CODE -->
RE: Command "Recognize" and error message
I have modified the above code with PtrSafe but still have lots of errors as per pictures below. I have tried to figure out but no success yet. Please help
*** My code in Visual Studio 2017 Community
*** Error list
Your help is much appreciated and have a great day.
RE: Command "Recognize" and error message
the code works in all aforementioned IDEs but not entirely the same (e.g. 'long' in VS should be 'integer' type, PtrSafe is only if you run VBA on 64bits and so on)
Here are the declarations for VS:
CODE -->
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, _ ByVal wMsg As Integer, ByVal wParam As Integer, _ ByVal lParam As String) As Integer Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As Integer, ByVal lpsz2 As String) As IntegerIf you can't handle FROM here, you shouldn't use VS.
Good luck!