Sph class

The Sph class gives you access to Element SPH cards in PRIMER. 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

Member functions

Sph properties

Name Type Description
colour Colour The colour of the sph element.
exists (read only) logical true if sph exists, false if referred to but not defined.
include integer The Include file number that the sph is in.
mass real Mass value.
model (read only) integer The Model number that the sph is in.
nid integer Node ID.
pid integer Part ID to which this element belongs.
transparency integer The transparency of the sph (0-100) 0% is opaque, 100% is transparent.

Detailed Description

The Sph class allows you to create, modify, edit and manipulate SPH cards. See the documentation below for more details.

Constructor

new Sph(Model[Model], nid[integer], pid[integer], mass[real])

Description

Create a new object.

Arguments

  • Model (Model)

    Model that sph will be created in

  • nid (integer)

    Node ID and Element ID are the same for the SPH option.

  • pid (integer)

    Part ID to which this element belongs.

  • mass (real)

    Mass value.

    Returns

    Sph object

    Return type

    Sph

    Example

    To create a new sph element in model m with nid = 100, pid = 400, mass = 0.9:

    var s = new Sph(m, 100, 400, 0.9);

    Details of functions

    AssociateComment(Comment[Comment])

    Description

    Associates a comment with a sph.

    Arguments

  • Comment (Comment)

    Comment that will be attached to the sph

    Returns

    No return value

    Example

    To associate comment c to the sph s:

    s.AssociateComment(c);


    Blank()

    Description

    Blanks the sph

    Arguments

    No arguments

    Returns

    No return value

    Example

    To blank sph s:

    s.Blank();


    BlankAll(Model[Model], redraw (optional)[boolean]) [static]

    Description

    Blanks all of the sphs in the model.

    Arguments

  • Model (Model)

    Model that all sphs will be blanked in

  • redraw (optional) (boolean)

    If model should be redrawn or not. If omitted redraw is false. If you want to do several (un)blanks and only redraw after the last one then use false for all redraws apart from the last one. Alternatively you can redraw using View.Redraw().

    Returns

    No return value

    Example

    To blank all of the sphs in model m:

    Sph.BlankAll(m);


    BlankFlagged(Model[Model], flag[Flag], redraw (optional)[boolean]) [static]

    Description

    Blanks all of the flagged sphs in the model.

    Arguments

  • Model (Model)

    Model that all the flagged sphs will be blanked in

  • flag (Flag)

    Flag set on the sphs that you want to blank

  • redraw (optional) (boolean)

    If model should be redrawn or not. If omitted redraw is false. If you want to do several (un)blanks and only redraw after the last one then use false for all redraws apart from the last one. Alternatively you can redraw using View.Redraw().

    Returns

    No return value

    Example

    To blank all of the sphs in model m flagged with f:

    Sph.BlankFlagged(m, f);


    Blanked()

    Description

    Checks if the sph is blanked or not.

    Arguments

    No arguments

    Returns

    true if blanked, false if not.

    Return type

    Boolean

    Example

    To check if sph s is blanked:

    if (s.Blanked() ) do_something...


    Browse(modal (optional)[boolean])

    Description

    Starts an edit panel in Browse mode.

    Arguments

  • modal (optional) (boolean)

    If this window is modal (blocks the user from doing anything else in PRIMER until this window is dismissed). If omitted the window will be modal.

    Returns

    no return value

    Example

    To Browse sph s:

    s.Browse();


    ClearFlag(flag[Flag])

    Description

    Clears a flag on the sph.

    Arguments

  • flag (Flag)

    Flag to clear on the sph

    Returns

    No return value

    Example

    To clear flag f for sph s:

    s.ClearFlag(f);


    Copy(range (optional)[boolean])

    Description

    Copies the sph. The target include of the copied sph can be set using Options.copy_target_include.

    Arguments

  • range (optional) (boolean)

    If you want to keep the copied item in the range specified for the current include. Default value is false. To set current include, use Include.MakeCurrentLayer().

    Returns

    Sph object

    Return type

    Sph

    Example

    To copy sph s into sph z:

    var z = s.Copy();


    Create(Model[Model], modal (optional)[boolean]) [static]

    Description

    Starts an interactive editing panel to create a sph

    Arguments

  • Model (Model)

    Model that the sph will be created in.

  • modal (optional) (boolean)

    If this window is modal (blocks the user from doing anything else in PRIMER until this window is dismissed). If omitted the window will be modal.

    Returns

    Sph object (or null if not made).

    Return type

    Sph

    Example

    To start creating a sph in model m:

    var s = Sph.Create(m);


    DetachComment(Comment[Comment])

    Description

    Detaches a comment from a sph.

    Arguments

  • Comment (Comment)

    Comment that will be detached from the sph

    Returns

    No return value

    Example

    To detach comment c from the sph s:

    s.DetachComment(c);


    Edit(modal (optional)[boolean])

    Description

    Starts an interactive editing panel.

    Arguments

  • modal (optional) (boolean)

    If this window is modal (blocks the user from doing anything else in PRIMER until this window is dismissed). If omitted the window will be modal.

    Returns

    no return value

    Example

    To Edit sph s:

    s.Edit();


    Error(message[string], details (optional)[string])

    Description

    Adds an error for sph. For more details on checking see the Check class.

    Arguments

  • message (string)

    The error message to give

  • details (optional) (string)

    An optional detailed error message

    Returns

    No return value

    Example

    To add an error message "My custom error" for sph s:

    s.Error("My custom error");


    ExtractColour()

    Description

    Extracts the actual colour used for sph.
    By default in PRIMER many entities such as elements get their colour automatically from the part that they are in. PRIMER cycles through 13 default colours based on the label of the entity. In this case the sph colour property will return the value Colour.PART instead of the actual colour. This method will return the actual colour which is used for drawing the sph.

    Arguments

    No arguments

    Returns

    colour value (integer)

    Return type

    Number

    Example

    To return the colour used for drawing sph s:

    var colour = s.ExtractColour();


    First(Model[Model]) [static]

    Description

    Returns the first sph in the model.

    Arguments

  • Model (Model)

    Model to get first sph in

    Returns

    Sph object (or null if there are no sphs in the model).

    Return type

    Sph

    Example

    To get the first sph in model m:

    var s = Sph.First(m);


    FirstFreeLabel(Model[Model], layer (optional)[Include number]) [static]

    Description

    Returns the first free sph label in the model. Also see Sph.LastFreeLabel(), Sph.NextFreeLabel() and Model.FirstFreeItemLabel().

    Arguments

  • Model (Model)

    Model to get first free sph label in

  • layer (optional) (Include number)

    Include file (0 for the main file) to search for labels in (Equivalent to First free in layer in editing panels). If omitted the whole model will be used (Equivalent to First free in editing panels).

    Returns

    Sph label.

    Return type

    Number

    Example

    To get the first free sph label in model m:

    var label = Sph.FirstFreeLabel(m);


    FlagAll(Model[Model], flag[Flag]) [static]

    Description

    Flags all of the sphs in the model with a defined flag.

    Arguments

  • Model (Model)

    Model that all sphs will be flagged in

  • flag (Flag)

    Flag to set on the sphs

    Returns

    No return value

    Example

    To flag all of the sphs with flag f in model m:

    Sph.FlagAll(m, f);


    Flagged(flag[Flag])

    Description

    Checks if the sph is flagged or not.

    Arguments

  • flag (Flag)

    Flag to test on the sph

    Returns

    true if flagged, false if not.

    Return type

    Boolean

    Example

    To check if sph s has flag f set on it:

    if (s.Flagged(f) ) do_something...


    ForEach(Model[Model], func[function], extra (optional)[any]) [static]

    Description

    Calls a function for each sph in the model.
    Note that ForEach has been designed to make looping over sphs as fast as possible and so has some limitations.
    Firstly, a single temporary Sph object is created and on each function call it is updated with the current sph data. This means that you should not try to store the Sph object for later use (e.g. in an array) as it is temporary.
    Secondly, you cannot create new sphs inside a ForEach loop.

    Arguments

  • Model (Model)

    Model that all sphs are in

  • func (function)

    Function to call for each sph

  • extra (optional) (any)

    An optional extra object/array/string etc that will appended to arguments when calling the function

    Returns

    No return value

    Example

    To call function test for all of the sphs in model m:

    Sph.ForEach(m, test);
    function test(s)
    {
    // s is Sph object
    }

    To call function test for all of the sphs in model m with optional object:

    var data = { x:0, y:0 };
    Sph.ForEach(m, test, data);
    function test(s, extra)
    {
    // s is Sph object
    // extra is data
    }


    GetAll(Model[Model], property (optional)[string]) [static]

    Description

    Returns an array of Sph objects or properties for all of the sphs in a model in PRIMER. If the optional property argument is not given then an array of Sph objects is returned. If the property argument is given, that property value for each sph is returned in the array instead of a Sph object

    Arguments

  • Model (Model)

    Model to get sphs from

  • property (optional) (string)

    Name for property to get for all sphs in the model

    Returns

    Array of Sph objects or properties

    Return type

    Array

    Example

    To make an array of Sph objects for all of the sphs in model m:

    var a = Sph.GetAll(m);

    To return an array containing the value of property 'foo' (for example 'x' for a node) for each sph in model m:

    var a = Sph.GetAll(m, 'foo');


    GetComments()

    Description

    Extracts the comments associated to a sph.

    Arguments

    No arguments

    Returns

    Array of Comment objects (or null if there are no comments associated to the node).

    Return type

    Array

    Example

    To get the array of comments associated to the sph s:

    var comm_array = s.GetComments();


    GetFlagged(Model[Model], flag[Flag], property (optional)[string]) [static]

    Description

    Returns an array of Sph objects for all of the flagged sphs in a model in PRIMER If the optional property argument is not given then an array of Sph objects is returned. If the property argument is given, then that property value for each sph is returned in the array instead of a Sph object

    Arguments

  • Model (Model)

    Model to get sphs from

  • flag (Flag)

    Flag set on the sphs that you want to retrieve

  • property (optional) (string)

    Name for property to get for all flagged sphs in the model

    Returns

    Array of Sph objects or properties

    Return type

    Array

    Example

    To make an array of Sph objects for all of the sphs in model m flagged with f:

    var s = Sph.GetFlagged(m, f);

    To return an array containing the value of property 'foo' (for example 'x' for a node) for all of the sphs in model m flagged with f:

    var a = Sph.GetFlagged(m, f, 'foo');


    GetFromID(Model[Model], number[integer]) [static]

    Description

    Returns the Sph object for a sph ID.

    Arguments

  • Model (Model)

    Model to find the sph in

  • number (integer)

    number of the sph you want the Sph object for

    Returns

    Sph object (or null if sph does not exist).

    Return type

    Sph

    Example

    To get the Sph object for sph 100 in model m

    var s = Sph.GetFromID(m, 100);


    GetParameter(prop[string])

    Description

    Checks if a Sph property is a parameter or not. Note that object properties that are parameters are normally returned as the integer or float parameter values as that is virtually always what the user would want. For this function to work the JavaScript interpreter must use the parameter name instead of the value. This can be done by setting the Options.property_parameter_names option to true before calling the function and then resetting it to false afterwards.. This behaviour can also temporarily be switched by using the Sph.ViewParameters() method and 'method chaining' (see the examples below).

    Arguments

  • prop (string)

    sph property to get parameter for

    Returns

    Parameter object if property is a parameter, null if not.

    Return type

    Parameter

    Example

    To check if Sph property s.example is a parameter:

    Options.property_parameter_names = true;
    if (s.GetParameter(s.example) ) do_something...
    Options.property_parameter_names = false;

    To check if Sph property s.example is a parameter by using the GetParameter method:

    if (s.ViewParameters().GetParameter(s.example) ) do_something...


    Keyword()

    Description

    Returns the keyword for this sph (*ELEMENT_SPH) Note that a carriage return is not added. See also Sph.KeywordCards()

    Arguments

    No arguments

    Returns

    string containing the keyword.

    Return type

    String

    Example

    To get the keyword for sph s:

    var key = s.Keyword();


    KeywordCards()

    Description

    Returns the keyword cards for the sph. Note that a carriage return is not added. See also Sph.Keyword()

    Arguments

    No arguments

    Returns

    string containing the cards.

    Return type

    String

    Example

    To get the cards for sph s:

    var cards = s.KeywordCards();


    Last(Model[Model]) [static]

    Description

    Returns the last sph in the model.

    Arguments

  • Model (Model)

    Model to get last sph in

    Returns

    Sph object (or null if there are no sphs in the model).

    Return type

    Sph

    Example

    To get the last sph in model m:

    var s = Sph.Last(m);


    LastFreeLabel(Model[Model], layer (optional)[Include number]) [static]

    Description

    Returns the last free sph label in the model. Also see Sph.FirstFreeLabel(), Sph.NextFreeLabel() and see Model.LastFreeItemLabel()

    Arguments

  • Model (Model)

    Model to get last free sph label in

  • layer (optional) (Include number)

    Include file (0 for the main file) to search for labels in (Equivalent to Highest free in layer in editing panels). If omitted the whole model will be used.

    Returns

    Sph label.

    Return type

    Number

    Example

    To get the last free sph label in model m:

    var label = Sph.LastFreeLabel(m);


    Next()

    Description

    Returns the next sph in the model.

    Arguments

    No arguments

    Returns

    Sph object (or null if there are no more sphs in the model).

    Return type

    Sph

    Example

    To get the sph in model m after sph s:

    var s = s.Next();


    NextFreeLabel(Model[Model], layer (optional)[Include number]) [static]

    Description

    Returns the next free (highest+1) sph label in the model. Also see Sph.FirstFreeLabel(), Sph.LastFreeLabel() and Model.NextFreeItemLabel()

    Arguments

  • Model (Model)

    Model to get next free sph label in

  • layer (optional) (Include number)

    Include file (0 for the main file) to search for labels in (Equivalent to Highest+1 in layer in editing panels). If omitted the whole model will be used (Equivalent to Highest+1 in editing panels).

    Returns

    Sph label.

    Return type

    Number

    Example

    To get the next free sph label in model m:

    var label = Sph.NextFreeLabel(m);


    Pick(prompt[string], limit (optional)[Model or Flag], modal (optional)[boolean], button text (optional)[string]) [static]

    Description

    Allows the user to pick a sph.

    Arguments

  • prompt (string)

    Text to display as a prompt to the user

  • limit (optional) (Model or Flag)

    If the argument is a Model then only sphs from that model can be picked. If the argument is a Flag then only sphs that are flagged with limit can be selected. If omitted, or null, any sphs from any model can be selected. from any model.

  • modal (optional) (boolean)

    If picking is modal (blocks the user from doing anything else in PRIMER until this window is dismissed). If omitted the pick will be modal.

  • button text (optional) (string)

    By default the window with the prompt will have a button labelled 'Cancel' which if pressed will cancel the pick and return null. If you want to change the text on the button use this argument. If omitted 'Cancel' will be used.

    Returns

    Sph object (or null if not picked)

    Return type

    Sph

    Example

    To pick a sph from model m giving the prompt 'Pick sph from screen':

    var s = Sph.Pick('Pick sph from screen', m);


    Previous()

    Description

    Returns the previous sph in the model.

    Arguments

    No arguments

    Returns

    Sph object (or null if there are no more sphs in the model).

    Return type

    Sph

    Example

    To get the sph in model m before sph s:

    var s = s.Previous();


    RenumberAll(Model[Model], start[integer]) [static]

    Description

    Renumbers all of the sphs in the model.

    Arguments

  • Model (Model)

    Model that all sphs will be renumbered in

  • start (integer)

    Start point for renumbering

    Returns

    No return value

    Example

    To renumber all of the sphs in model m, from 1000000:

    Sph.RenumberAll(m, 1000000);


    RenumberFlagged(Model[Model], flag[Flag], start[integer]) [static]

    Description

    Renumbers all of the flagged sphs in the model.

    Arguments

  • Model (Model)

    Model that all the flagged sphs will be renumbered in

  • flag (Flag)

    Flag set on the sphs that you want to renumber

  • start (integer)

    Start point for renumbering

    Returns

    No return value

    Example

    To renumber all of the sphs in model m flagged with f, from 1000000:

    Sph.RenumberFlagged(m, f, 1000000);


    Select(flag[Flag], prompt[string], limit (optional)[Model or Flag], modal (optional)[boolean]) [static]

    Description

    Allows the user to select sphs using standard PRIMER object menus.

    Arguments

  • flag (Flag)

    Flag to use when selecting sphs

  • prompt (string)

    Text to display as a prompt to the user

  • limit (optional) (Model or Flag)

    If the argument is a Model then only sphs from that model can be selected. If the argument is a Flag then only sphs that are flagged with limit can be selected (limit should be different to flag). If omitted, or null, any sphs can be selected. from any model.

  • modal (optional) (boolean)

    If selection is modal (blocks the user from doing anything else in PRIMER until this window is dismissed). If omitted the selection will be modal.

    Returns

    Number of sphs selected or null if menu cancelled

    Return type

    Number

    Example

    To select sphs from model m, flagging those selected with flag f, giving the prompt 'Select sphs':

    Sph.Select(f, 'Select sphs', m);

    To select sphs, flagging those selected with flag f but limiting selection to sphs flagged with flag l, giving the prompt 'Select sphs':

    Sph.Select(f, 'Select sphs', l);


    SetFlag(flag[Flag])

    Description

    Sets a flag on the sph.

    Arguments

  • flag (Flag)

    Flag to set on the sph

    Returns

    No return value

    Example

    To set flag f for sph s:

    s.SetFlag(f);


    Sketch(redraw (optional)[boolean])

    Description

    Sketches the sph. The sph will be sketched until you either call Sph.Unsketch(), Sph.UnsketchAll(), Model.UnsketchAll(), or delete the model

    Arguments

  • redraw (optional) (boolean)

    If model should be redrawn or not after the sph is sketched. If omitted redraw is true. If you want to sketch several sphs and only redraw after the last one then use false for redraw and call View.Redraw().

    Returns

    No return value

    Example

    To sketch sph s:

    s.Sketch();


    SketchFlagged(Model[Model], flag[Flag], redraw (optional)[boolean]) [static]

    Description

    Sketches all of the flagged sphs in the model. The sphs will be sketched until you either call Sph.Unsketch(), Sph.UnsketchFlagged(), Model.UnsketchAll(), or delete the model

    Arguments

  • Model (Model)

    Model that all the flagged sphs will be sketched in

  • flag (Flag)

    Flag set on the sphs that you want to sketch

  • redraw (optional) (boolean)

    If model should be redrawn or not after the sphs are sketched. If omitted redraw is true. If you want to sketch flagged sphs several times and only redraw after the last one then use false for redraw and call View.Redraw().

    Returns

    No return value

    Example

    To sketch all sphs flagged with flag in model m:

    Sph.SketchFlagged(m, flag);


    Total(Model[Model], exists (optional)[boolean]) [static]

    Description

    Returns the total number of sphs in the model.

    Arguments

  • Model (Model)

    Model to get total for

  • exists (optional) (boolean)

    true if only existing sphs should be counted. If false or omitted referenced but undefined sphs will also be included in the total.

    Returns

    number of sphs

    Return type

    Number

    Example

    To get the total number of sphs in model m:

    var total = Sph.Total(m);


    Unblank()

    Description

    Unblanks the sph

    Arguments

    No arguments

    Returns

    No return value

    Example

    To unblank sph s:

    s.Unblank();


    UnblankAll(Model[Model], redraw (optional)[boolean]) [static]

    Description

    Unblanks all of the sphs in the model.

    Arguments

  • Model (Model)

    Model that all sphs will be unblanked in

  • redraw (optional) (boolean)

    If model should be redrawn or not. If omitted redraw is false. If you want to do several (un)blanks and only redraw after the last one then use false for all redraws apart from the last one. Alternatively you can redraw using View.Redraw().

    Returns

    No return value

    Example

    To unblank all of the sphs in model m:

    Sph.UnblankAll(m);


    UnblankFlagged(Model[Model], flag[Flag], redraw (optional)[boolean]) [static]

    Description

    Unblanks all of the flagged sphs in the model.

    Arguments

  • Model (Model)

    Model that the flagged sphs will be unblanked in

  • flag (Flag)

    Flag set on the sphs that you want to unblank

  • redraw (optional) (boolean)

    If model should be redrawn or not. If omitted redraw is false. If you want to do several (un)blanks and only redraw after the last one then use false for all redraws apart from the last one. Alternatively you can redraw using View.Redraw().

    Returns

    No return value

    Example

    To unblank all of the sphs in model m flagged with f:

    Sph.UnblankFlagged(m, f);


    UnflagAll(Model[Model], flag[Flag]) [static]

    Description

    Unsets a defined flag on all of the sphs in the model.

    Arguments

  • Model (Model)

    Model that the defined flag for all sphs will be unset in

  • flag (Flag)

    Flag to unset on the sphs

    Returns

    No return value

    Example

    To unset the flag f on all the sphs in model m:

    Sph.UnflagAll(m, f);


    Unsketch(redraw (optional)[boolean])

    Description

    Unsketches the sph.

    Arguments

  • redraw (optional) (boolean)

    If model should be redrawn or not after the sph is unsketched. If omitted redraw is true. If you want to unsketch several sphs and only redraw after the last one then use false for redraw and call View.Redraw().

    Returns

    No return value

    Example

    To unsketch sph s:

    s.Unsketch();


    UnsketchAll(Model[Model], redraw (optional)[boolean]) [static]

    Description

    Unsketches all sphs.

    Arguments

  • Model (Model)

    Model that all sphs will be unblanked in

  • redraw (optional) (boolean)

    If model should be redrawn or not after the sphs are unsketched. If omitted redraw is true. If you want to unsketch several things and only redraw after the last one then use false for redraw and call View.Redraw().

    Returns

    No return value

    Example

    To unsketch all sphs in model m:

    Sph.UnsketchAll(m);


    UnsketchFlagged(Model[Model], flag[Flag], redraw (optional)[boolean]) [static]

    Description

    Unsketches all flagged sphs in the model.

    Arguments

  • Model (Model)

    Model that all sphs will be unsketched in

  • flag (Flag)

    Flag set on the sphs that you want to unsketch

  • redraw (optional) (boolean)

    If model should be redrawn or not after the sphs are unsketched. If omitted redraw is true. If you want to unsketch several things and only redraw after the last one then use false for redraw and call View.Redraw().

    Returns

    No return value

    Example

    To unsketch all sphs flagged with flag in model m:

    Sph.UnsketchAll(m, flag);


    ViewParameters()

    Description

    Object properties that are parameters are normally returned as the integer or float parameter values as that is virtually always what the user would want. This function temporarily changes the behaviour so that if a property is a parameter the parameter name is returned instead. This can be used with 'method chaining' (see the example below) to make sure a property argument is correct.

    Arguments

    No arguments

    Returns

    Sph object.

    Return type

    Sph

    Example

    To check if Sph property s.example is a parameter by using the Sph.GetParameter() method:

    if (s.ViewParameters().GetParameter(s.example) ) do_something...


    Warning(message[string], details (optional)[string])

    Description

    Adds a warning for sph. For more details on checking see the Check class.

    Arguments

  • message (string)

    The warning message to give

  • details (optional) (string)

    An optional detailed warning message

    Returns

    No return value

    Example

    To add a warning message "My custom warning" for sph s:

    s.Warning("My custom warning");


    Xrefs()

    Description

    Returns the cross references for this sph.

    Arguments

    No arguments

    Returns

    Xrefs object.

    Return type

    Xrefs

    Example

    To get the cross references for sph s:

    var xrefs = s.Xrefs();


    toString()

    Description

    Creates a string containing the sph data in keyword format. Note that this contains the keyword header and the keyword cards. See also Sph.Keyword() and Sph.KeywordCards().

    Arguments

    No arguments

    Returns

    string

    Return type

    String

    Example

    To get data for sph s in keyword format

    var str = s.toString();