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!

Remove save all dialog box while making save all command with vb.net

Status
Not open for further replies.

TiagoFigueiredo

Industrial
May 22, 2013
494
PT
I have a very long macro, and while running it, I have inserted in the middle of it, a step to make the save all command.

CATIA.StartCommand("Save All")

It does exactly what i want, this is only to prevent loss the information in case of catia breaks down while executing macro.
But always appear that boring message box, and i have to press yes...
Capture_bx9f84.png


unfortenately it doesn't work with
catia.displayfilealerts=false

Any idea to prevent this step?

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Replies continue below

Recommended for you

Why not save each document individually and avoid the message? Are there links involved and you'd require a specific order of saving?
 
I tried this before,

Code:
Dim i As Integer
        Dim Num_documents As Integer
        documents1 = CATIA.Documents

        Num_documents = documents1.Count

        For i = 1 To Num_documents

            documents1.Item(i).Save()

        Next

but it takes more time to save, and is switching the display to the opened parts while saving...

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
First of all, I'd go with 'save each document individually' even though it takes more time. Switching the views is not relevant (you can put back the window you choose) although I can't understand why.

Secondly, if you really want to Save them All, try this:

Declarations:

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

Actual code:

Code:
Private Sub ClickOk()
    Dim lSaveAll As Long
    Dim lOK As Long
    
    lSaveAll = FindWindow("#32770", "Save All")
    Do While lSaveAll = 0
       lSaveAll = FindWindow("#32770", "Save All")
    Loop
    
    lOK = FindWindowEx(lSaveAll, 0&, 0&, "&Yes")
    Do While lOK = 0
       lOK = FindWindowEx(lSaveAll, 0&, 0&, "&Yes")
    Loop
    
    SendMessage lOK, BM_CLICK, 0, 0
    SendMessage lOK, BM_CLICK, 0, 0
End Sub

I recommend getting out of the Do-Loop(s) after a certain number of iterations and/or seconds to avoid the code looping to infinite and crashing your system.
You could also use the Sleep function to 'pause' in-between do-loop iterations.

Code:
 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)]

Hope it helps,
Calin
 
Wow!!! I was no expecting such an elaborated solution... It goes really ahead of my programming capabilities.

I have inserted your code in my visual studio project. But I have a few questions.

First

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

here i'm having a problem with As Any. It says that "As Any is not supported in declare statments".


The latest question, is where I insert the line:

CATIA.StartCommand("Save All")

Thanks

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
1. Ok, then change the declarations to fit the usage (put whatever you want as long as you respect the type when calling the function:

Code:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
                                                    ByVal lpWindowName As String) As Long

If you're using VS then change all "long" to "integer" and you should be fine.

2. For the other question, your code structure should look something like this:
- your whatever code;
- CATIA.StartCommand("Save All")
- Call ClickOK 'this should click ok for you
- continue with whatever code you have.

Hope it helps,
Calin
 
You didn't change the declaration of FindWindow as advised (any->string)
 
cilici,

The code stops at the line

CATIA.StartCommand("Save All")

then the message appears.

I will go back to the other idea.

Code:
Dim i As Integer
        Dim Num_documents As Integer
        documents1 = CATIA.Documents

        Num_documents = documents1.Count

        For i = 1 To Num_documents

            documents1.Item(i).Save()

        Next

And i will try it.

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
I've made a few comparisons, between the save all command, and save each document individually.

I've created some videos to see a comparison between the 2 methods.

save each document individually.

In this method, I see that there is a few strange behaviors.
1-While saving, the display of the parts, that are oppened in other windows, are switched
2-There is a lag between saving the parts that oppened. Don't know why but while saving it looks the action stops for while, and then returns.
3-The time of saving is definitely to long.

save all

Note: in this video I have removed the code provided by cilici.

Any thoughts about this?

Tiago Figueiredo
Tooling Engineer

Youtube channel:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top