vcCommand

Object type for commands that can be executed using Python API and made available in user interface of application.

See in: Overview

Module: vcCore

Parent: vcObject

Children -

Referenced by: vcCore.getCommand()

Properties

Learn how to use properties here. The properties are also inherited from the parent class.

Name Type Access Description
Commands vcList R Gets the list of Python 3 commands.
FilePath String R Gets the source file path.
FolderPath Path R Gets the source folder path.
IsEnabled Boolean RW Gets or sets the flag defining if the command is enabled in the user interface.
Name String RW Gets or sets command's name
Properties vcPropertyContainer R Gets the properties of this command.

Methods

Learn how to use methods here. The methods are also inherited from the parent class.

Name Return Type Parameters Description
addMenuItem None String menuName,
String caption,
Optional Keyword[position = Integer],
Optional Keyword[tooltip = String],
Optional Keyword[iconPath = String],
Optional Keyword[referenceId = String],
Optional Keyword[controlType = vcMenuTool]
Adds this command to a menu.
See more
Parameters:
menuName (String): Target menu name.
caption (String): A caption to display.
Optional: position (Integer): Where the menu item will be added in the given menu.
Any value less than zero is indexed from the end of the menu. By default, a new menu item is appended to the end of a menu.
Optional: tooltip (String): A tooltip text to display.
Optional: iconPath (String): An icon to display. This can either be an absolute path or relative to "Icons" folder in the installation directory.
Optional: referenceId (String): Refers to another menu item by its command name or id. Generally, you would use this to add items to a gallery menu on the Ribbon in which both the gallery and its items are created using the same Python command.
Optional: controlType (vcMenuTool): Specifies the control type of the menu item.

Exceptions:
RuntimeError: When the command has no name set or name is not unique.

See menuName's
createCommand vcCommand String filePath Creates a new Python 3 command from a given file path.
See more
Parameters:
commandPath (String): Command file path.

Exceptions:
RuntimeError: When failing to read the file from the given path.

Returns:
vcCommand: Created command.
execute None None Calls 'OnExecute' function on this command.
findCommand vcCommand String arg Finds a Python 3 command with a given name.
See more
Parameters:
name (String): Command name.

Returns:
vcCommand: Command if found, None otherwise.

Note: Python 3 API features improved support for commands. A command is now initialized and represented by a single file, removing the need for the separate __init__.py file that was required by the Python 2 API. For more information on the elements defined in this example refer to How to use - vcCommands.

Example: Simple Command Template

""" Template for a simple command with no property panel."""
import vcCore as vc
app = vc.getApplication()
cmd = vc.getCommand()
def OnInit():
  # Executed only once at init
  cmd.Name = "Py3Test"
  cmd.addMenuItem('VcTabHome/Python3', "Py3Test")
  
def OnExecute():
  print('Py3Test')

Example: Command with Panel

""" Template for a command with a property panel with one custom property and 'Apply' & 'Close' buttons."""
import vcCore as vc
app = vc.getApplication()
cmd = vc.getCommand()
def OnInit():
  # Executed only once at init
  cmd.Name = "Py3PanelTest"
  cmd.addMenuItem('VcTabHome/Python3', "Py3PanelTest")
def OnExecute():
  panel.showCommand(cmd)
def on_cancel():
  print ("Canceled.")
def on_apply():
  print('Apply')
  return True
def on_close():
  print("Close")
  return True
def on_prop_changed(args):
  print('New value for S1: ' + prop_s1.Value)
prop_s1 = cmd.Properties['S1']
if prop_s1 == None:
  prop_s1 = cmd.Properties.create(vc.vcPropertyType.STRING, 'S1')
prop_s1.OnChanged += on_prop_changed
panel = vc.vcCommandPanel.new()
panel.Title = "Python 3 Panel Test"
panel.setOnCancel(on_cancel)
btnApply = panel.createButton("Apply", on_apply)
btnApply.IsEnabled = True
btnClose = panel.createButton("Close", on_close)
btnClose.IsEnabled = True

Example: Add Icon to Command

"""
Adding an icon ('MyCommandIcon.svg') to a command.
"""
def OnInit():
  cmd.Name = 'My_Command'
  my_icon_path = os.path.join(cmd.FolderPath, 'MyCommandIcon.svg')
  cmd.addMenuItem('VcTabHome/MyCommandGroup','My_Command', iconPath = my_icon_path)