C#ATIA

↑タイトル詐欺 主にFusion360API 偶にCATIA V5 VBA(絶賛ネタ切れ中)

Fusion360を言語を指定して起動する1

こちらに挑んでます。
言語を指定して起動する方法 - Autodesk Community
そうです、僕が欲しいんです。

で、xmlを書き換える方向性でやってます。

Sub Main()

    path = "C:\temp\NMachineSpecificOptions.xml"
    '本番は"C:\Users\<PCアカウント>\AppData\Roaming\Autodesk\Neutron Platform\Options\NMachineSpecificOptions.xml"
    'です。念のため本物はバックアップをしておいてね

    Set dom = get_dom(path)
    If dom Is Nothing Then
        Exit Sub
    End If

    Set nodeRoot = dom.DocumentElement
    Set BootstrapOptionsGroup = getElementByTagName(nodeRoot, "BootstrapOptionsGroup")
    Set userLanguageOptionId = getElementByTagName(BootstrapOptionsGroup, "userLanguageOptionId")
    If userLanguageOptionId Is Nothing Then
        Set userLanguageOptionId = BootstrapOptionsGroup.appendChild(createNode(dom))
    End If
    
    Set langValue = getAttributeByName(userLanguageOptionId, "Value")

    If langValue.Value = "ja-JP" Then
        lang = "en-US"
    Else
        lang = "ja-JP"
    End If

    langValue.Value = lang

    dom.Save path
    
End Sub

Function createNode(dom)
    Set node = dom.createElement("userLanguageOptionId")
    node.appendChild dom.createTextNode("test")
    node.setAttribute "ToolTip", "ユーザ インタフェースの表示に使用する言語です。"
    node.setAttribute "UserName", "ユーザ言語"
    node.setAttribute "Value", "en-US"
     
    Set createNode = node
End Function

Function getAttributeByName(node, name)

    Set getAttributeByName = Nothing

    For Each attr In node.Attributes
        If attr.BaseName = name Then
            Set getAttributeByName = attr
            Exit Function
        End If
    Next

End Function

Function getElementByTagName(node, name)

    Set getElementByTagName = Nothing
    
    Set lst = node.getElementsByTagName(name)
    If lst.Length < 1 Then Exit Function
    
    Set getElementByTagName = lst.Item(0)

End Function

Function get_dom(path)

    Set dom = CreateObject("Msxml2.DOMDocument")
    res = dom.Load(path)
    
    If res Then
        Set get_dom = dom
    Else
        Set get_dom = Nothing
    End If

End Function

開発は、ExcelVBAで行ってますが、実際はVBScriptにする予定です。
VBScript時には先頭に

call Main()

を入れるだけです。

こちらを実行するとxmlを日本語->英語 日本語以外->英語 に書き換えます。

ちょっと危ない匂いがするので、
・元xmlをバックアップ
 ↓
xml書き換え
 ↓
Fusion360を起動
 ↓
・書き換えたxmlは捨て、元のxmlに戻す
を行う予定です。 届くかな?