<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.labrps.com/index.php?action=history&amp;feed=atom&amp;title=Command</id>
	<title>Command - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.labrps.com/index.php?action=history&amp;feed=atom&amp;title=Command"/>
	<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=Command&amp;action=history"/>
	<updated>2026-05-04T14:29:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.2</generator>
	<entry>
		<id>https://wiki.labrps.com/index.php?title=Command&amp;diff=2132&amp;oldid=prev</id>
		<title>LabRPS: Created page with &quot;==Introduction==   {{TOCright}}   A command is what is being executed when you press a toolbar button or type a keyboard shortcut. It can be a very simple action or a complex system that will open dialog boxes and wait for the user to perform specific tasks.  Each LabRPS command has a unique name, that appears in the :Category:Command Reference page. Commands can be launched by a toolbar button, a menu item, or from a Python|...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.labrps.com/index.php?title=Command&amp;diff=2132&amp;oldid=prev"/>
		<updated>2024-10-29T01:26:12Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Introduction==   {{TOCright}}   A &lt;a href=&quot;/Command&quot; title=&quot;Command&quot;&gt;command&lt;/a&gt; is what is being executed when you press a toolbar button or type a keyboard shortcut. It can be a very simple action or a complex system that will open dialog boxes and wait for the user to perform specific tasks.  Each LabRPS command has a unique name, that appears in the &lt;a href=&quot;/Category:Command_Reference&quot; title=&quot;Category:Command Reference&quot;&gt;:Category:Command Reference&lt;/a&gt; page. Commands can be launched by a toolbar button, a menu item, or from a Python|...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Introduction== &lt;br /&gt;
&lt;br /&gt;
{{TOCright}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A [[Command|command]] is what is being executed when you press a toolbar button or type a keyboard shortcut. It can be a very simple action or a complex system that will open dialog boxes and wait for the user to perform specific tasks.&lt;br /&gt;
&lt;br /&gt;
Each LabRPS command has a unique name, that appears in the [[:Category:Command_Reference|:Category:Command Reference]] page. Commands can be launched by a toolbar button, a menu item, or from a [[Python|python]] script or the [[Python_console|Python console]], by running:&lt;br /&gt;
&lt;br /&gt;
{{Code|code=&lt;br /&gt;
LabRPSGui.runCommand(&amp;quot;my_Command_Name&amp;quot;)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Background == &lt;br /&gt;
&lt;br /&gt;
LabRPS commands are defined per workbench. Workbenches will normally add their command definitions at LabRPS init time, so the command exists and is available as soon as LabRPS is started, no matter if the corresponding workbench has been activated yet or not. In some cases however, the workbench author might have decided to not overload/burden the LabRPS startup process and therefore loaded the command definitions only at workbench init. In those cases, the command will only be available after the workbench has been activated (you have switched to it at least once with the workbench selector).&lt;br /&gt;
&lt;br /&gt;
As most of them require user interaction, LabRPS commands are only available in GUI-mode, and not in console mode. However, for convenience, most LabRPS commands will either have a corresponding python function, or will execute code that is very easy to replicate in a python script and/or [[macros|macro]].&lt;br /&gt;
&lt;br /&gt;
Commands can be defined either in C++ or in Python.&lt;br /&gt;
&lt;br /&gt;
== Commands defined in C++ == &lt;br /&gt;
&lt;br /&gt;
Example of a C++ command definition, usually defined following the structure {{FileName|Mod/ModuleName/Gui/Command.cpp}}.&lt;br /&gt;
&lt;br /&gt;
{{Code|lang=cpp|code=&lt;br /&gt;
DEF_STD_CMD_A(StdCmdMyCommand);&lt;br /&gt;
&lt;br /&gt;
StdCmdMyCommand::StdCmdMyCommand()&lt;br /&gt;
  : Command(&amp;quot;Std_My_Command&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
    sGroup        = QT_TR_NOOP(&amp;quot;File&amp;quot;);&lt;br /&gt;
    sMenuText     = QT_TR_NOOP(&amp;quot;My Command&amp;quot;);&lt;br /&gt;
    sToolTipText  = QT_TR_NOOP(&amp;quot;Runs my command in the active document&amp;quot;);&lt;br /&gt;
    sWhatsThis    = &amp;quot;Std_MyCommand&amp;quot;;&lt;br /&gt;
    sStatusTip    = QT_TR_NOOP(&amp;quot;Runs my command in the active document&amp;quot;);&lt;br /&gt;
    sPixmap       = &amp;quot;MyCommand.svg&amp;quot;;&lt;br /&gt;
    sAccel        = &amp;quot;Ctrl+A&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void StdCmdExport::activated(int iMsg)&lt;br /&gt;
{&lt;br /&gt;
    // place here the code to be executed when the command is ran&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
bool StdCmdMyCommand::isActive(void)&lt;br /&gt;
{&lt;br /&gt;
    // here you have a chance to return true or false depending if your command must be shown as active or inactive (greyed).&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// the command must be &amp;quot;registered&amp;quot; in LabRPS&amp;#039;s command system&lt;br /&gt;
CommandManager &amp;amp;rcCmdMgr = Application::Instance-&amp;gt;commandManager();&lt;br /&gt;
rcCmdMgr.addCommand(new StdCmdMyCommand());&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Commands defined in Python == &lt;br /&gt;
&lt;br /&gt;
Example of a Python command definition, it can be placed in a directory like {{FileName|Mod/ModuleName/tools/commands.py}}.&lt;br /&gt;
{{Code|code=&lt;br /&gt;
from PySide.QtCore import QT_TRANSLATE_NOOP&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyCommand:&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;Explanation of the command.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Initialize variables for the command that must exist at all times.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
    def GetResources(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Return a dictionary with data that will be used by the button or menu item.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return {&amp;#039;Pixmap&amp;#039;: &amp;#039;MyCommand.svg&amp;#039;,&lt;br /&gt;
                &amp;#039;Accel&amp;#039;: &amp;quot;Ctrl+A&amp;quot;,&lt;br /&gt;
                &amp;#039;MenuText&amp;#039;: QT_TRANSLATE_NOOP(&amp;quot;My_Command&amp;quot;, &amp;quot;My Command&amp;quot;),&lt;br /&gt;
                &amp;#039;ToolTip&amp;#039;: QT_TRANSLATE_NOOP(&amp;quot;My_Command&amp;quot;, &amp;quot;Runs my command in the active document&amp;quot;)}&lt;br /&gt;
&lt;br /&gt;
    def Activated(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Run the following code when the command is activated (button press).&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        print(&amp;quot;Activated&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    def IsActive(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Return True when the command should be active or False when it should be disabled (greyed).&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return True&lt;br /&gt;
&lt;br /&gt;
# The command must be &amp;quot;registered&amp;quot; with a unique name by calling its class.&lt;br /&gt;
LabRPSGui.addCommand(&amp;#039;My_Command&amp;#039;, MyCommand())&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{Powerdocnavi}}&lt;br /&gt;
[[Category:Developer Documentation]]&lt;br /&gt;
[[Category:Python Code]]&lt;br /&gt;
[[Category:Glossary]]&lt;/div&gt;</summary>
		<author><name>LabRPS</name></author>
	</entry>
</feed>