Conventions¶
Docstring¶
Following a consistent docstring format is recommended for other users to understand more about the code.
Google Docstring:
"""
Title
Description
Args:
input (type) : input description
Returns:
output (type) : output description
References:
Some source or reference links.
Help:
remarks content
TODO and Additional Sections (See Napoleon readthedocs)
"""
Note
Docstring also applies to GHPython component, the docstring is used to assign tooltips for the component
Help section appears on GHPython Help content.
References:
Workflow¶
Workflow script is a sequence of operations which process a predefined Input and generate a specific result Output.
All generic workflow scripts should be placed in Tools.
All project specific scripts should be placed in their corresponding Code folder per project.
Template:
1 2 3 4 5 6 7 8 9 10 11 | import armacode
def main(x, y):
"""
Docstring
"""
result = x + y
return result
if __name__ == "__main__":
main()
|
Note
All workflow should be defined in a main() function and call it safely using if __name__ == "__main__":
Command¶
A python script can be used as a Rhino Command.
Workflow that are stable has been fully tested and working as intended should be turned into a command for easy execution.
Command python files are named with a suffix _cmd.py. All commands are stored in the Plug-in folder.
Create a command:
- Open Python script editor using
EditPythonScript - File > New > Command
- Select the AR-MA plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import armacode
import rhinoscriptsyntax as rs
import Rhino
__commandname__ = "CommandName"
# RunCommand is the called when the user enters the command name in Rhino.
# The command name is defined by the filname minus "_cmd.py"
def RunCommand( is_interactive=True ):
print "Hello", __commandname__
# get a point
point = rhinoscript.userinterface.GetPoint()
if( point != None ):
rhinoscript.geometry.AddPoint(point)
# you can optionally return a value from this function
# to signify command result. Return values that make
# sense are
# 0 == success
# 1 == cancel
# If this function does not return a value, success is assumed
return 0
if __name__ == "__main__":
RunCommand()
|