Example Adding a Print Button

2
ModelSim Technotes – www.model.com ModelSim Tcl/Tk Examples You can run this example in any of the following ways: 1. Copy the example and paste it directly into ModelSim (at the ModelSim> or VSIM> prompt). 2. Copy the example and paste it into a file called "modelsim.tcl" in the directory that ModelSim will be invoked from (ModelSim looks for a file of this name in the current directory and in the user’s home directory). 3. Copy the example and paste it into a file with any name and then use the "source" command from the ModelSim prompt to load that Tcl/Tk code. 4. Copy the example and paste it into a file with any name and then set the environment variable MODELSIM_TCL to the name of the file prior to invoking ModelSim. [Note: MODELSIM_TCL can be a ":" separated list of Tcl/Tk files to load]. 5. [Not recommended] You copy and add the example to the file "<ModelSim Install Directory>/tcl/vsim/pref.tcl". This file gets loaded every time ModelSim is invoked. Care should be taken when editing this file because every user who uses ModelSim from that directory will load the Tcl/Tk that you have added. Add a Print button to the Wave Window Place the following Tcl/Tk code into your modelsim.tcl file either in the project directory or in your home directory. Alternatively, you can set the environment variable MODELSIM_TCL to the name of the file containing: # Setting the following variable will cause the procedure # addPrintButton to be called every time a ModelSim Wave # window is created. It will be called with a single argument # which is the name of the Wave window (".wave" , ".wave1" , # ".wave2" , etc). set PrefWave(user_hook) "addPrintButton" #Print the viewed waveform proc printit {wname} { set time_range [$wname.tree zoomrange] set time_start [lindex $time_range 0] set time_end [lindex $time_range 1]

description

eg

Transcript of Example Adding a Print Button

Page 1: Example Adding a Print Button

ModelSim Technotes – www.model.com ModelSim Tcl/Tk Examples

You can run this example in any of the following ways:

1. Copy the example and paste it directly into ModelSim (at the ModelSim> or VSIM> prompt).

2. Copy the example and paste it into a file called "modelsim.tcl" in the directory that ModelSim will be invoked from (ModelSim looks for a file of this name in the current directory and in the user’s home directory).

3. Copy the example and paste it into a file with any name and then use the "source" command from the ModelSim prompt to load that Tcl/Tk code.

4. Copy the example and paste it into a file with any name and then set the environment variable MODELSIM_TCL to the name of the file prior to invoking ModelSim. [Note: MODELSIM_TCL can be a ":" separated list of Tcl/Tk files to load].

5. [Not recommended] You copy and add the example to the file "<ModelSim Install Directory>/tcl/vsim/pref.tcl". This file gets loaded every time ModelSim is invoked. Care should be taken when editing this file because every user who uses ModelSim from that directory will load the Tcl/Tk that you have added.

Add a Print button to the Wave Window

Place the following Tcl/Tk code into your modelsim.tcl file either in the project directory or in your home directory. Alternatively, you can set the environment variable MODELSIM_TCL to the name of the file containing:

# Setting the following variable will cause the procedure # addPrintButton to be called every time a ModelSim Wave # window is created. It will be called with a single argument # which is the name of the Wave window (".wave" , ".wave1" , # ".wave2" , etc). set PrefWave(user_hook) "addPrintButton" #Print the viewed waveform proc printit {wname} { set time_range [$wname.tree zoomrange] set time_start [lindex $time_range 0] set time_end [lindex $time_range 1]

Page 2: Example Adding a Print Button

ModelSim Technotes – www.model.com $wname.tree write -width inch -height inch -start $time_start \ -end $time_end -margin 0.5inch -pagecount 1 \ -landscape wave.ps # If you send things to the printer with "lpr" then # uncomment the following line: # exec lpr wave.ps } #Add the print button for this wave window. proc addPrintButton {wname} { set wnamebase [string range $wname 1 end] ;#Strip leading "." apply_button_adder $wnamebase controls right #667de3 \ white Print "printit $wname" }

Note: If you get a message stating that "apply_button_adder" is an invalid command then you are probably on release 5.1f or before. To make the above example work with that release, replace the call to "apply_button_adder" with a call to "_add_menu" with the same arguments.