×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Command "Recognize" and error message

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.

RE: Command "Recognize" and error message

SendKeys {ESCAPE}

?

RE: Command "Recognize" and error message

(OP)
Thanks for your suggestion but {ESCAPE} doesn't work. I have tried many time after running command "Recognize".

RE: Command "Recognize" and error message

Are you sure CATIA is the active app when sending ESCAPE?

RE: Command "Recognize" and error message

(OP)
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

RE: Command "Recognize" and error message

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

RE: Command "Recognize" and error message

(OP)
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?

RE: Command "Recognize" and error message

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
'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

(OP)
Thanks cilici...

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

It works in VBA/VB6/VB.NET.

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

RE: Command "Recognize" and error message

(OP)
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?



I am using Windows 10 and VBA 6.5.

Thanks

RE: Command "Recognize" and error message

So the syntax in your case would be:

CODE -->

Private Declare PtrSafe Function FindWindow..... 

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

CODE -->

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

RE: Command "Recognize" and error message

(OP)
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


*** Error list


Your help is much appreciated and have a great day.

RE: Command "Recognize" and error message

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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources