Cyclone 3DR Script
from Technodigit, part of Hexagon. Copyright 1997-2025.
Loading...
Searching...
No Matches
SMeasure Class Reference

Provides measurement features, to display and analyze measurements in the 3D scene. More...

Inheritance diagram for SMeasure:
SComp

Public Types

enum  SPositionningMode { FIXED = 0 , BORDER = 1 }
 The positioning mode for measures. More...
 
- Public Types inherited from SComp
enum  VisibilityEnum { HIDDEN_ONLY = 0 , VISIBLE_ONLY = 1 , ANY_VISIBILITY = 2 }
 Visible criteria. More...
 

Public Member Functions

Object AddRow (Object rowDefinition)
 Add a new row to the measure. A row is identified by a unique key and can contain multiple values that will be displayed in columns. Each value is defined by a key and a numeric value. Optionally, a prefix can be added. More...
 
Object GetComment ()
 Get the comment associated to the measure. More...
 
number GetID ()
 Get the ID of the measure. More...
 
Object GetPoint ()
 Get the anchor point of the measure. More...
 
Object GetRowData (string rowKey)
 Get all data related to a given row identified by its key. More...
 
Object GetRowName (string rowKey)
 Get the row name and unit. More...
 
Object GetRowsKeys ()
 Get all row keys of the measure. More...
 
Object GetTolerances (string rowKey)
 Return the min/max tolerances of a given row identified by its key. More...
 
Object GetValues (string rowKey)
 Get the values of a given row identified by its key. More...
 
boolean HasTolerances (string rowKey)
 Check if tolerances are defined on a given row. More...
 
 SetComment (string comment)
 Set a comment to the measure. More...
 
 SetID (number id)
 Set the ID of the measure. More...
 
Object SetPoint (SPoint point)
 Set the anchor point of the measure. More...
 
Object SetTolerances (string rowKey, number tolMin, number tolMax)
 Set the min/max tolerances of a given row. More...
 
 SMeasure ()
 Default constructor.
 
 SMeasure (SMeasure other)
 Construct a SMeasure by copying the SMeasure other. More...
 
 SMeasure (string name, SPoint point, number id=-1, string comment="")
 Construct a custom measure. More...
 
Object ToJSON ()
 Get all data related to the measure in a JSON format. More...
 
string toString ()
 Get the type of the variable. More...
 
- Public Member Functions inherited from SComp
 AddToDoc ()
 Add the object to the document. More...
 
 ApplyTransformation (SMatrix matrix)
 Apply a geometric transformation to the current object by making a product with the given matrix. More...
 
Object GetBoundingBox (SMatrix ucs=null)
 Calculate the bounding box of the object. More...
 
Object GetColors ()
 Get the colors of the object. More...
 
string GetFolderName ()
 Get the name of the folder containing the object. More...
 
string GetName ()
 Return the object's name. More...
 
string GetPath ()
 Return the full path of an SComp in the tree. More...
 
 Invert ()
 Invert the normal of the object.
 
boolean IsInDoc ()
 Return if the object is in the document or not. More...
 
boolean IsVisible ()
 Get the visibility of the object. More...
 
 MoveToGroup (string groupPath, boolean moveInsideTopParent=true)
 Move the object to the document group represent by the given path. If some groups, in the path, don't exist, they will be created. More...
 
 RemoveFromDoc ()
 Remove the object from the document.
 
 SetClippable (boolean clipping)
 Set clippable or not. More...
 
 SetColors (number red, number green, number blue)
 Set the colors of the object. More...
 
 SetName (string objectName)
 Set the object's name. More...
 
 SetTransparency (number alpha)
 Set the transparency of the object. More...
 
 SetVisibility (boolean visible)
 Set the object to be visible, or not visible. More...
 
string toString ()
 Get the type of the variable. More...
 
 Translate (SVector vector)
 Make a translation of the current object with an SVector. More...
 

Static Public Member Functions

static Array< SMeasureAll (VisibilityEnum visCrit=SComp.ANY_VISIBILITY)
 Get all the SMeasure in the document. More...
 
static Object CreateAnalysisMeasure (SPoint seedPoint, SComp comp)
 Create a measure from analysis information at a specific point of an object. More...
 
static Object CreateInfosMeasure (SPoint seedPoint, SComp comp)
 Create a measure from all attributes at a specific point of an object. More...
 
static Object FromClick ()
 Launch an interaction to select a SMeasure in the scene. More...
 
static Array< SMeasureFromName (string name)
 Search all the SMeasure with the given name. More...
 
static Array< SMeasureFromSel ()
 Get all the selected SMeasure. More...
 
static Object GetPositioningMode ()
 Get the current positioning mode of measures. More...
 
static SMeasure New (SMeasure other)
 Construct a SMeasure by copying the SMeasure other. More...
 
static SMeasure New (string name, SPoint point, number id=-1, string comment="")
 Construct a custom measure. More...
 
static Object SetPositioningMode (SPositionningMode mode)
 Switch between 'Fixed positioning' or 'Border positioning'. More...
 
- Static Public Member Functions inherited from SComp
static Array< SCompAll (VisibilityEnum visCrit=SComp.ANY_VISIBILITY)
 Get all the SComp in the document. More...
 
static Object FromClick ()
 Launch an interaction to select a SComp in the scene. More...
 
static Array< SCompFromName (string name)
 Search all the SComp with the given name. More...
 
static Array< SCompFromSel ()
 Get all the selected SComp. More...
 

Detailed Description

Provides measurement features, to display and analyze measurements in the 3D scene.

Member Enumeration Documentation

◆ SPositionningMode

The positioning mode for measures.

Enumerator
FIXED 

Fixed positioning.

BORDER 

Border positioning.

Constructor & Destructor Documentation

◆ SMeasure() [1/2]

SMeasure::SMeasure ( SMeasure  other)

Construct a SMeasure by copying the SMeasure other.

Parameters
other(SMeasure) The SMeasure to copy

◆ SMeasure() [2/2]

SMeasure::SMeasure ( string  name,
SPoint  point,
number  id = -1,
string  comment = "" 
)

Construct a custom measure.

Parameters
name(string) The name of the measure
point(SPoint) The anchor point
id(number) The ID (default -1)
comment(string) The comment (default empty)

Member Function Documentation

◆ AddRow()

Object SMeasure::AddRow ( Object  rowDefinition)

Add a new row to the measure. A row is identified by a unique key and can contain multiple values that will be displayed in columns. Each value is defined by a key and a numeric value. Optionally, a prefix can be added.

Note
The tolMin / tolMax are only applied to the first value in the row
// Ask the user to click a point
const point = SPoint.FromClick().Point;
// Scene origin point
const originPoint = SPoint.New(0,0,0);
// Create a measure at the point position and with ID 1
const meas = SMeasure.New("My meas", point, 1);
// Add a row displaying the xyz position + a distance to origin
meas.AddRow({
"key": "position",
"name": "Position",
"values": [
{
"key": "x",
"value": point.GetX()
},
{
"key": "y",
"value": point.GetY()
},
{
"key": "z",
"value": point.GetZ()
},
{
"key": "distanceToOrigin",
// Add a prefix to the column value
"prefix": "Dist. to Origin",
"value": point.Distance(originPoint)
}
]
});
// Add the measure to the document
meas.AddToDoc();
Provides measurement features, to display and analyze measurements in the 3D scene.
Definition: Reshaper.h:6611
static SMeasure New(SMeasure other)
Construct a SMeasure by copying the SMeasure other.
Object AddRow(Object rowDefinition)
Add a new row to the measure. A row is identified by a unique key and can contain multiple values tha...
Provide point edition and creation methods.
Definition: Reshaper.h:7661
static Object FromClick()
Launch an interaction to select a SPoint in the scene.
static SPoint New()
Default constructor to create an empty new SPoint. X = Y = Z = 0.
See also
SMeasure.GetRowData()
Parameters
rowDefinition(Object) The new row data definition
  • key (string): The row key
  • name (string): The row name (default: same as "key")
  • unit (string): The row unit
  • tolMin (number): The row minimum tolerance
  • tolMax (number): The row maximum tolerance
  • values (Array<Object>): The list of value per column
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: Missing key argument
  • 2: Missing values argument
  • 3: Missing row key argument
  • 4: First row value must be numeric when tolMin/tolMax are defined
  • 5: Missing row value argument
  • 6: An error occurred

◆ All()

static Array< SMeasure > SMeasure::All ( VisibilityEnum  visCrit = SComp.ANY_VISIBILITY)
static

Get all the SMeasure in the document.

Parameters
visCrit(VisibilityEnum) Visible selection criteria
Returns
(Array<SMeasure>) Array of all the SMeasure contained in the document, that fulfill the visibility criteria

◆ CreateAnalysisMeasure()

static Object SMeasure::CreateAnalysisMeasure ( SPoint  seedPoint,
SComp  comp 
)
static

Create a measure from analysis information at a specific point of an object.

Parameters
seedPoint(SPoint) The seed point (projected on the component)
comp(SComp) The component to analyze
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.Measure(SMeasure) The new analysis measure

◆ CreateInfosMeasure()

static Object SMeasure::CreateInfosMeasure ( SPoint  seedPoint,
SComp  comp 
)
static

Create a measure from all attributes at a specific point of an object.

Parameters
seedPoint(SPoint) The seed point (projected on the component)
comp(SComp) The component to measure
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.Measure(SMeasure) The new infos measure

◆ FromClick()

static Object SMeasure::FromClick ( )
static

Launch an interaction to select a SMeasure in the scene.

Warning
This function will pause the script, and wait for user interaction
Return values
ret.ErrorCode(number) The error code
  • 0: No error, the SMeasure is selected.
  • 1: Nothing is selected.
  • 2: The ESCape key has been pressed
ret.Measure(SMeasure) The selected SMeasure

◆ FromName()

static Array< SMeasure > SMeasure::FromName ( string  name)
static

Search all the SMeasure with the given name.

Parameters
name(string) The name to find
Returns
(Array<SMeasure>) All the SMeasure with the given name

◆ FromSel()

static Array< SMeasure > SMeasure::FromSel ( )
static

Get all the selected SMeasure.

Returns
(Array<SMeasure>) All the selected SMeasure

◆ GetComment()

Object SMeasure::GetComment ( )

Get the comment associated to the measure.

See also
SMeasure.SetComment()
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.String(string) The comment associated to the measure

◆ GetID()

number SMeasure::GetID ( )

Get the ID of the measure.

See also
SMeasure.SetID()
Returns
(number) The ID of the measure

◆ GetPoint()

Object SMeasure::GetPoint ( )

Get the anchor point of the measure.

See also
SMeasure.SetPoint()
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.Point(SPoint) The anchor point of the measure

◆ GetPositioningMode()

static Object SMeasure::GetPositioningMode ( )
static

Get the current positioning mode of measures.

See also
SMeasure.SetPositioningMode()
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.MeasurePositioningMode(SPositionningMode) The current positioning mode

◆ GetRowData()

Object SMeasure::GetRowData ( string  rowKey)

Get all data related to a given row identified by its key.

// Ask the user to click on a measure
const res = SMeasure.FromClick();
if(res.ErrorCode == 0)
{
const meas = res.Measure;
// Iterate on each row key
const keys = meas.GetRowsKeys().StringTbl;
keys.forEach(function(key)
{
// Fetch the row data
const rowData = meas.GetRowData(key);
if(rowData.ErrorCode == 0)
{
const res = rowData.Result;
print(`Values for row "${res.Name}"`)
res.Values.forEach(function(value)
{
const prefix = value.Prefix ?? "No Prefix";
print(`${prefix} (${value.Key}) : ${value.Value}`)
});
}
});
}
static Object FromClick()
Launch an interaction to select a SMeasure in the scene.
See also
SMeasure.GetRowKeys()
Parameters
rowKey(string) The key of the measure row
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.Result(Object) A structured object containing row data
  • Key (string): The row key
  • Name (string): The row name
  • Unit (string): The row unit
  • TolMin (number): The row minimum tolerance
  • TolMax (number): The row maximum tolerance
  • Values (Array<Object>): The list of value per column

◆ GetRowName()

Object SMeasure::GetRowName ( string  rowKey)

Get the row name and unit.

const measureTbl = SMeasure.FromSel();
const measure = measureTbl[0];
const keys = measure.GetRowsKeys().StringTbl;
keys.forEach(function(key)
{
// Print the name and unit of each row
const rowRet = measure.GetRowName(key);
print(`Row : ${rowRet.Result.Name} | Unit : ${rowRet.Result.Unit}`);
});
static Array< SMeasure > FromSel()
Get all the selected SMeasure.
Parameters
rowKey(string) The key of the measure row
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.Result(Object) Object with Name and Unit properties
  • Name (string): The name of the row
  • Unit (string): The unit of the row

◆ GetRowsKeys()

Object SMeasure::GetRowsKeys ( )

Get all row keys of the measure.

const measureTbl = SMeasure.FromSel();
const measure = measureTbl[0];
const keys = measure.GetRowsKeys().StringTbl;
keys.forEach(function(key)
{
// Print the list of keys available in the measure
print(key);
});
See also
SMeasure.GetRowData()
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.StringTbl(Array<string>) A table of row keys

◆ GetTolerances()

Object SMeasure::GetTolerances ( string  rowKey)

Return the min/max tolerances of a given row identified by its key.

const measureTbl = SMeasure.FromSel();
const measure = measureTbl[0];
const keys = measure.GetRowsKeys().StringTbl;
keys.forEach(function(key)
{
if(measure.HasTolerances(key)){
const toleranceRet = measure.GetTolerances(key)
// Print the minimum/maximum tolerances of each row
print(`TolMin : ${toleranceRet.Result.TolMin} | TolMax : ${toleranceRet.Result.TolMax}`);
}
});
See also
SMeasure.GetRowKeys(), SMeasure.SetTolerances()
Parameters
rowKey(string) The key of the measure row
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.Result(Object) An object with tolerance minimum and maximum
  • TolMin (number): The row minimum tolerance
  • TolMax (number): The row maximum tolerance

◆ GetValues()

Object SMeasure::GetValues ( string  rowKey)

Get the values of a given row identified by its key.

const measureTbl = SMeasure.FromSel();
const measure = measureTbl[0];
const keys = measure.GetRowsKeys().StringTbl;
keys.forEach(function(key, rowIdx)
{
// Print the values of each row
print(`Row ${rowIdx} values:`)
const res = measure.GetValues(key);
res.StringTbl.forEach(function(value, valueIdx) {
print(`Value ${valueIdx} : ${value}`);
});
});
See also
SMeasure.GetRowKeys()
Parameters
rowKey(string) The key of the measure row
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.StringTbl(Array<string>) Array of values for the row

◆ HasTolerances()

boolean SMeasure::HasTolerances ( string  rowKey)

Check if tolerances are defined on a given row.

See also
SMeasure.GetRowKeys()
Parameters
rowKey(string) The key of the measure row
Returns
(boolean) True if the row has tolerances defined, false otherwise

◆ New() [1/2]

static SMeasure SMeasure::New ( SMeasure  other)
static

Construct a SMeasure by copying the SMeasure other.

Parameters
other(SMeasure) The SMeasure to copy
Returns
(SMeasure) The new SMeasure.

◆ New() [2/2]

static SMeasure SMeasure::New ( string  name,
SPoint  point,
number  id = -1,
string  comment = "" 
)
static

Construct a custom measure.

Parameters
name(string) The name of the measure
point(SPoint) The anchor point
id(number) The ID (default -1)
comment(string) The comment (default empty)
Returns
(SMeasure) The new SMeasure.

◆ SetComment()

SMeasure::SetComment ( string  comment)

Set a comment to the measure.

See also
SMeasure.GetComment()
Parameters
comment(string) The comment to set

◆ SetID()

SMeasure::SetID ( number  id)

Set the ID of the measure.

See also
SMeasure.GetID()
Parameters
id(number) The ID to set

◆ SetPoint()

Object SMeasure::SetPoint ( SPoint  point)

Set the anchor point of the measure.

See also
SMeasure.GetPoint()
Parameters
point(SPoint) The anchor point to set
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred

◆ SetPositioningMode()

static Object SMeasure::SetPositioningMode ( SPositionningMode  mode)
static

Switch between 'Fixed positioning' or 'Border positioning'.

Warning
This setting is applied to the active scene.
See also
SMeasure.GetPositioningMode()
Parameters
mode(SPositionningMode) The positioning mode to set
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred

◆ SetTolerances()

Object SMeasure::SetTolerances ( string  rowKey,
number  tolMin,
number  tolMax 
)

Set the min/max tolerances of a given row.

Note
The tolMin / tolMax are only applied to the first value in the row
See also
SMeasure.GetTolerances()
Parameters
rowKey(string) The key of the measure row
tolMin(number) The minimum tolerance
tolMax(number) The maximum tolerance
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred

◆ ToJSON()

Object SMeasure::ToJSON ( )

Get all data related to the measure in a JSON format.

const measureTbl = SMeasure.FromSel();
const measure = measureTbl[0];
const res = measure.ToJSON();
const jsonStr = JSON.stringify(res.Result);
// Print the content of a measure as a JSON object
print(jsonStr);
// Write the measure to a json file
const file = SFile.New("D:/measure.json");
file.Write(jsonStr);
file.Close();
Provide an interface for reading from and writing to files on disk.
Definition: Reshaper.h:1810
@ WriteOnly
The file is opened for writing. Note that this mode implies Truncate.
Definition: Reshaper.h:1819
static SFile New(string name)
Construct a new file object to represent the file with the given name.
boolean Open(OpenModeEnum openMode)
Open the existing file (The file is always open in text mode).
Return values
ret.ErrorCode(number) The error code
  • 0: No error
  • 1: An error occurred
ret.Result(Object) A structured object containing all data
  • ID (number): The measure id
  • Title (string): The measure name
  • Comment (string): The measure comment
  • Rows (Array<Object>): The list of row data

◆ toString()

string SMeasure::toString ( )

Get the type of the variable.

Returns
(string) The type name