Skip to content

Commit

Permalink
Export all Roster Entries as DCC-EX ROSTER() macro calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mstevetodd committed Apr 14, 2023
1 parent 5335f7f commit 31bb53d
Showing 1 changed file with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
# RosterExportToDCC-EX.py, v1.0.0, 04/13/2023
# RosterExportToDCC-EX.py, v1.2.0, 04/14/2023
# Export all JMRI Roster Entries as ROSTER() macro calls
# Syntax: ROSTER(999,"Loco Name","F0/F1/*F2/F3/F4/F5/F6/F7/F8")
# Open the Script Output Window, run the script, and then copy the lines into your myAutomation.h
# Run the script. It will show a list of formatted ROSTER() calls which you can copy.
# Copy the lines into your myAutomation.h and compile+upload DCC-EX to your Arduino.
# For convenience, you can "add script to button..." in Preferences, Startup
# NOTE: EX-CommandStation cannot (yet) handle multiple roster entries with the same address
# Author: mstevetodd, copyright 2023
# Part of the JMRI distribution

#import jmri
import jmri.jmrit.roster
import java
import jmri
import java.awt
import javax.swing

print("")
print("//copy the lines below into your myAutomation.h file for EX-CommandStation")
#find or create the display to show the macro calls
title = "Roster Export To DCC-EX"
f = jmri.util.JmriJFrame.getFrame(title)
if (f is None) :
f = jmri.util.JmriJFrame(title)
jta = javax.swing.JTextArea(100,100)
jsp = javax.swing.JScrollPane(jta)
f.getContentPane().add(jsp, java.awt.BorderLayout.CENTER)
f.pack();
else :
jta = f.getContentPane().getComponents()[0].getComponents()[0].getComponents()[0] #get the text area from the open window
f.setExtendedState(java.awt.Frame.NORMAL) #restore if minimized
f.setVisible(True);

#build a text message that will be displayed in the new window
msg = "//copy the lines below into your myAutomation.h file for EX-CommandStation\n"

dups = []

Expand Down Expand Up @@ -40,5 +58,9 @@
if (not entry.getFunctionLockable(func)) : label = '*' + label # prepend '*' to indicate momentary
rc = rc + label + "/" # add this label to entry

# close the syntax and write out the completed line
print (rc + "\")")
# close the syntax and add this completed line to the message
msg += rc + "\")\n"

#put the message in the window's text area
msg += "//copy the lines above into your myAutomation.h file for EX-CommandStation\n"
jta.setText(msg)

0 comments on commit 31bb53d

Please sign in to comment.