3Dconnexion set button to Turn On/Off Show in .gh

Hi Guys.
If you are using 3Dconnexion space mouse. And if you want to set the button for boolen True/False in gh ( I got it for showing geometry ). You have to create .vbs macro ( copy to notepad and save as *.vbs ) , in 3Dconnexion Home app create new macro for button and load this script with your own .ico icon .

Dim fso, file, filePath, currentValue, newValue, lineNumber
lineNumber = 1  ' Set the line number to work with (1 for the first line, 2 for the second, etc.)

filePath = "C:\Users\karel\Documents\symbol\karel.txt"
Set fso = CreateObject("Scripting.FileSystemObject")

' Load all lines from the file into an array
Dim lines()
ReDim lines(0)

If fso.FileExists(filePath) Then
    Set file = fso.OpenTextFile(filePath, 1)
    
    Do Until file.AtEndOfStream
        lineContent = file.ReadLine
        If Trim(lineContent) <> "" Then  ' Skip empty lines
            ReDim Preserve lines(UBound(lines) + 1)
            lines(UBound(lines) - 1) = lineContent
        End If
    Loop
    file.Close
Else
    ' If the file does not exist, set default values for 8 lines
    ReDim lines(7)
    For i = 0 To 7
        lines(i) = "False"
    Next
End If

' If the specified line exists, load its value; otherwise, initialize it as "False"
If lineNumber <= UBound(lines) + 1 Then
    currentValue = Trim(lines(lineNumber - 1))
Else
    currentValue = "False"
    ReDim Preserve lines(lineNumber - 1)
    lines(lineNumber - 1) = "False"
End If

' Toggle the value for the specified line
If currentValue = "True" Then
    newValue = "False"
Else
    newValue = "True"
End If

lines(lineNumber - 1) = newValue

' Write all lines back to the file, skipping empty lines
Set file = fso.OpenTextFile(filePath, 2, True)
For Each line In lines
    If Trim(line) <> "" Then  ' Skip empty lines when writing
        file.WriteLine line
    End If
Next
file.Close

In gh , just read this .txt file. It has 0,5 latency. Its great.
For each button you have to create own .vbs file and change linenumber to another line.
I hope you will like it.

1 Like