Universal Robots TypeScript API - v10.12.0
    Preparing search index...

    ScriptBuilder provides methods to easily generate well indented UR script programmatically. This class manages indentation automatically as the script is built step by step. But,it does not guarantee perfect formatting as there is a possibility to pass badly formatted expressions, statements or scripts.

    Index

    Constructors

    • Creates a new ScriptBuilder

      Parameters

      • Optionalscript: string

        If a script is specified, the new ScriptBuilder will be preloaded with that script

      • OptionalinitialIndent: number

        If an indent is specified, the ScriptBuilder will be initialized with that indent

      Returns ScriptBuilder

    Properties

    type: "$$ScriptBuilder"
    SINGLE_INDENT: " "
    SINGLE_INDENT_LEVEL: 1

    Methods

    • Add a frame with the name 'name' initialized at the specified pose expressed in the refFrame coordinate frame. This command only adds a frame to the world, it does not attach it to the ref_frame coordinate frame. Use attach_frame() to attach the newly added frame to ref_frame if desired.

      Parameters

      • name: string

        name of the frame to be added. The name must not be the same as any existing world model object (frame, axis, or axis group), otherwise an exception is thrown

      • pose: ControllerPose

        initial pose of the new object or string expression

      Returns ScriptBuilder

    • Add a frame with the name 'name' initialized at the specified pose expressed in the refFrame coordinate frame.

      Parameters

      • name: string
      • poseOrExpression: string | Pose
      • OptionalrefFrame: string

      Returns ScriptBuilder

    • Add raw script code. As this method takes raw script code that may not be indented and appends it without indenting it, it may violate the overall indentation.

      Parameters

      • script: string

        The script to be appended

      Returns ScriptBuilder

      this object.

    • Add a block of statements to the builder.

      Parameters

      • statements: string

        A block of statements as a String.

      Returns ScriptBuilder

      this object.

    • Append the content of another script builder to this script builder

      Parameters

      Returns ScriptBuilder

    • Add a statement that assigns an expression to a variable.

      Parameters

      • name: string

        The name of the variable.

      • expression: string

        The expression to be assigned to the variable.

      Returns ScriptBuilder

      this object.

    • Attaches the child frame to the parent world model object. The relative transform between the parent and child will be set such that the child does not move in the world when the attachment occurs. The child cannot be "world", "tcp", or the same as parent. This will fail if child or parent is not an existing frame, or this makes the attachments form a closed chain.

      Parameters

      • child: string

        name of the frame to be attached. The name must not be "world" or "tcp".

      • parent: string

        name of the object that the child frame will be attached to.

      Returns ScriptBuilder

    • Add a while statement with a given expression. This is unbalanced, it has to be balanced by a call to #end() at the appropriate time.

      Parameters

      • expression: string

        The string representation of an expression.

      Returns ScriptBuilder

      this object.

    • Add a while not statement with a given expression. This is unbalanced, it has to be balanced by a call to #end() at the appropriate time.

      Parameters

      • expression: string

        The string representation of an expression.

      Returns ScriptBuilder

      this object.

    • Add a while statement that loops forever. This is unbalanced, it has to be balanced by a call to #end() at the appropriate time.

      Returns ScriptBuilder

      this object.

    • Returns ScriptBuilder

      this object.

      Insert a break statement.

    • Add a comment in the script.

      Parameters

      • text: string

        The comment text.

      Returns ScriptBuilder

      this object.

    • Decrease the indent.

      Parameters

      • Optionallevel: number

      Returns void

    • Add a function definition with the given name and parameters. This is unbalanced, it has to be balanced by a call to #end() at the appropriate time.

      Parameters

      • name: string

        The name of the function.

      • ...params: string[]

        The parameters of the function.

      Returns ScriptBuilder

      this object.

    • Add a thread definition with given the threadName. This is unbalanced, it has to be balanced by a call to #end() at the appropriate time.

      Parameters

      • threadName: string

        The threadName of the thread.

      Returns ScriptBuilder

      this object.

    • Delete the frame named frame from the world model. The "world", "base", and "tcp" frames cannot be deleted. Any frames that are attached to the deleted frame will be attached to the "world" frame with new frame offsets set such that the detached frame does not move in the world. This command will fail if the frame does not exist.

      Parameters

      • name: string

        name of the frame to be deleted

      Returns ScriptBuilder

    • Add an else statement. This is unbalanced, it has to be balanced by a call to #end() at the appropriate time.

      Returns ScriptBuilder

      this object.

    • Add an else if statement with a given expression. This is unbalanced, it has to be balanced by a call to #elseIfCondition(String) or #elseIfCondition(Script) or #else() or #end() at the appropriate time.

      Parameters

      • expression: string

        The expression that the else if statement branches on.

      Returns ScriptBuilder

      this object.

    • Add the end keyword that balances/terminates the declaration of functions, branch and loop statements.

      Returns ScriptBuilder

      this object.

    • End a block, without an end statement Used by if and elseif

      Returns ScriptBuilder

      this object.

    • Get the current indention level of this ScriptBuilder.

      Returns number

      the indention level as a number.

    • The terminal operation that generates the as string containing the UR Script.

      Returns string

      the string that contains the UR Script.

    • Add a statement that declares a global variable and assigns it an initial value.

      Parameters

      • name: string

        The name of the global variable.

      • value: string

        An expression which is the initial value of the global variable.

      Returns ScriptBuilder

      this object.

    • Add a halt statement.

      Returns ScriptBuilder

      this object.

    • Add an if statement with a given expression. This is unbalanced, it has to be balanced by a call to #elseIfCondition(String) or #else() or #end() at the appropriate time.

      Parameters

      • expression: string

        The expression that the if statement branches on.

      Returns ScriptBuilder

      this object.

    • Increase the indent.

      Parameters

      • Optionallevel: number

      Returns void

    • Add a statement that increments a variable with the given name.

      Parameters

      • name: string

        The name of the variable.

      Returns ScriptBuilder

      this object.

    • Returns ScriptBuilder

      this object.

      Use break

      Insert a break statement.

    • Add a statement to kill a thread.

      Parameters

      • threadHandle: string

        The thread threadHandle.

      Returns ScriptBuilder

      this object.

    • Add a statement that declares a local variable and assigns it an initial value.

      Parameters

      • name: string

        The name of the local variable.

      • value: string

        An expression which is the initial value of the local variable.

      Returns ScriptBuilder

      this object.

    • TCP moves on the circular arc segment from current pose, through pose_via to pose_to. Accelerates to and moves with constant tool speed v. Use the mode parameter to define the orientation interpolation.

      Parameters

      • pose_via: string | number[]

        path point (note: only position is used). Pose_via can also be specified as joint positions, then forward kinematics is used to calculate the corresponding pose as a string or number array.

      • pose_to: string | number[]

        target pose (note: only position is used in Fixed orientation mode). Pose_to can also be specified as joint positions, then forward kinematics is used to calculate the corresponding pose as a string or number array.

      • Optionalacc: string | number

        tool acceleration rad/s2 as a string or number (optional).

      • Optionalspeed: string | number

        tool speed in m/s as a string or number (optional).

      • OptionalblendRadius: string | number

        blend radius (of target pose) in m as a string or number (optional).

      • Optionalmode: string | number

        mode of circular arc move as a string or number (optional). 0: Unconstrained mode. Interpolate orientation from current pose to target pose (pose_to) 1: Fixed mode. Keep orientation constant relative to the tangent of the circular arc (starting from current pose)

      Returns ScriptBuilder

      this object.

    • Changes the placement of the coordinate frame named name to the new placement given by pose that is defined in the refFrame coordinate frame. This will fail if name is “world”, "tcp", or if the frame does not exist. Note: to move the "tcp" frame, use the set_tcp() command instead. If being used with the part positioner product, the ref_name argument can be the name of an external axis or axis group.

      Parameters

      • name: string

        the name of the frame to move

      • pose: ControllerPose

        the new placement

      Returns ScriptBuilder

    • Changes the placement of the coordinate frame named name to the new placement given by pose that is defined in the refFrame coordinate frame.

      Parameters

      • name: string
      • pose: Pose
      • OptionalrefFrame: string

      Returns ScriptBuilder

    • Add a call to the function that will Move to position (linear in joint-space).

      Parameters

      • q: string | number[]

        joint positions (q can also be specified as a pose, then inverse kinematics is used to calculate the corresponding joint positions) as a string or number array.

      • Optionalacc: string | number

        joint acceleration of leading axis in rad/s2 as a string or number.

      • Optionalspeed: string | number

        joint speed of leading axis in rad/s as a string or number (optional).

      • Optionaltime: string | number

        time in seconds as a string or number (optional).

      • OptionalblendRadius: string | number

        blend radius in m as a string or number (optional).

      Returns ScriptBuilder

      this object.

    • Add a call to the function that will Move to position (linear in tool-space).

      Parameters

      • pose: string

        target pose (pose can also be specified as joint positions, then forward kinematics is used to calculate the corresponding pose) as a string.

      • Optionalacc: string | number

        tool acceleration m/s2 as a string or number.

      • Optionalspeed: string | number

        tool speed in m/s as a string or number (optional).

      • Optionaltime: string | number

        time in seconds as a string or number (optional).

      • OptionalblendRadius: string | number

        blend radius in m as a string or number (optional).

      Returns ScriptBuilder

      this object.

    • Blend circular (in tool-space) and move linear (in tool-space) to position. Accelerates to and moves with constant tool speed v.

      Parameters

      • q: string | number[]

        joint positions (q can also be specified as a pose, then inverse kinematics is used to calculate the corresponding joint positions) as a string or number array.

      • Optionalacc: string | number

        joint acceleration of leading axis in rad/s2 as a string or number.

      • Optionalspeed: string | number

        joint speed of leading axis in rad/s as a string or number (optional).

      • OptionalblendRadius: string | number

        blend radius in m as a string or number (optional).

      Returns ScriptBuilder

      this object.

    • Add a call to the function that will Move to position (linear in joint-space), using OptiMove

      Parameters

      • q: string | number[]

        joint positions (q can also be specified as a pose, then inverse kinematics is used to calculate the corresponding joint positions) as a string or number array.

      • Optionalacc: string | number

        Joint acceleration as a fraction of what the joints are able to perform - a (0.0, 1.0] (optional).

      • Optionalspeed: string | number

        Joint speed as a fraction of how fast the joints can move during the motion - v (0.0, 1.0] (optional).

      • OptionalblendRadius: string | number

        blend radius in m as a string or number (optional).

      Returns ScriptBuilder

      this object.

    • Add a call to the function that will Move to position (linear in tool-space), using OptiMove

      Parameters

      • pose: string

        target pose (pose can also be specified as joint positions, then forward kinematics is used to calculate the corresponding pose) as a string.

      • acc: string | number

        tool acceleration m/s2 as a string or number.

      • Optionalspeed: string | number

        tool speed in m/s as a string or number (optional).

      • OptionalblendRadius: string | number

        blend radius in m as a string or number (optional).

      Returns ScriptBuilder

      this object.

    • Add a popup with the given parameters.

      Parameters

      • message: string

        The popup message.

      • title: string

        The popup title.

      • level: PopupLevel

        The popup level.

      • isBlocking: boolean

        true if its a blocking popup and false otherwise.

      Returns ScriptBuilder

      this object.

    • Request a value with the given parameters.

      Parameters

      • variableName: string

        The variable name to assign the value to

      • message: string

        The request message.

      • valueType: RequestValueType

        The type: integer, float, boolean, or string

      Returns ScriptBuilder

      this object.

    • Add a return statement.

      Returns ScriptBuilder

      this object.

    • Add a statement to run a thread with the given name and assign the thread handle to a variable.

      Parameters

      • threadHandle: string

        The variable that gets assigned the thread handle .

      • threadName: string

        The name of the thread to be started.

      Returns ScriptBuilder

      this object.

    • Changes the orientation of the frame

      Parameters

      Returns ScriptBuilder

      name to the given

      orientation.

    • Parameters

      • name: string
      • orientation: [number, number, number]

      Returns ScriptBuilder

      Use the overload that accepts zUpRotationVectorRadians directly instead

    • Set the direction of the acceleration experienced by the robot.

      Parameters

      • x: string | number

        x m/s^2

      • y: string | number

        y m/s^2

      • z: string | number

        z m/s^2

      Returns ScriptBuilder

    • Parameters

      • mass: string | number

        mass in kilograms as a Script.

      Returns ScriptBuilder

      this object.

      use setTargetPayload

      Add a call to the function that sets the mass.

    • Parameters

      • mass: string | number

        mass in kilograms as a Script.

      • cx: string | number

        CoG x offset in meters

      • cy: string | number

        CoG y offset in meters

      • cz: string | number

        CoG z offset in meters

      • Optionalinertia: [number, number, number, number, number, number]

        The payload inertia matrix in kg*m^2, elements lxx,lyy lzz, lxy, lxz, lyz

      Returns ScriptBuilder

      this object.

      use setTargetPayload

      Add a call to the function that sets the mass and CoG.

    • Declares or updates a persistent (shared) variable in URScript with the given name and value. Shared variables retain their values between program runs and are accessible globally.

      Parameters

      • name: string

        The name of the persistent variable.

      • value: string

        The initial value or expression to assign to the persistent variable.

      Returns ScriptBuilder

      This ScriptBuilder instance for chaining.

    • Parameters

      • mass: string | number

        mass in kilograms as a Script.

      • cx: string | number

        CoG x offset in meters

      • cy: string | number

        CoG y offset in meters

      • cz: string | number

        CoG z offset in meters

      • Optionalinertia: [number, number, number, number, number, number]

        The payload inertia matrix in kg*m^2, elements lxx,lyy lzz, lxy, lxz, lyz

      Returns ScriptBuilder

      this object.

      Add a call to the function that sets the mass and CoG.

    • Parameters

      • x: string | number

        x length

      • y: string | number

        y length

      • z: string | number

        z length

      • rx: string | number

        rx angle

      • ry: string | number

        ry angle

      • rz: string | number

        rz angle

      • Optionalname: string

        Name of the TCP

      Returns ScriptBuilder

      Add a call function which specifies the desired TCP

    • Add a sleep command.

      Parameters

      • seconds: string | number

        The amount of time in seconds.

      Returns ScriptBuilder

      this object.

    • Add a call to the function that will accelerate linearly in joint space and continue with constant joint speed.

      Parameters

      • qd: number[] | string[]

        array of joint speeds in rad/s.

      • jointAcceleration: string | number

        joint acceleration in rad/s2 (of leading axis)

      • time: string | number

        time in seconds before the function returns.

      Returns ScriptBuilder

      this object.

    • Add a call to the function that will accelerate linearly in Cartesian space and continue with constant tool speed.

      Parameters

      • xd: number[] | string[]

        array of tool speeds in m/s (spatial vector).

      • cartesianAcceleration: string | number

        tool position acceleration m/s2.

      • time: string | number

        time in seconds before the function returns.

      • OptionalrefFrameName: string

        name of reference frame

      Returns ScriptBuilder

      this object.

    • Add a stopj command. It decelerates joint speeds to zero.

      Parameters

      • jointAcceleration: string | number

        The joint acceleration in rad/s2.

      Returns ScriptBuilder

      this object.

    • Add a stopl command. It decelerates tool speed to zero.

      Parameters

      • toolAcceleration: string | number

        The tool acceleration in m/s2.

      Returns ScriptBuilder

      this object.

    • Add a sync command that uses up the remaining "physical" time a thread has in the current frame.

      Returns ScriptBuilder

      this object.

    • Create a ScriptBuilder preloaded with the incognito program definition. This is unbalanced, it has to be balanced by a call to #end() before calling #getScript().

      Returns ScriptBuilder

      new ScriptBuilder.

    • Create a ScriptBuilder preloaded with a secondary program definition. This is unbalanced, it has to be balanced by a call to #end() before calling #getScript().

      Parameters

      • name: string

        The name of the secondary program.

      Returns ScriptBuilder

      new ScriptBuilder.

    • Return a String representation of the input array.

      Parameters

      • input: number[] | string[] | boolean[]

        the input array.

      Returns string

      String representation of the input array.

    • Converts a variable's value to a URScript-compatible literal string based on its declared type.

      Handles proper formatting for POSE, BOOLEAN, ARRAY, and STRING types to ensure valid URScript syntax.

      • Strings like "true"/"false" are parsed to booleans when the variable type is BOOLEAN.
      • Arrays passed as comma-separated strings or raw arrays are parsed and validated for homogeneity.
      • POSE values are returned as-is within a p[...] wrapper, assuming correct formatting.
      • Returns an empty string '' for invalid or mixed-type array inputs, or if the variable type is missing.

      Parameters

      • variable: URVariable

        The URVariable object containing the variable's metadata.

      • value: string | number | boolean | number[] | string[] | boolean[] | number[][]

        The value to be converted. Typically a string, but may also be a boolean, number, or array.

      Returns string

      The value formatted as a URScript-compatible literal string.

    • Generate the String representation of a boolean.

      Parameters

      • b: boolean

        The input boolean

      Returns string

      The String representation of the input

    • Parameters

      • expression: string

        The expression to be negated

      Returns string