Command/ru: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 1: Line 1:
<languages/>
<languages/>
==Introduction==

{{TOCright}}

<div class="mw-translate-fuzzy">
Команда FreeCAD - это то, что выполняется, когда вы нажимаете кнопку на панели инструментов или набираете комбинацию клавиш. Это может быть очень простое действие, например изменение уровня масштабирования 3D-вида или поворот точки зрения или сложная система, которая откроет диалоговые окна и дождитесь, когда пользователь выполнит определенные задачи.
Команда FreeCAD - это то, что выполняется, когда вы нажимаете кнопку на панели инструментов или набираете комбинацию клавиш. Это может быть очень простое действие, например изменение уровня масштабирования 3D-вида или поворот точки зрения или сложная система, которая откроет диалоговые окна и дождитесь, когда пользователь выполнит определенные задачи.
</div>


<div class="mw-translate-fuzzy">
Каждая команда FreeCAD имеет уникальное имя, которое появляется на странице [[:Category:Command_Reference]]. Команды могут запускаться с помощью кнопки панели инструментов, элемента меню или скрипта python или консоли python, запустив:
Каждая команда FreeCAD имеет уникальное имя, которое появляется на странице [[:Category:Command_Reference]]. Команды могут запускаться с помощью кнопки панели инструментов, элемента меню или скрипта python или консоли python, запустив:
</div>


FreeCADGui.runCommand("my_Command_Name")
FreeCADGui.runCommand("my_Command_Name")


== Background ==
FreeCAD commands are defined per workbench. Workbenches will normally add their command definitions at FreeCAD init time, so the command exists and is available as soon as FreeCAD 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 too much the FreeCAD startup process, to load 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).


FreeCAD commands are defined per workbench. Workbenches will normally add their command definitions at FreeCAD init time, so the command exists and is available as soon as FreeCAD 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 FreeCAD 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).
As most of them require user interaction, FreeCAD commands are only available in GUI-mode, and not in console mode. However, for convenience, most FreeCAD commands will either have a corresponding python function (like Part.makeBox or Draft.makeLine), or will execute code that is very easy to replicate in a python script.

As most of them require user interaction, FreeCAD commands are only available in GUI-mode, and not in console mode. However, for convenience, most FreeCAD commands will either have a corresponding python function (like {{incode|Part.makeBox}} or {{incode|Draft.makeLine}}), or will execute code that is very easy to replicate in a python script and/or [[macros|macro]].


Commands can be defined either in C++ or in Python.
Commands can be defined either in C++ or in Python.


== Example ==
Example of a C++ command definition (usually defined in /Mod/ModuleName/Gui/Command.cpp):

Example of a C++ command definition (usually defined in {{FileName|/Mod/ModuleName/Gui/Command.cpp}}):
{{Code|code=
{{Code|code=
DEF_STD_CMD_A(StdCmdMyCommand);
DEF_STD_CMD_A(StdCmdMyCommand);
Line 66: Line 78:
}}
}}


{{Userdocnavi{{#translation:}}}} <!-- Anything below this line must come after a closing translate tag -->

[[Category:User Documentation{{#translation:}}]]
[[Category:Developer Documentation{{#translation:}}]]
[[Category:Developer Documentation{{#translation:}}]]
[[Category:Command Reference{{#translation:}}]]
[[Category:Command Reference{{#translation:}}]]
{{Category:Glossary{{#translation:}}}}

Revision as of 16:00, 22 February 2020

Introduction

Команда FreeCAD - это то, что выполняется, когда вы нажимаете кнопку на панели инструментов или набираете комбинацию клавиш. Это может быть очень простое действие, например изменение уровня масштабирования 3D-вида или поворот точки зрения или сложная система, которая откроет диалоговые окна и дождитесь, когда пользователь выполнит определенные задачи.

Каждая команда FreeCAD имеет уникальное имя, которое появляется на странице Category:Command_Reference. Команды могут запускаться с помощью кнопки панели инструментов, элемента меню или скрипта python или консоли python, запустив:

FreeCADGui.runCommand("my_Command_Name")

Background

FreeCAD commands are defined per workbench. Workbenches will normally add their command definitions at FreeCAD init time, so the command exists and is available as soon as FreeCAD 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 FreeCAD 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).

As most of them require user interaction, FreeCAD commands are only available in GUI-mode, and not in console mode. However, for convenience, most FreeCAD commands will either have a corresponding python function (like Part.makeBox or Draft.makeLine), or will execute code that is very easy to replicate in a python script and/or macro.

Commands can be defined either in C++ or in Python.

Example

Example of a C++ command definition (usually defined in /Mod/ModuleName/Gui/Command.cpp):

DEF_STD_CMD_A(StdCmdMyCommand);

StdCmdMyCommand::StdCmdMyCommand()
  : Command("Std_My_Command")
{
    sGroup        = QT_TR_NOOP("File");
    sMenuText     = QT_TR_NOOP("My Command");
    sToolTipText  = QT_TR_NOOP("Runs my command in the active document");
    sWhatsThis    = "Std_MyCommand";
    sStatusTip    = QT_TR_NOOP("Runs my command in the active document");
    sPixmap       = "MyCommand.svg";
    sAccel        = "Ctrl+A";
}

void StdCmdExport::activated(int iMsg)
{
    // place here the code to be executed when the command is ran
}

bool StdCmdMyCommand::isActive(void)
{
    // here you have a chance to return true or false depending if your command must be shown as active or inactive (greyed).
}

// the command must be "registered" in FreeCAD's command system
CommandManager &rcCmdMgr = Application::Instance->commandManager();
rcCmdMgr.addCommand(new StdCmdMyCommand());

and a similar command in python (no rule for where it must be done, each python workbench does as it sees fit...)

class MyCommand:

    def __init__(self):
        # you can add things here like defining some variables that must exist at all times

    def GetResources(self):
        return {'Pixmap'  : 'MyCommand.svg',
                    'Accel' : "Ctrl+A",
                    'MenuText': QtCore.QT_TRANSLATE_NOOP("My_Command", "My Command"),
                   'ToolTip': QtCore.QT_TRANSLATE_NOOP("My_Command", "Runs my command in the active document")}

    def Activated(self):
        # place here the code to be executed when the command is ran

    def isActive(self):
        # here you have a chance to return True or False depending if your command must be shown as active or inactive (greyed).

# the command must be "registered" in FreeCAD's command system
FreeCADGui.addCommand('My_Command',MyCommand())

Эта категория отслеживает страницы, полученные переводом на русский язык понятий, относящихся к FreeCAD. Англоязычные оригиналы, в том числе ещё не переведённые, надо искать на странице.