rhinoscriptsyntax

repository·rhino-8.x·Indexed 42 days ago

https://github.com/mcneel/rhinoscriptsyntax

A Python wrapper for the Rhino command engine. This documentation specifies the docstring standards used for API help and documentation generation, including formatting for parameters, return values, and self-contained code examples.

Tokens
1.7K
Snippets
3
Records
5
Agent score
4%

What's inside rhinoscriptsyntax

  1. Understand the RhinoScriptSyntax Docstring Format

    rhino-8.x

    The rhinoscriptsyntax library uses a specific docstring format to generate context help in the editor and API documentation. The format is inspired by PEP 257, PEP 216, and Google Style Docstrings.

    Key sections used in a standard docstring include:

    • Delimiters: Uses triple quotes """ to start and end the docstring.
    • Description: A short summary of the function. Multi-line descriptions must have the second line and subsequent lines indented by two spaces.
    • Parameters: A section starting with Parameters: describing input arguments.
    • Returns: A section starting with Returns: describing the output.
    • Example: A section starting with Example: containing functional, self-contained code.
    • See Also: A section listing related functions.
  2. Create self-contained docstring examples

    rhino-8.x

    The Example: section should provide code that is functional and can be copied and pasted into an empty script to run immediately.

    Requirements for Examples:

    1. Must be self-contained.
    2. Must include the import rhinoscriptsyntax as rs line.
    3. Must not require external .3dm files or support files.
    4. Should demonstrate the use of optional arguments if applicable.
    def AliasMacro(alias, macro=None):
        """Returns or modifies the macro of a command alias.
        Parameters:
          alias (str): The name of an existing command alias.
          macro (str, optional): The new macro to run when the alias is executed. If omitted, the current alias macro is returned.
        Returns:
          str:  If a new macro is not specified, the existing macro if successful.
          str:  If a new macro is specified, the previous macro if successful.
          null:  None on error
        Example:
          import rhinoscriptsyntax as rs
          aliases = rs.AliasNames()
          for alias in aliases:
              print("{}
     -> {}".format(alias, rs.AliasMacro(alias)))
        See Also:
          AddAlias
          AliasCount
          AliasNames
          DeleteAlias
          IsAlias
        """
        # implementation...
  3. Define function parameters in docstrings

    rhino-8.x

    The Parameters: section describes the input arguments. Each parameter line follows the pattern: variable_name (type): description.

    Type Notation Rules:

    • Simple type: alias (str): description
    • List of same type (unlimited): alias ([str, ...]): description
    • List of different types: alias ([str, number, bool]): description
    • Nested lists: alias ([str, [number, number], bool]): description
    • Type OR (Pipe): alias (str|guid): description
    • Optional parameters: Add , optional to the type and explain the default behavior (e.g., alias (str, optional): description. If omitted, None is returned.)
    # Examples of parameter syntax
    alias (str): The name of an existing command alias.
    alias ([str, ...]): The name of an existing command alias.
    alias ([str, number, bool]): list of an existing command alias.
    alias ([str, [number, number], bool]): list of values for command alias.
    alias (str|guid): The name or guid identifier of an existing command alias.
    alias (str, optional): The name of an existing command alias. If omitted, None is returned.
  4. Use RhinoScriptSyntax variable type abbreviations

    rhino-8.x

    When writing docstrings for rhinoscriptsyntax, use the following abbreviations for variable types to maintain consistency with the library's documentation style:

    AbbreviationTypes
    numberfloat, integer, long
    strstring
    boolboolean
    listlist
    tupletuple
    guiduuid, object identifier
    pointrhino.geometry.point3d
    planerhino.geometry.plane3d
    linerhino.geometry.line
    colorsystem.drawing.color
  5. Define return values in docstrings

    rhino-8.x

    The Returns: section describes what the function outputs. Even if a function returns None, it must be explicitly listed.

    Return Notation Rules:

    • Simple type: str: description
    • List of same type: list(str, ...): description
    • List of different types: list(str, number, bool): description
    • Multiple return types: Use separate lines for different conditions:
      str: The name of an existing command alias.
      number: If no argument, returns number of aliases.
      None: If not successful
    • Numeric codes: If a number refers to a specific state, list them:
      1 = counter clockwise
      0 = stationary
      -1 = clockwise
    • Index numbers: If a number refers to a specific index in a returned collection:
      [0] point for origin
      [1] area of surface
    # Examples of return syntax
    Returns:
        None
    
    str: The name of an existing command alias.
    list(str, ...): A list of alias.
    list(str, number, bool): Various information about command alias.
    
    # Multiple return values
    str: The name of an existing command alias.
    number: If no argument, returns number of aliases.
    None: If not successful
    
    # Numeric codes
    1 = counter clockwise
    0 = stationary
    -1 = clockwise
    
    # Index numbers
    [0] point for origin
    [1] area of surface
    [2] point of center