5.应用程序s¶
RoboDK Apps (or Add-ins) allow you to extend RoboDK features and customize the look of RoboDK. Any application or script can be easily converted to a RoboDK Add-in to automate certain tasks, perform specific actions or facilitate a user’s workflow.
You can integrate scripts as part of the RoboDK user interface and easily customize RoboDK for customized offline programming and simulation purposes. Adding scripts to an App will add buttons in the menu and the toolbar automatically.
A settings file allows you to easily customize the appearance of a specific set of buttons/actions. A readme.md file allows you to publishing the app to the RoboDK Add-in marketplace://www.sinclairbody.com/addins.
Once you complete developing your App you can easily distribute your App as a self-contained package file (rdkp file).
应用程序s are handled by RoboDK with the AppLoader Add-in, androboappsprovides the necessary Python tools to build your App.
- You can find more information about the AppLoader in our GitHub:
- You can find sample Apps in our GitHub:
5.1.应用程序Template¶
This App example provides the necessary examples to build a RoboDK App. It can be used as a template to build your own RoboDK Apps. Note that
- Please visit our GitHub to get the complete App:
5.1.1.Actions¶
The most common action type is the momentary action (on click). It is useful to run on-demand scripts.
# --------------------------------------------# --------------- DESCRIPTION ----------------## Momentary action example.## More information about the RoboDK API for Python here:# //www.sinclairbody.com/doc/en/RoboDK-API.html# //www.sinclairbody.com/doc/en/PythonAPI/index.html## More information on RoboDK Apps here:# https://github.com/RoboDK/Plug-In-Interface/tree/master/PluginAppLoader## --------------------------------------------fromrobodkimportrobolink,roboappsfrom_AppUtilitiesimportShowMessageimportosACTION_NAME=os.path.basename(__file__)defActionMomentary():"""Action to perform when the action is clicked in RoboDK."""RDK=robolink.Robolink()ShowMessage(RDK,ACTION_NAME,"Clicked!",True)defrunmain():"""Entrypoint of this action when it is executed on its own or interacted with in RoboDK.Important: Use the function name 'runmain()' if you want to compile this action.Example for a 'Checkable Action':.. code-block:: pythondefrunmain():if roboapps.Unchecked():ActionUnchecked()else:roboapps.SkipKill() # Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()Example for a 'Momentary Action':.. code-block:: pythondefrunmain():if roboapps.Unchecked():roboapps.Exit() # or sys.exit()else:roboapps.SkipKill() # Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()Example for a 'Checkable Option':.. code-block:: pythondefrunmain():if roboapps.Unchecked():ActionUnchecked()else:roboapps.KeepChecked() # Important, prevents RoboDK from unchecking the action after it has completedActionChecked()"""ifroboapps.Unchecked():roboapps.Exit()else:ActionMomentary()if__name__=='__main__':runmain()
支票的操作(切换)is useful for running continuous scripts.
# --------------------------------------------# --------------- DESCRIPTION ----------------## Checkable action example.## The main icon for this action is automatically loaded as it shares the same name (ActionCheckable[.py, .svg]).# The checked icon loaded as it is suffixed with 'Checked'.## More information about the RoboDK API for Python here:# //www.sinclairbody.com/doc/en/RoboDK-API.html# //www.sinclairbody.com/doc/en/PythonAPI/index.html## More information on RoboDK Apps here:# https://github.com/RoboDK/Plug-In-Interface/tree/master/PluginAppLoader## --------------------------------------------fromrobodkimportrobolink,robomath,roboappsfrom_AppUtilitiesimportShowMessageimportosACTION_NAME=os.path.basename(__file__)defActionChecked():"""Action to perform when the action is checked in RoboDK."""RDK=robolink.Robolink()应用程序=roboapps.RunApplication()ShowMessage(RDK,ACTION_NAME,"Checked! Waiting to be unchecked..",True)i=0while应用程序.Run():ShowMessage(RDK,ACTION_NAME,"Checked Status.. "+str(i),False)robomath.pause(0.25)i+=1# This will not be called if SkipKill() is not presentrobomath.pause(3)ShowMessage(RDK,ACTION_NAME,"Unchecked! This is a post-run message (SkipKill). Closing..",True)defActionUnchecked():"""Action to perform when the action is unchecked in RoboDK."""# It is not recommended to use APP.Run() in the Unchecked state!RDK=robolink.Robolink()ShowMessage(RDK,ACTION_NAME,"Unchecked!",True)returndefrunmain():"""Entrypoint of this action when it is executed on its own or interacted with in RoboDK.Important: Use the function name 'runmain()' if you want to compile this action.Example for a 'Checkable Action':.. code-block:: pythondefrunmain():if roboapps.Unchecked():ActionUnchecked()else:roboapps.SkipKill() # Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()Example for a 'Momentary Action':.. code-block:: pythondefrunmain():if roboapps.Unchecked():roboapps.Exit() # or sys.exit()else:roboapps.SkipKill() # Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()Example for a 'Checkable Option':.. code-block:: pythondefrunmain():if roboapps.Unchecked():ActionUnchecked()else:roboapps.KeepChecked() # Important, prevents RoboDK from unchecking the action after it has completedActionChecked()"""ifroboapps.Unchecked():ActionUnchecked()else:roboapps.SkipKill()# Comment this line to have RoboDK kill the process after 2 seconds (if it still runs)ActionChecked()if__name__=='__main__':runmain()
The contextual action (right-click menu) has the same capabilities has the momentary and checkable actions, but is bound to user selection. It is useful to perform actions on specific items.
# --------------------------------------------# --------------- DESCRIPTION ----------------## Context action example (right-click a tree item of a specific type).## More information about the RoboDK API for Python here:# //www.sinclairbody.com/doc/en/RoboDK-API.html# //www.sinclairbody.com/doc/en/PythonAPI/index.html## More information on RoboDK Apps here:# https://github.com/RoboDK/Plug-In-Interface/tree/master/PluginAppLoader## --------------------------------------------fromrobodkimportrobolink,roboappsfrom_AppUtilitiesimportShowMessageimportosACTION_NAME=os.path.basename(__file__)defOnContextAction():"""Action to perform when the action is clicked in RoboDK."""RDK=robolink.Robolink()selected_items=RDK.Selection()ifnotselected_items:ShowMessage(RDK,ACTION_NAME,"Nothing selected!",True)returnnames=[x.Name()forxinselected_items]ShowMessage(RDK,ACTION_NAME,'User selected '+', '.join(names)+'.',True)defrunmain():"""Entrypoint of this action when it is executed on its own or interacted with in RoboDK.Important: Use the function name 'runmain()' if you want to compile this action.Example for a 'Checkable Action':.. code-block:: pythondefrunmain():if roboapps.Unchecked():ActionUnchecked()else:roboapps.SkipKill() # Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()Example for a 'Momentary Action':.. code-block:: pythondefrunmain():if roboapps.Unchecked():roboapps.Exit() # or sys.exit()else:roboapps.SkipKill() # Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()Example for a 'Checkable Option':.. code-block:: pythondefrunmain():if roboapps.Unchecked():ActionUnchecked()else:roboapps.KeepChecked() # Important, prevents RoboDK from unchecking the action after it has completedActionChecked()"""ifroboapps.Unchecked():roboapps.Exit()else:OnContextAction()if__name__=='__main__':runmain()
5.1.2.Options¶
The checkable option (toggle) is useful to provide status to the user. You can also group options, so that they are mutually exclusive.
# --------------------------------------------# --------------- DESCRIPTION ----------------## Checkable option example.## More information about the RoboDK API for Python here:# //www.sinclairbody.com/doc/en/RoboDK-API.html# //www.sinclairbody.com/doc/en/PythonAPI/index.html## More information on RoboDK Apps here:# https://github.com/RoboDK/Plug-In-Interface/tree/master/PluginAppLoader## --------------------------------------------fromrobodkimportrobolink,roboappsfrom_AppUtilitiesimportShowMessagefrom应用程序SettingsimportSettingsimportosACTION_NAME=os.path.basename(__file__)defActionChecked():"""Action to perform when the action is checked in RoboDK."""RDK=robolink.Robolink()S=Settings()S.Load(RDK)RDK.setParam(S.应用程序_OPTION_KEY,1.0)ShowMessage(RDK,ACTION_NAME,str(RDK.getParam(S.应用程序_OPTION_KEY)),False)defActionUnchecked():"""Action to perform when the action is unchecked in RoboDK."""RDK=robolink.Robolink()S=Settings()S.Load(RDK)RDK.setParam(S.应用程序_OPTION_KEY,0.0)ShowMessage(RDK,ACTION_NAME,str(RDK.getParam(S.应用程序_OPTION_KEY)),False)defrunmain():"""Entrypoint of this action when it is executed on its own or interacted with in RoboDK.Important: Use the function name 'runmain()' if you want to compile this action.Example for a 'Checkable Action':.. code-block:: pythondefrunmain():if roboapps.Unchecked():ActionUnchecked()else:roboapps.SkipKill() # Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()Example for a 'Momentary Action':.. code-block:: pythondefrunmain():if roboapps.Unchecked():roboapps.Exit() # or sys.exit()else:roboapps.SkipKill() # Optional, prevents RoboDK from force-killing the action after 2 secondsActionChecked()Example for a 'Checkable Option':.. code-block:: pythondefrunmain():if roboapps.Unchecked():ActionUnchecked()else:roboapps.KeepChecked() # Important, prevents RoboDK from unchecking the action after it has completedActionChecked()"""ifroboapps.Unchecked():ActionUnchecked()else:roboapps.KeepChecked()ActionChecked()if__name__=='__main__':runmain()
5.1.3.配置¶
A configuration is needed to determine the action type, names, description, etc.
[General]MenuName=应用程序ExampleMenuParent=MenuPriority=50MenuVisible=trueToolbarArea=2ToolbarSizeRatio=1.5RunCommands=Version=1.0.0[ActionCheckable]DisplayName=CheckableActionDescription=CheckableactionexampleVisible=trueShortcut=Checkable=trueCheckableGroup=-1AddToToolbar=truePriority=10TypeOnContextMenu=TypeOnDoubleClick=DeveloperOnly=falseAddToMenu=true[ActionMomentary]DisplayName=MomentaryActionDescription=MomentaryactionexampleVisible=trueShortcut=Checkable=falseCheckableGroup=-1AddToToolbar=truePriority=20TypeOnContextMenu=TypeOnDoubleClick=DeveloperOnly=falseAddToMenu=true[ActionOnContext]DisplayName=ContextualActionDescription=ContextualactionexampleVisible=trueShortcut=Checkable=falseCheckableGroup=-1AddToToolbar=falsePriority=30TypeOnContextMenu=-1TypeOnDoubleClick=DeveloperOnly=falseAddToMenu=true[ActionOnDoubleClick]DisplayName=Double-ClickActionDescription=DoubleclickactionexampleVisible=trueShortcut=Checkable=falseCheckableGroup=-1AddToToolbar=falsePriority=31TypeOnContextMenu=TypeOnDoubleClick=-1DeveloperOnly=falseAddToMenu=true[OptionCheckable]DisplayName=CheckableOptionDescription=CheckableoptionexampleVisible=trueShortcut=Checkable=trueCheckableGroup=-1AddToToolbar=falsePriority=40TypeOnContextMenu=TypeOnDoubleClick=DeveloperOnly=falseAddToMenu=true[OptionCheckableGroupA]DisplayName=CheckableOption(Group)ADescription=Checkableoption(group)AexampleVisible=trueShortcut=Checkable=trueCheckableGroup=1AddToToolbar=falsePriority=50TypeOnContextMenu=TypeOnDoubleClick=DeveloperOnly=falseAddToMenu=true[OptionCheckableGroupB]DisplayName=CheckableOption(Group)BDescription=Checkablepption(group)BexampleVisible=trueShortcut=Checkable=trueCheckableGroup=1AddToToolbar=falsePriority=51TypeOnContextMenu=TypeOnDoubleClick=DeveloperOnly=falseAddToMenu=true[应用程序Settings]DisplayName=SettingsDescription=EdittheexamplesettingsVisible=trueShortcut=Checkable=falseCheckableGroup=1AddToToolbar=falsePriority=100TypeOnContextMenu=TypeOnDoubleClick=DeveloperOnly=falseAddToMenu=true