Examples of Using Some Functions

Navigation:  Variables and Related Parametric Tools > Variables >

Examples of Using Some Functions

Previous pageReturn to chapter overviewNext page

Using functions ATOT (), LTOT (), SATOT (), SLTOT ().

These four functions are intended for converting numerical values to character strings in a specified format. The conversion format is similar to that used for converting the nominal dimension values.

The function SATOT () converts a real number of an angular value into a string of text. The conversion parameters are defined by the settings of the "ST: Set Document Parameters" command on the Dimensions tab.

The function SATOT () specifically uses the definitions from the "Angular Dimensions" group. Suppose, the following parameters are defined in the "ST: Set Document Parameters" command. In this case, calling SATOT (120.34567) leads to the following result: 12%%d30'

               

The character combination %%d stands for the degree symbol (°).

In order to realize this character combination as the degree symbol, the variable must be used as a parameter of some detailing element, such as a text (string text only), dimension, leader note, etc.

Let's clarify the above on the following example. Suppose, the following value is assigned to the variable $str by the function call:

$str = SATOT ( 120.34567 ) = 120%%30'

We will then create a dimension with the "Before" string containing the variable in braces instead of the default. The following result will then be displayed:

clip2164         clip2165

The variables that are assigned return values of such functions can also be entered (in braces) in string text. Such text will then be correctly displayed as well.

Modifying the Units parameter in the command ST: Set Document Parameters as shown leads to the following result:

SATOT ( 120.34567 ) returns  120.5%%d

The “Accuracy” parameter allows controlling the accuracy of the returned result:

SATOT ( 120.34567 ) returns  120%%d21

The “Minimum digits” parameter is used only for decimal representation:

SATOT ( 120.34567 ) returns  120.500%%d

The function SLTOT () differs from the previous one only in that the value to be converted is considered a linear value. Therefore, the conversion formats change accordingly. There are four standard formats for this function:

1 – decimal format. Example: 1.123;

2 – in inches;

3 – in inches and fractions;

4 – in feet, inches and fractions.

The following settings showing in the pictures result in: SLTOT ( 120.34567 ) returns  ®  120.35        

       

The functions ATOT () and LTOT () are, respectively, the variations of the functions SATOT () and SLTOT (), with the conversion parameters defined explicitly.

The calling sequence of the function LTOT is as follows,

LTOT (value, accuracy, standard, digits), where

value – a real number to be converted;

accuracy – the accuracy to be used in the conversion;

standard – the measurement system; takes one of the following values:

 1 – decimal format. Example: 1.123;

 2 – in inches;

 3 – in inches and fractions;

 4 – in feet, inches and fractions;

digits – the number of significant decimal digits in the decimal representation.

The calling sequence of the function ATOT is as follows,

ATOT (value, accuracy, standard, digits), where

value – a real number to be converted;

accuracy – the accuracy to be used in the conversion;

standard – the angular units; takes one of the following values:

 1 – decimal format. Example: 1.123;

 2 – degrees, minutes and seconds. Example: 1°2'30".

digits – the number of significant decimal digits in the decimal representation.

Example:

LTOT ( 120.34567, 0.001, 1, 5 ) returns  ®  120.34600

 

Using function GET ()

This function returns the value of the requested property of a 2D or 3D element, as well as the current drawing page. Sets of accessible properties vary depending on the queried element.

The function will be automatically substituted as expression for a variable if such variable is created when measuring properties of 2D or 3D element in "PM: Measure Element or relation between two Elements" command.

The calling sequence:

GET  ( "string1",  "string2" ), where

string1 – the queried element name or Id,

string2 – the parameter name.

All 3D elements and operations are assigned Ids (unique identification numbers). They are also assigned a "Name" parameter that is automatically initialized by a system default. The name can be changed by the user if necessary. The 2D elements by default only get an Id. Names can be assigned to some 2D elements, particularly, to 2D nodes and graphic lines. The names are assigned in the editing commands, such as "EN: Edit Node" or "EG: Edit Graphic Line", using the option.

The elements whose parameters can be got by the described function, are:

- the drawing's 2D pages;

- construction lines;

- nodes;

- graphic lines;

- text;

- fragments;

- hatches;

- 3D elements;

- 3D operations;

- faces, edges, loops.

The following reserved names are used for the available parameters:

 

for 2D pages of a drawing:

"ZONES_STEP_X" - the size of one zone along X-axis (the step size along X-axis);

"ZONES_STEP_Y" - the size of one zone along X-axis (the step size along Y-axis_;

"ZONES_OFFSET_X" - the offset of the area being divided into the zones from the point (0,0) - along X-axis;

"ZONES_OFFSET_Y" - the offset of the area being divided into the zones from the point (0,0) - along Y-axis;

"ZONES_COUNT_X" - the number of zones along X-axis;

"ZONES_COUNT_Y" - the number of zones along Y-axis.

The parameters of dividing a drawing page into zones are defined in the command "ST: Set Document Parameters", on the tab Paper > Zones.

 

for nodes:

"X" – X-coordinate of the node

"Y" – Y-coordinate of the node

 

for construction lines:

lines:

"X", "Y" – the coordinates of the first node the straight construction line is passing through.

"P1", "P2" - the coordinates of the second node the straight construction line is passing through.

 

circles and ellipses:

"LENGTH" – the length of the circumferential

"P1" – the radius of the circle (this parameter is specific to circles)

"X", "Y" – the coordinates of the center of the circle

 

splines, 2D paths, functions and offsets:

"LENGTH" – the entity length

 

for graphic lines:

segments:

"LENGTH" - the segment length

"START_X", "START_Y" – the coordinates of the start point of the segment

"END_X", "END_Y" – the coordinates of the end point of the segment

 

based on circles:

"LENGTH" – the length of the circle arc;

"CENTER_X", "CENTER_Y" – the coordinates of the circle center;

"ANGLE" – the angular arc length of the graphic line;

"RADIUS" – the radius of the circle;

 

based on ellipses, splines, 2D paths, offsets and functions:

"LENGTH" – the entity length;

 

for graphic lines constructed as a circular or elliptical arc, portion of spline, 2D path, offset or function, there are following additional parameters:

"START_X", "START_Y" – coordinates of the arc start point;

"END_X", "END_Y" – coordinates of the arc end point;

 

for hatches:

"AREA" – the hatch area

"PERIMETER" – the hatch contour perimeter

"XMASS" - X-coordinate of the center of gravity

"YMASS" - Y-coordinate of the center of gravity

“XAREAMOMENT” – 1x component of inertia moment;

“YAREAMOMENT” – 1y component of inertia moment;

“PRODUCTAREAMOMENT” – Centrifugal inertia moment of area;

“XINERTIARADIUSVALUE” – Radius of inertia X;

“YINERTIARADIUSVALUE” - Radius of inertia Y;

“XAREAMOMENTMAINVALUE” – 1x component of principal moment of inertia relative to mass center;

“YAREAMOMENTMAINVALUE” – 1y component of principal moment of inertia relative to mass center;

“MAINAXESROTATIONVALUE” – Rotation angle of principal axes.

 

for text:

"WIDTH" – the text width

"HEIGHT" - the text height

"X", "Y" – X and Y coordinates of text fixing point;

“TEXT” – text content;

 

for fragments: "string 1" represents the fragment name or Id, "string 2" – the name of the fragment variable. The function returns the value of the variable.

In addition, the following parameters are available for 2D fragments:

“BoundBoxLeft” – left coordinate of bound box (X-coordinate);

“BoundBoxRight” – right coordinate of bound box (X-coordinate);

“BoundBoxTop” – top coordinate of bound box (Y-coordinate);

“BoundBoxBottom” – bottom coordinate of bound box (Y-coordinate);

“BoundBoxCenterX” –X-coordinate of bound box center;

“BoundBoxCenterY” –Y-coordinate of bound box center.

 

In the three-dimensional version of the system, the following 3D element parameters are accessible:

for operations:

"AREA" – the surface area

"MASS" – the mass of the body (material density accounted)

"XMASS", "YMASS", "ZMASS" - X, Y, Z-coordinates of the center of gravity

"IX", "IY", "IZ" – the moments of inertia about the axes X, Y, Z respectively

"IXY", "IYZ", "IZX" – the products of inertia with respect to the planes XY, YZ, ZX

"VOLUME" – volume

 

for "Apply Material" operation the following additional parameter is used:

"MaterialArea" – total area of faces with the attached material;

 

for all 3D Arrays (except arrays of faces) the following additional parameter is used:

"CopyCount" – actual number of copies in the array (with account of limitations and exclusions);

 

for 3D nodes:

"POINTX""POINTY""POINTZ"   - X, Y, Z-coordinates of the 3D node

 

for a 3D profile:

"AREA" – the area of the surface surrounded by the 3D profile

"PERIMETER" – perimeter of a closed 3D profile or length of an open one

 

for a 3D path:

"PERIMETER" – the length of the 3D path

 

for a face:

"AREA" - the area of the face surface

"PERIMETER" - the perimeter of the face border

 

special for a flat face:

"LocationX", "LocationY", "LocationZ" – X, Y, Z-coordinates of the face's underlying plane origin

"NormalX", "NormalY", "NormalZ" – X, Y, Z-coordinates of the normal to the face's underlying plane

"RefDirectionX", "RefDirectionY", "RefDirectionZ" – X, Y, Z-coordinates of the reference vector on the plane (the plane vector defines the direction of the X-axis of a flat plane)

 

special for a cylindrical face:

"RADIUS" – the radius of the cylinder

“Diameter” – cylinder diameter

"CENTERX", "CENTERY", "CENTERZ"   – X, Y, Z-coordinates of the center

"AXISX", "AXISY", "AXISZ"  – X, Y, Z-coordinates of the axis

 

for a toroidal face the following additional parameters are used:

"MaxRadius", "MinRadius" -  major and minor torus radii

"CenterX", "CenterY", "CenterZ" – X, Y, Z-coordinates of the torus center

"AxisX", "AxisY", "AxisZ" – X, Y, Z-coordinates of the torus axis

 

for a spherical face additional characteristics are used:

“Radius” – sphere radius

“Diameter” – sphere diameter

“CenterX”, “CenterY”, “CenterZ” – X, Y, Z-coordinates of sphere center

 

for an edge:

"PERIMETER" – the edge length

"STARTX", "STARTY", "STARTZ"  - X, Y, Z-coordinates of the start point

"ENDX", "ENDY", "ENDZ"  - X, Y, Z-coordinates of the end point

 

special for a straight edge:

"VECTORX", "VECTORY", "VECTORZ"   - X, Y, Z-coordinates of the edge direction

 

for a circular edge or along circular arc:

"Radius" – circle radius

“Diameter” – circle diameter

"CenterX", "CenterY", "CenterZ" – X, Y, Z-coordinate of the circle center

"AxisX", "AxisY", "AxisZ" – X, Y, Z-coordinates of the circle plane normal

"StartAngle" – arc start angle

"EndAngle" – arc end angle

 

special for a elliptical edge:

"MajorRadius" – ellipse major radius

"MinorRadius" – ellipse minor radius

"CenterX", "CenterY", "CenterZ" – X, Y, Z-coordinate of the ellipse center

"AxisX", "AxisY", "AxisZ" – X, Y, Z-coordinates of the normal to the ellipse plane

"MaxDirectionX", "MaxDirectionY", "MaxDirectionZ" – X, Y, Z-coordinates of the ellipse major axis

"MinDirectionX", "MinDirectionY", "MinDirectionZ" – X, Y, Z-coordinates of the ellipse minor axis

"STARTANGLE" – the start angle

"ENDANGLE" - the end angle.

 

for loop:

"Perimeter" – loop perimeter.

 

The parameter names are case-insensitive. If an incorrect element name or parameter name is input, then the function returns 0.

 

Examples:

Get the X-coordinate of a node named NODE_1 by calling the function GET () as follows,

get ( "NODE_1", "X" )

Get the length of a graphic line named IMAGE_1 as follows,

get ( "IMAGE_1", "length" )

Get the perimeter of the contour of the hatch Id 0x9000001 as follows,

get ("0x9000001", "PERIMETER")

Get the volume of the 3D body of a 3D fragment named 3D fragment_11 as follows,

get ("3D fragment_11", "volume")

To compute the total length of a chain of connected graphic lines, one could call the function GET() for each line and sum up the results. However, a more efficient way is to construct a 2D path that follows along the chain of the graphic lines, and create a single graphic line from this path. In this case, the 2D path is considered a spline. Then it is easy to get the length of this single graphic line.

 

Using Functions DISTANCE() and MEASURE()

Function distance() returns the value of distance between two 2D or 3D elements.

The function will be automatically substituted as expression for a variable if such variable is created when measuring distance between two 2D or 3D elements in "PM: Measure Element or relation between two Elements" command.

The calling sequence:

distance ( "name1",  "name2" ), where

 name1 - name or ID of the first element,

 name2 - name or ID of the second element.

Distance can be calculated for the following pairs of 2D or 3D objects:

2D elements – is the distance between a 2D node and another 2D node, construction line, graphic line or hatch (the order of selecting the measurable entities is not significant);

3D objects – is the distance between two arbitrary 3D objects that are 3D construction entities (except for LCS), operations or such topological objects as an edge, loop, face, vertex.

Function distance() also measures distances for such geometrical 3D objects as vertices, edges, loops, faces. This is possible only for already named objects. Naming (e.g. "Vertex_1 or "Edge_2") occurs automatically in "PM: Measure Element or relation between two Elements» or in commands where such objects were specified as source data. These names should be used as input parameters.

Function measure() calculates various relations between two 2D or 3D objects.

The function will be automatically substituted as expression for a variable if such variable is created when measuring any relation (except distance) between two 2D or 3D elements in "PM: Measure Element or relation between two Elements" command.

The calling sequence:

Measure ( "name1", "name2", "relation"), where

 name1 – name or ID of the first element,

 name2 – name or ID of the second element.

 relation – type of  relation.

 

Function calculates the following types of relations:

 

for 2D elements:

"Angle" – is the angle between two lines, segments or a line and a segment.

 

for 3D objects:

"Angle" – is the angle between directional vectors of two 3D objects. Listed below are 3D objects, for which a direction can be defined (and, therefore, this relation can be calculated). Additionally specified is what will be selected as the direction vector for each object:

for a 3D path or open 3D profile lying on a straight line – the line direction;

for a 3D path or open 3D profile lying on an ellipse (circle) – the vector directed from the center of the ellipse (circle) normal to the plane of the ellipse (circle);

for a flat 3D profile; workplane; an operation body consisting of one face lying in a plane – the normal to the plane;

for a cylindrical worksurface; 3D profile lying on a cylinder; an operation body consisting of one face lying on a cylinder – the axis of the cylinder;

for a 3D profile, lying on a cone; an operation body consisting of one face lying on a cone – the axis of the cone;

for a toroidal worksurface; 3D profile or face lying on a torus; an operation body consisting of one face lying on a torus – the axis of the torus.

"AxisDistance" – is the distance between the axis of two 3D objects. The same 3D objects can be selected as the objects of the measurement as in the previous case (when identifying "Angle"), except for workplanes. In the latter case, the axes of the selected objects coincide with the directional vectors of the planes.

DX” – Shift of two 3D nodes or 3D points with respect to each other along the X-axis;

DY” – Shift of two 3D nodes or 3D points with respect to each other along the Y-axis;

DZ” – Shift of two 3D nodes or 3D points with respect to each other along the Z-axis.

Distance” – is the distance between two arbitrary 3D objects that are 3D construction entities (except for LCS), operations or such topological objects as an edge, loop, face, vertex.

GeomDistance” – is the distance between 3D points, 3D curves or surfaces corresponding to two respective 3D objects of the types: 3D node, vertex, edge, face.

MaxDistance” – Maximum distance between two 3D objects (between two points the most distant from each other).

MaxGeomDistance” – Maximum distance between two geometric elements (3D points, 3D curves or surfaces).

Analogous to distance(),  measure() can calculate relations between various topological 3D objects - vertices, edges, loops, and faces,  that were already named earlier in "PM: Measure Element or relation between two Elements" or other commands.

One more additional relation  can be measured for vertices, edges and faces, as well as for a pair "geometrical object – 3D node":

"GeomDistance" – is the distance between 3D points, 3D curves or surfaces corresponding to two respective 3D objects of the types: 3D node, vertex, edge, face.

Input parameters for distance() and measure() functions can be specified using either small or capital letters analogous to get() function. If an incorrect element name or relation name is input, then the function returns 0.

 

Examples:

Distance between two 3D nodes "3D Node_0" and "3D Node_1" can be measured with the following call of distance() function:

distance ( "3D Node_0", "3D Node_1" )

Distance between image line with ID 0x3000014 and 2D node named as "Node 1" will be returned by the following call:

distance ( "0x3000014", "Node 1" )

Axial distance between cylinder axis resulted from extrusion operation named "Extrusion_1" and torus axis from "Rotation_2" operation can be calculated with the following call to measure() function:

measure ("Extrusion_1", "Rotation_2", "AxisDistance")

"PM: Measure Element or relation between two Elements" command is recommended for using distance() and measure() functions. Read more details in chapter "Measure elements and relations between them".

 

Using function CHECK ()

This function searches files by name in certain directories. Specifically, the files are searched in the current directory, and in the directories specified in the command "SO: Set System Options" on the "Folders" tab.

CHECK ("FILE NAME", TYPE)

The file name must be specified with the extension. The file type is defined as follows,

0 – undefined;

1 – T-FLEX CAD document;

2 – font;

3 – database;

4 – pattern;

5 – BOM.

 

Using Functions SETV () and GETV ()

Functions setv() and getv() allow the user to obtain and specify the values of real service characteristics of the T-FLEX CAD documents, such as the number of pages in the document, scale and font size, assigned for each page, coordinates of corners of the title block, volume of all bodies in the 3D scene (if the document contains a 3D model), etc. The values of these characteristics can be used, for example, for transferring data between the assembly drawing and the fragments.

Syntax of Functions

setv("NAME",N)

This function sets the numeric value N for the parameter of the current document NAME.

getv ("NAME",Err)

This function returns the value of the parameter NAME of the current drawing.  Err – the value which will be returned by this function if the indicated parameter is not found.

In multipage document certain characteristics (scale, font size, etc.) are set independently for each page of the document. By default, the functions get() and set() deal with the characteristics of the first page of the document.

To address characteristics of other pages it is required to add “_Page” to the end of the parameter’s name, where “Page” – the name of the desired page.

List of Characteristics of the T-FLEX CAD Document Processed by Function GETV()

Characteristics of 2D pages of Document:

PAGES – total number of pages in current document;

DPAGE – the number of the current drawing’s page;

DPAGES – total number of drawings’ pages in the document;

SCALE – scale of current drawing;

XL – coordinate X of the left border of the drawing;

XH – coordinate X of the right border of the drawing;

YL – coordinate Y of the lower border of the drawing;

YH – coordinate Y of the upper border of the drawing;

FSIZE – font size of the drawing.

LTHICK – thickness of main lines in the drawing.

TLTHICK - thickness of thin lines in the document.

 

Characteristics of 3D scene of Document:

MASS – mass of all bodies in the 3D scene of the current document;

VOLUME – volume of all bodies in 3D scene of the current document;

AREA – surface area of all bodies in 3D scene of the current document;

EXPLODE – state of exploded view mode for the fragments of 3D model of the current document (0 – exploded view mode is turned off, 1 – turned on).

 

Characteristics of fragments calculated from assembly:

_XL – coordinate X of the left border of the assembly drawing when using the current document as a fragment;

_XH – coordinate X of the right border of the assembly drawing when using the current drawing as a fragment;

_YL – coordinate Y of the lower border of the assembly drawing when using the current drawing as a fragment;

_YH – coordinate Y of the upper border of the assembly drawing when using the current drawing as a fragment;

APAGES - returns the total number of pages in the document containing a given fragment;

APAGE - returns the number of the page which contains a given fragment;

BOMPAGES – returns the total number of pages in the BOM of the document containing a given fragment;

BOMPAGE – returns the number of the page of the BOM which contains a given fragment.

The values of these characteristics are calculated for the document-fragment inside the assembly. For example, if in the document of the fragment the user created the variable the value of which is specified by the expression (“apage”, -1), then inside the document of the fragment the value of this variable will be equal to -1, and inside àn assembly document – to the number of the page of the document which contains a given fragment.

 

List of Characteristics of T-FLEX CAD Document Processed by Function SETV()

Characteristics of 2D pages of document:

SCALE – scale of current drawing;

FSIZE – font size of the drawing.

LTHICK – thickness of main lines in the drawing.

TLTHICK – thickness of main lines in the drawing.

_XL, _XH, _YL, _YH, EXPLODE, APAGES, APAGE, BOMPAGES, BOMPAGE parameters are not used in SETV() function.

Examples of Using Functions

getv("SCALE",0) – returns the value of the scale specified for the first page of the current document;

getv("SCALE_Page 2",-1) – returns the value of the scale specified for the page of the current document with the name “Page 2”. If this page is absent in the document, the function returns the value “1”;

getv("mass",0) – returns the value of mass of all bodies in the 3D scene of the current document. If the 3D scene is empty, the function returns the value “0”;

setv("SCALE_Front_0",2) – this functions sets the value of the scale equal to 2 for the page “Front_0” (page of workplane “Front view”);

Using Function TGETV ()

Function tgetv() allows the user to obtain the values of  system’s text characteristics of the current T-FLEX CAD document.

Syntax of functions:

tgetv ("NAME"), where NAME – the name of text parameter of the system or the current document.

Any of the following characteristics can be used as parameter of this function:

USERNAME – Name of current user of the system;

YEAR – Current year;

MONTH – Current month (number);

DAYOFWEEK – Current day of week (number);

DAY – Current day of month (number);

HOUR – Current hour;

MINUTE – Current minute;

SECOND – Current second;

DATE – Current date (the name) in accordance with system’s current settings;

TIME – Current time in accordance with system’s current settings;

REGNAME – User name on whom the system is registered;

REGCOMPANY – Name of company on which the system is registered;

TITLE – Title of current drawing;

SUBJECT – Subject of current drawing;

AUTHOR – Name of author of current drawing;

KEYWORDS – Keywords of current drawing;

COMMENTS – Comment of current drawing;

TEMPLATE – Template of OLE document;

LASTAUTHOR – Name of author who last saved the drawing by;

REVNUM – Number of revision of current drawing;

EDITTIME – Total editing time of current drawing;

PRINTDATE – Date of the last print of current drawing;

CREATEDATE – Date of creation of current drawing;

SAVEDATE – Date of last save of current drawing;

FILENAME – Name of current file (the returned line contains full path to current document and the file name with extension);

SHORTFILENAME – Name of current file (the returned line contains the file name only);

FORMAT – Title block of current drawing;

_FORMAT - Format name for the drawing of the page on which the current fragment is inserted;

SCALE – Scale of current drawing.

_SCALE - Scale for the drawing of the page on which the current fragment is inserted

SCALEVALUE – Scale of the current drawing (the returned string contains the value of the scale without the letter М)

_SCALEVALUE – Scale of the drawing’s page onto which the current fragment is inserted (the returned string contains the value of the scale without the letter М).

Example of using the function tgetv:

$TIME = tgetv ("TIME")