Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command "Recognize" and error message

Status
Not open for further replies.

Thosnow

Aerospace
Feb 23, 2017
68
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:
SHEET_METAL_wv9odr.jpg


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.
 
Replies continue below

Recommended for you

Thanks for your suggestion but {ESCAPE} doesn't work. I have tried many time after running command "Recognize".
 
Are you sure CATIA is the active app when sending ESCAPE?
 
Yes...I am really sure CATIA app is active when press ESCAPE. I can only either press Yes or No on the little window as seen above in order to Cancel or say yes to continue
 
Then I'm out for CATIA API

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).

 
I have tried to google up to see any similar WinAPI error message but have not seen anything close yet.

Could you please be more specific/detailed?
 
There you go. Call this sub when you want to click No


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
[indent]'If you want to click Yes, change below to "&Yes"[/indent]
    	hNoWnd = FindWindowExhValidationErrorWnd, 0, 0, "&No")
    	SendMessage hNoWnd, BM_CLICK, 0, 0
End Sub
 
Thanks cilici...

Is it VBA code or VB script?

I am busy today...but I will try and let you know its result.
 
It works in VBA/VB6/VB.NET.

Never tried it in VBScript although it might work (no idea, not a fan of VBScript)
 
Hi cilici,

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?

SUB_NO_pfpouh.jpg


I am using Windows 10 and VBA 6.5.

Thanks
 
So the syntax in your case would be:

Code:
Private Declare [b]PtrSafe[/b] Function FindWindow.....

And, obviously, there is a mistake on the last red line. It should be:

Code:
hNoWnd = FindWindowEx(hValidationErrorWnd, 0, 0, "&No")

 
Hi Fedro and Cilici...

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
PRIVATE_xy8wjw.jpg


*** Error list
ERROR_LIST_ekargo.jpg


Your help is much appreciated and have a great day.
 
Thosnow,

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 Integer

If you can't handle FROM here, you shouldn't use VS.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor