Workflow class

The Workflow class allows you to read and write workflow files. More...

The PRIMER JavaScript API provides many class constants, properties and methods. For Arup to be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:

Class functions

Workflow constants

Constants for UnitSystem

Name Description
Workflow.UNIT_SYSTEM_NONE No unit system
Workflow.UNIT_SYSTEM_U1 U1 unit system (m, kg, s)
Workflow.UNIT_SYSTEM_U2 U2 unit system (mm, t, s)
Workflow.UNIT_SYSTEM_U3 U3 unit system (mm, kg, ms)
Workflow.UNIT_SYSTEM_U4 U4 unit system (mm, g, ms)
Workflow.UNIT_SYSTEM_U5 U5 unit system (ft, slug, s)
Workflow.UNIT_SYSTEM_U6 U6 unit system (m, t, s)

Detailed Description

The Workflow class gives you simple functions to read and write workflow files

Details of functions

ModelIdFromIndex(model_index[integer], workflow_name (optional)[string]) [static]

Description

Returns the id of a model that has data for the selected workflow by index (starting at 0).

Arguments

  • model_index (integer)

    The index of the model to return the id for.

  • workflow_name (optional) (string)

    If defined the id of the model that has data for the named workflow is returned. If it is not specified it uses the name of the workflow selected by the user from the workflow menu.

    Returns

    integer

    Return type

    Number

    Example

    To get the id of the first model that has data for the workflow selected by the user

          var id = Workflow.ModelIdFromIndex(0);
          

    To get the id of the first model that has data for the specified workflow "Automotive Assessment"

          var id = Workflow.ModelIdFromIndex(0, "Automotive Assessment");
          


    ModelUnitSystemFromIndex(model_index[integer], workflow_name (optional)[string]) [static]

    Description

    Returns the unit system of a model that has data for the selected workflow by index (starting at 0). Will be Workflow.UNIT_SYSTEM_NONE or Workflow.UNIT_SYSTEM_U1 or Workflow.UNIT_SYSTEM_U2 or Workflow.UNIT_SYSTEM_U3 or Workflow.UNIT_SYSTEM_U4 or Workflow.UNIT_SYSTEM_U5 or Workflow.UNIT_SYSTEM_U6

    Arguments

  • model_index (integer)

    The index of the model to return the unit system for.

  • workflow_name (optional) (string)

    The workflow name to return the unit system for. This is required when a PRIMER item is generated from REPORTER. If it is not specified the first workflow unit system associated with the model is returned (this is the 'normal' case where a user launches a workflow from the workflow menu).

    Returns

    integer

    Return type

    Number

    Example

    To get the unit system of the first model that has data for the workflow selected by the user

    var unit_system = Workflow.ModelUnitSystemFromIndex(0);
          

    To get the unit system of the second model that has data for the "Automotive Assessment" workflow

    var unit_system = Workflow.ModelUnitSystemFromIndex(1, "Automotive Assessment");
          


    ModelUserDataBuildFromIndex(model_index[integer], workflow_name (optional)[string]) [static]

    Description

    Returns the build number of the program that was used to write out the user data of a model for the selected workflow by index (starting at 0).

    Arguments

  • model_index (integer)

    The index of the model to return the program build number for.

  • workflow_name (optional) (string)

    The workflow name to return the build number for. This is required when a PRIMER item is generated from REPORTER. If it is not specified the build number for the first user data associated with the model is returned (this is the 'normal' case where a user launches a workflow from the workflow menu).

    Returns

    number

    Return type

    number

    Example

    To get the build number of the program that was used to write user data for the first model that has data for the workflow selected by the user

    var build = Workflow.ModelUserDataBuildFromIndex(0);
          

    To get the build number of the program that was used to write user data for the second model that has data for the "Automotive Assessment" workflow

    var build = Workflow.ModelUserDataBuildFromIndex(1, "Automotive Assessment");
          


    ModelUserDataFromIndex(model_index[integer], workflow_name (optional)[string]) [static]

    Description

    Returns the user data associated with a model that has data for the selected workflow by index (starting at 0).

    Arguments

  • model_index (integer)

    The index of the model to return the user data for.

  • workflow_name (optional) (string)

    The workflow name to return the user data for. If it is not specified it uses the name of the workflow selected by the user from the workflow menu.

    Returns

    object

    Return type

    Object

    Example

    To get the user data for the first model that has data for the workflow selected by the user

    var user_data = Workflow.ModelUserDataFromIndex(0);
          

    To get the user data for the second model that has data for the "Automotive Assessment" workflow

    var user_data = Workflow.ModelUserDataFromIndex(1, "Automotive Assessment");
          


    ModelUserDataProgramFromIndex(model_index[integer], workflow_name (optional)[string]) [static]

    Description

    Returns the name of the program that was used to write out the user data of a model for the selected workflow by index (starting at 0).

    Arguments

  • model_index (integer)

    The index of the model to return the program name for.

  • workflow_name (optional) (string)

    The workflow name to return the program name for. This is required when a PRIMER item is generated from REPORTER. If it is not specified the program name for the first user data associated with the model is returned (this is the 'normal' case where a user launches a workflow from the workflow menu).

    Returns

    string

    Return type

    String

    Example

    To get the name of the program that was used to write user data for the first model that has data for the workflow selected by the user

    var program = Workflow.ModelUserDataProgramFromIndex(0);
          

    To get the name of the program that was used to write user data for the second model that has data for the "Automotive Assessment" workflow

    var program = Workflow.ModelUserDataProgramFromIndex(1, "Automotive Assessment");
          


    ModelUserDataVersionFromIndex(model_index[integer], workflow_name (optional)[string]) [static]

    Description

    Returns the version of the program that was used to write out the user data of a model for the selected workflow by index (starting at 0).

    Arguments

  • model_index (integer)

    The index of the model to return the program version for.

  • workflow_name (optional) (string)

    The workflow name to return the version for. This is required when a PRIMER item is generated from REPORTER. If it is not specified the version for the first user data associated with the model is returned (this is the 'normal' case where a user launches a workflow from the workflow menu).

    Returns

    number

    Return type

    number

    Example

    To get the version of the program that was used to write user data for the first model that has data for the workflow selected by the user

    var version = Workflow.ModelUserDataVersionFromIndex(0);
          

    To get the version of the program that was used to write user data for the second model that has data for the "Automotive Assessment" workflow

    var version = Workflow.ModelUserDataVersionFromIndex(1, "Automotive Assessment");
          


    NumberOfModels(workflow_name (optional)[string]) [static]

    Description

    Returns the number of models that have data for the workflow selected by the user.

    Arguments

  • workflow_name (optional) (string)

    If defined the number of models that have data for the named workflow is returned. If not defined the number of models that have data for the workflow selected by the user on the workflow menu is returned

    Returns

    integer

    Return type

    Number

    Example

    To get the number of models that have data

          var n = Workflow.NumberOfModels();
          


    Refresh() [static]

    Description

    Scan for fresh workflow data

    Arguments

    No arguments

    Returns

    No return value

    Example

    Workflow.Refresh();
          


    WorkflowDefinitionFilename(workflow_name (optional)[string]) [static]

    Description

    Returns the workflow definition filename

    Arguments

  • workflow_name (optional) (string)

    The workflow name to return the workflow defintion filename for. If it is not specified it uses the name of the workflow selected by the user from the workflow menu.

    Returns

    string

    Return type

    String

    Example

    To get the worklow definition filename that the script has been run with

          var workflow_definition_filename = Workflow.WorkflowDefinitionFilename();
          


    WriteToFile(user_data[object], output_filename[string], workflow_definition_filename[string], extra (optional)[object]) [static]

    Description

    Writes a workflow to a JSON file. If the file already exists the workflow is added to the file (or updated if it is already in the file).

    Arguments

  • user_data (object)

    Object containing user data required for the workflow.

  • output_filename (string)

    Filename to write to.

  • workflow_definition_filename (string)

    Filename of the workflow definition file.

  • extra (optional) (object)

    Extra workflow information

    Object has the following properties:

    Name Type Description
    model_unit_system (optional) integer The model unit system. Can be Workflow.UNIT_SYSTEM_NONE or Workflow.UNIT_SYSTEM_U1 or Workflow.UNIT_SYSTEM_U2 or Workflow.UNIT_SYSTEM_U3 or Workflow.UNIT_SYSTEM_U4 or Workflow.UNIT_SYSTEM_U5 or Workflow.UNIT_SYSTEM_U6

    Returns

    No return value

    Example

    To write the file "C:\my_workflow.json" with some user data and the contents of the workflow definition file "C:\workflows\my_workflow_definition.json"

          var user_data = { part_ids: [1, 2, 10, 100], node_ids: [12, 23, 24] };
          Workflow.WriteToFile(user_data, "C:\\my_workflow.json", "C:\\workflows\\my_workflow_definition.json");
          


    WriteToModel(user_data[object], model[Model], workflow_definition_filename[string], extra (optional)[object]) [static]

    Description

    Writes a workflow to a model (updating it if it already exists)

    Arguments

  • user_data (object)

    Object containing user data required for the workflow.

  • model (Model)

    Model to write to.

  • workflow_definition_filename (string)

    Filename of the workflow definition file.

  • extra (optional) (object)

    Extra workflow information

    Object has the following properties:

    Name Type Description
    model_unit_system (optional) integer The model unit system. Can be Workflow.UNIT_SYSTEM_NONE or Workflow.UNIT_SYSTEM_U1 or Workflow.UNIT_SYSTEM_U2 or Workflow.UNIT_SYSTEM_U3 or Workflow.UNIT_SYSTEM_U4 or Workflow.UNIT_SYSTEM_U5 or Workflow.UNIT_SYSTEM_U6

    Returns

    No return value

    Example

    To write the workflow to the first model with some user data and the contents of the workflow definition file "C:\workflows\my_workflow_definition.json"

          var user_data = { part_ids: [1, 2, 10, 100], node_ids: [12, 23, 24] };
          var m = Model.First();
          Workflow.WriteToModel(user_data, m, "C:\\workflows\\my_workflow_definition.json");