To make your CATScript macro run faster turn off the refresh display while the macro is running then turn it back on once it is complete, like so:
Sub CATMain()
CATIA.RefreshDisplay = False
‘enter code here
CATIA.RefreshDisplay = True
End Sub
You may also want to hide any file alerts (such as a dialog box that pops up notifying the user that the file they need to save is read only). Turn them on and off like this:
CATIA.DisplayFileAlerts = False
CATIA.DisplayFileAlerts = True
You can also change the size of the window to force CATIA to refresh or repaint. In this example, we will change the width of the window by two (may not be detectable to the eye) and reset it back to the original width (which is expressed in pixels):
Sub CATMain()
CATIA.RefreshDisplay = True
iWidth = CATIA.ActiveWindow.Width
CATIA.ActiveWindow.Width = iWidth – 2
CATIA.ActiveWindow.Width = iWidth
End Sub
Tips to make your CATIA macros run faster:
- Run in batch mode
- Turn display refresh off
- Turn file alerts off
- use colon to condense lines of code
Learn more about CATIA VBA and automation.
How do you choose “ok” on a pop up window to accept change. For example if I use CATIA.StartCommand “Measure Inertia” of a part and I want to keep it.
I guess one option is to use send keys but I believe that method is highly unreliable so I’m not sure there is a good way to do it.
try to use windows API functions to Get the window you need to click on , then find the button and send message to it
here is some functions you may use:
Private Declare Function PostMessage Lib “user32.dll” Alias “PostMessageA” (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Declare Function FindWindowEx Lib “user32.dll” Alias “FindWindowExA” (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
‘Private Declare Function SendMessage Lib “user32.dll” Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Thanks!