Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Language Setting info 2

Status
Not open for further replies.

dddn

Mechanical
Nov 26, 2022
35
0
0
IT
Hello everyone,
I want obtain info language setting of CATIA with a simple macro;
Can help me someone?
I know I can read the body name of the firt part and so deduct the language, but I want a msgbox that tell me which language is setting.

Thank you to all
 
Replies continue below

Recommended for you

Hi dddn -San.

The status bar in the lower left corner of the screen displays different characters for each language.
I have created a function to determine the language by how "Object" is displayed when nothing is selected.
Link

I am using Japanese CATIA V5, so the characters to be judged may be slightly different, but it should be usable enough.
 
Code below doesn't rely on any side effects and reads language from CATIA settings.
Note that default CATIA behavior is to use system language, which can be obtained with GetLocale() function.

Code:
'==============================================================================
'   Gets current CATIA UI language by reading FrameGeneral.CATSettings file
'==============================================================================
Private Function GetLanguageFromSettings()
    ' set the defaul return value
    GetLanguageFromSettings = ""
    
    ' read FrameGeneral.CATSettings from settings as binary
    Dim fso, settingsFile, content, filePos
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set settingsFile = fso.OpenTextFile(fso.BuildPath(CATIA.SystemService.Environ("CATUserSettingPath"), "FrameGeneral.CATSettings"))
    content = settingsFile.ReadAll()
    settingsFile.Close
    filePos = InStr(content, "UserInterfaceLanguage")

    ' read byte that stores setting value
    Select Case Asc(Mid(content, filePos + 54, 1))
        Case &HE5:  GetLanguageFromSettings = "RU"
        Case &H56:  GetLanguageFromSettings = "FR"
        Case &HCA:  GetLanguageFromSettings = "EN"
        Case &H5A:  GetLanguageFromSettings = "DE"
        Case &H27:  GetLanguageFromSettings = "JP"
        Case &H24:  GetLanguageFromSettings = "CH"
        Case &H60:  GetLanguageFromSettings = "KO"
        Case &H0:   GetLanguageFromSettings = "SYSTEM"
    End Select
End Function
 
Hi,
thank you all.
Little C. your idea is very interesting but I don't have access at FrameGeneral settings, and so the macro dosen't work; but is a good input and I will try to read this settings.

Thanky you so much.
 
I have this setting file but I can't manipulate; I want to get a msgbox with a selected language, but I don't know a way to do it.
 
What error does it raise? Can you post a screenshot?

Code:
Sub CATMain()
    MsgBox GetLanguageFromSettings()
End Sub
'==============================================================================
'   Gets current CATIA UI language by reading FrameGeneral.CATSettings file
'==============================================================================
Private Function GetLanguageFromSettings()
    ' set the defaul return value
    GetLanguageFromSettings = ""
    
    ' read FrameGeneral.CATSettings from settings as binary
    Dim fso, settingsFile, content, filePos
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set settingsFile = fso.OpenTextFile(fso.BuildPath(CATIA.SystemService.Environ("CATUserSettingPath"), "FrameGeneral.CATSettings"))
    content = settingsFile.ReadAll()
    settingsFile.Close
    filePos = InStr(content, "UserInterfaceLanguage")

    ' read byte that stores setting value
    Select Case Asc(Mid(content, filePos + 54, 1))
        Case &HE5:  GetLanguageFromSettings = "RU"
        Case &H56:  GetLanguageFromSettings = "FR"
        Case &HCA:  GetLanguageFromSettings = "EN"
        Case &H5A:  GetLanguageFromSettings = "DE"
        Case &H27:  GetLanguageFromSettings = "JP"
        Case &H24:  GetLanguageFromSettings = "CH"
        Case &H60:  GetLanguageFromSettings = "KO"
        Case &H0:   GetLanguageFromSettings = "SYSTEM"
    End Select
End Function
 
line_error_zikav9.png
error_nmswur.png

I have correct the error, with the direct path of the FrameGeneral and in this way, macro is correct. I don't catch why then line doesn't work, with your script.
 
Run this script and post messages it displays.

Code:
Sub CATMain()
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    MsgBox "Dir: " & CATIA.SystemService.Environ("CATUserSettingPath")
    MsgBox "Path: " & fso.BuildPath(CATIA.SystemService.Environ("CATUserSettingPath"), "FrameGeneral.CATSettings")
    MsgBox CStr(fso.FileExists(fso.BuildPath(CATIA.SystemService.Environ("CATUserSettingPath"), "FrameGeneral.CATSettings")))
End Sub
 
Ok, modify GetLanguageFromSettings function above:

Code:
Dim fso, dir, path, settingsFile, content, filePos
    Set fso = CreateObject("Scripting.FileSystemObject")
    For each dir in Split(CATIA.SystemService.Environ("CATUserSettingPath"), ";")
        path = fso.BuildPath(dir, "FrameGeneral.CATSettings")
        If fso.FileExists(path) then
            Set settingsFile = fso.OpenTextFile(path)
            content = settingsFile.ReadAll()
            settingsFile.Close
            Exit for
        End if
    Next
    If IsEmpty(dir) then
        Exit function 
    End if
 
Final version with "SYSTEM" language analysis:

Code:
'==============================================================================
'   Gets current CATIA UI language by reading FrameGeneral.CATSettings file
'==============================================================================
Private Function GetLanguageFromSettings()
    ' set the defaul return value
    GetLanguageFromSettings = ""
    
    ' locate FrameGeneral.CATSettings among all settings directories
    Dim fso, dir, path, settingsFile, content, filePos, ss
    Set fso = CreateObject("Scripting.FileSystemObject")
    For Each dir In Split(CATIA.SystemService.Environ("CATUserSettingPath"), ";")
        path = fso.BuildPath(dir, "FrameGeneral.CATSettings")
        If fso.FileExists(path) Then
            Exit For
        End If
    Next
    If IsEmpty(dir) Then
        Exit Function
    End If

    ' read file
    Set settingsFile = fso.OpenTextFile(path)
    content = settingsFile.ReadAll()
    settingsFile.Close
    filePos = InStr(content, "UserInterfaceLanguage")

    ' read byte that stores setting value
    Select Case Asc(Mid(content, filePos + 54, 1))
        Case &HE5:  GetLanguageFromSettings = "RU"
        Case &H56:  GetLanguageFromSettings = "FR"
        Case &HCA:  GetLanguageFromSettings = "EN"
        Case &H5A:  GetLanguageFromSettings = "DE"
        Case &H27:  GetLanguageFromSettings = "JP"
        Case &H24:  GetLanguageFromSettings = "CH"
        Case &H60:  GetLanguageFromSettings = "KO"
        Case &H0:   ' check system locale
            Set ss = CATIA.SystemService
            Select Case ss.Evaluate("Function Main() Main = GetLocale() End Function", CATVBScriptLanguage, "Main", Array())
                Case 1049: GetLanguageFromSettings = "RU"
                Case 1036: GetLanguageFromSettings = "FR"
                Case 1033: GetLanguageFromSettings = "EN"
                Case 1031: GetLanguageFromSettings = "DE"
                Case 1041: GetLanguageFromSettings = "JP"
                Case 2052: GetLanguageFromSettings = "CH"
                Case 1042: GetLanguageFromSettings = "KO"
            End Select
    End Select
End Function
 
Hi Little C. thanks again.

For the string "content = settingsFile.ReadAll()", is it possible to have a msgbox with all content of the FrameGeneral.CATSettings? When I print msgbox content I obtain: M◻︎
 
Not possible, because .CATsettings files are binary and contain null bytes which are atreated as end of string chars by VBA.

You really have to dig in with hex editor by yourself or use CAA to read it.
 
Status
Not open for further replies.
Back
Top