Skip to main content

KnowledgeBase

Main functions

Calculation

runCalcMethod()
Table 18. This function executes a calculation method (objective).

runCalcMethod(methodID, compID);

Parameter

Type

Description

methodID

string

Unique ID of the calculation method to run. A list of all calculation methods can be found in the section Calculations in scripting.

compID

int

Unique ID of the component in the model.

The system calculation is always performed on the gear unit (always has ID 1).

{options}

object

If specified, an output directory with the calculation kernel output files is created.

var options = {resultpath: path/to/results, createResultpath: true/false};

Return value

int

1 = calculation successful

0 = calculation terminated

-1 = error in the calculation

Possible errors

Calculation does not exist.

Component does not exist.

Component cannot be calculated with the specified calculation method.



Example 1 Perform a system calculation

1methodID = "001_SYSTEM_CALCULATION";
2var compID = 1;
3setAttr("gta_switch_iso_6336_2006", compID, true, EDAT);
4var status = runCalcMethod(methodID, compID);
5if (status == 1) {
6    println("Calculation was successful");
    } else {
7  println("Something went wrong");
    }

1

Assigns the ID for a system calculation to the methodID variable.

2

Assigns the ID of the gear unit to the compID variable. The ID of the gear unit is always 1.

3

Uses setAttr() to set the attribute with the ID "gta_switch_iso_6336_2006" to true. This will perform a load capacity calculation according to ISO 6336 (2996) as part of system calculation.

4

Starts the system calculation and stores the return value in the status variable.

5

If the return value in the status value = 1, then:

6

Output to the scripting console: "Calculation was successful."

7

For any other return value: "Something went wrong."

Example 2 Perform a bearing life calculation for a single bearing.

methodID = "800_ROLLING_BEARING_LIFETIME";
var compID = 15;
runCalcMethod(methodID, compID);

Accessing attributes

getAttr()
Table 19. This function returns the value of an attribute.

getAttr(attrID, compID, EDAT/RDAT);

Parameter

Type

Description

attrID

string

Unique ID of the attribute.

compID

int

Unique ID of the component in the model.

EDAT/RDAT

Specifies whether the input (EDAT) or calculated value (RDAT) should be returned.

Alternatively, 1 (EDAT) or 0 (RDAT) can be specified as a parameter.

For more information, see Data integrity (EDAT/RDAT)

Return value

Value of the attribute.

Possible errors

Incorrect Attribute ID or component ID.

Only for string, integer, double, boolean, array, and matrix attributes.



Example 1 Output the value of the normal pressure angle attribute to the console.

1let compID = getCompByType('cylindrical_mesh')[0];
2let value = getAttr("normal pressure angle", compID, EDAT);
3println(value);

1

Assigns the component ID of the first cylindrical gear stage in the model to the compID variable.

2

Assigns the input value (EDAT) of the normal pressure angle attribute to the value variable.

3

Outputs the value of the variable to the Scripting Monitor.

Example 2 Output the values of the static load rating array attribute to the console.

1let compID = getCompByType('bearing')[0];
2let value = getAttr("static capacity", compID, RDAT);
3println(value[0]);
4println(value[1]);

1

Assigns the component ID of the first rolling bearing in the model to the compID variable.

2

Assigns the calculated value (RDAT) of the static capacity attribute to the value variable.

static capacity is an array attribute and contains a value for every bearing row.

3

Outputs the attribute value for the first bearing row to the Scripting Monitor.

4

Outputs the attribute value for the second bearing row to the Scripting Monitor.

setAttr()
Table 20. This function sets the value of an attribute.

setAttr(attrID, compID, value, EDAT/RDAT);

Parameter

Type

Description

attrID

string

Unique ID of the attribute.

compID

int

Unique ID of the component in the model.

EDAT/RDAT

Specifies whether the input (EDAT) or calculated value (RDAT) should be returned. Alternatively, 1 (EDAT) or 0 (RDAT) can be specified as a parameter.

Possible errors

Incorrect Attribute ID.

Incorrect component ID.

Data type of the value does not match the attribute.

Value violates the constraints.



Example 1 Set the value of the oil temperature attribute to 90.

1var compID = 1;
2setAttr('temperature', compID, 90, EDAT);

1

Assigns the variable compID with the component ID of the gear unit. As the root component, the gear unit always has the ID of 1.

2

Assigns the attribute temperature of component 1 with the input value (EDAT).

Example 2 Set the attribute FVA_54 to true. The attribute FVA_54 corresponds to the "Calculation of micro pitting acc. to FVA 54" switch in the input editor.

1var compID = getCompByType('cylindrical_mesh')[0];
2setAttr('FVA_54', compID, true, EDAT);

1

Assigns the component ID of the first cylindrical stage to the compID variable.

2

Sets attribute FVA_54 to true (EDAT).

delAttr()
Table 21. This function deletes the input value (EDAT) of the attribute.

delAttr(attrID, compID);

Parameter

Type

Description

attrID

string

Unique ID of the attribute.

compID

int

Unique ID of the component in the model.

Return value

boolean

true if value deleted, otherwise false.

Possible errors

Incorrect component ID.

Incorrect attribute ID.



Example 1 Delete the lubricant attribute of the gear unit.

1delAttr('lubricant', 1);

1

Deletes the lubricant for the component gear unit.

getAttrProperty()
Table 22. This function returns the name, type, unit, or symbol of an attribute.

getAttrProperty(attrID, compID, propertyID);

Parameter

Type

Description

attrID

string

Unique ID of the attribute in the model.

compID

int

Unique ID of the component in the model.

propertyID

string

TYPE

Data type of the attribute.

NUMBER

Numeric attribute ID.

NAME

Attribute name

UNIT_NAME

Unit

SYMBOL

Symbol

EDAT_VALUE

EDAT value converted to string.

RDAT_VALUE

RDAT value converted to string.

Return value

Property of the attribute in the language in which the FVA-Workbench was started.

Possible errors

Incorrect component ID

Incorrect attribute ID

Attribute and component ID do not match.



Example Query the properties of the "face width" attribute on a cylindrical gear with ID 8.

1var compID = 8;
2var attributeID = 'face width';
3println('Name: ' + getAttrProperty(attributeID, compID, 'NAME'));
4println('Unit: ' + getAttrProperty(attributeID, compID, 'UNIT_NAME'));
5println('Symbol: ' + getAttrProperty(attributeID, compID, 'SYMBOL'));
6println('Value: ' + getAttrProperty(attributeID, compID, 'RDAT_VALUE'));

1

Assigns the component with ID 8 to the compID variable.

2

Assigns the ID of the face width attribute to the attributeID variable.

3

Outputs the name of the attribute to the scripting console.

4

Outputs the unit of the attribute to the scripting console.

5

Outputs the symbol of the attribute to the scripting console.

6

Outputs the output value of the attribute to the scripting console.

Accessing components

getCompProperty()
Table 23. This function delivers the name or type of a component.

getCompProperty(compID, propertyID);

Parameter

Type

Description

compID

int

Unique ID of the component in the model

propertyID

string

TYPE - component type (e.g., cylindrical_mesh)

NAME - component name

Return value

string

Property of the component

Possible errors

Incorrect component ID



Example 1 Output a component name and type to the scripting console.

1var compID = 3;
2println(getCompProperty(compID,'TYPE'));
3println(getCompProperty(compID,'NAME'));

1

Assigns a value of 3 to the compID variable.

2

Outputs the component type of component 3 to the scripting console.

3

Outputs the component name of component 3 to the scripting console.

Notice

In earlier versions of the FVA-Workbench, the properties IDENT_NO and DRAWING_NO could be queried via getCompProperty().

The drawing number (comp_drawing_number) and Ident number (comp_ident_number) are now attributes of the respective component and can be set or read via setAttr() and getAttr().

Example for reading the number of a drawing: getAttr("comp_drawing_number", 3, EDAT);

setCompProperty()
Table 24. This function can be used to change the name of a component.

setCompProperty(compID, propertyID);

Parameter

Type

Description

compID

int

Unique ID of the component in the model

propertyID

string

NAME - name of the component

Possible errors

Incorrect component ID



Example Change the name of a component.

var compID = 3;
setCompProperty(compID, "NAME", "New component name");
getCompByType()
Table 25. This function returns a list (array) of all component IDs of a certain type. If the model does not include any components of the specified type, an empty array (length = 0) is returned.

getCompProperty(compType);

Parameter

Type

Description

compType

string

Component type (e.g., "bearing")

Return value

array

Array of component IDs

Possible errors

Component type does not exist.



Example 1 Set the input type for all rolling bearings in the model to "rigidity."

1let bearings = getCompByType("bearing");

2for (i=0; i < bearings.length; i++){
3	setAttr("bearing data type", bearings[i], 2, EDAT);
    }

1

Assigns the variable bearings with an array of all rolling bearing IDs in the gear unit.

2

for loop that runs once for each element in the array.

3

Sets the attribute "input type " for each bearing to "rigidity" (value =2, see data type: combo attributes).

getSubComponents()
Table 26. The getSubComponents function can be used to query sub-components or connected components via scripting. The return value is an array with the component IDs of the sub-components.

getSubComponents(compID, subCompType);

Parameter

Type

Description

compID

int

ID of the main component

subCompType

string

Component type of the sub-component to be queried e.g., "cylindrical_mesh".

Return value

array

Array of the ID's of the sub-components. If there are no sub-components, an empty array will be returned.

Possible errors

The queried component type does not exist on the main component.

The main component does not exist.



Example 1 Query a cylindrical stage

1var stageID = 3;
2var gearIDs = getSubComponents(stageID, "general_gear");
3println(gearIDs[0]);
4println(gearIDs[1]);

1

Variable stageID includes the ID of the cylindrical stage.

2

getSubComponents() writes an array with the ID's of both cylindrical gears to the gearIDs variable.

3

Writes the ID of the first cylindrical gear to the console.

4

Writes the ID of the second cylindrical gear to the console

Querying sub-components
Table 27. The following stage components can be queried

Component

Exactly what is queried

getSubComponents(...)

Gears

All gears in a stage

stageID, "general_gear"

Specific gear type, e.g. bevel gear

stageID, "bevel_or_hypoid_gear"

Shafts

All shafts in a stage

stageID, "shaft"



Table 28. The following gear components can be queried

Component

Exactly what is queried

getSubComponents(...)

Modification

Modification for certain gear types.

gearID, "gear_correction"

Shaft

Shaft on which the gear sits.

gearID, "shaft"

Mating gears

All mating gears that mesh with the gear.

gearID, "general_gear"

Stages

All stages in which the gear appears.

gearID, "general_stage"

Stage-related gear data

More information

Abstract component that includes the mesh-related data of a gear (e.g., pitch diameter).

gearID, "stage_gear_data"

If a gear is engaged in multiple meshes, returns a component of type stage_gear_data for each mesh.

gearID, "stage_gear_data", "STAGEID=3"

If the ID of the stage is given as an option (here, a stage with ID 3), only the component of type stage_gear_data that belongs to the specified stage is returned.



Table 29. The following shaft components can be queried

Component

Exactly what is queried

getSubComponents(...)

Stages

All stages in which the shaft is present.

shaftID, "general_stage"

Gears

All gears on the shaft

shaftID, "general_gear"

Specific gear type, e.g., bevel gear

shaftID, "bevel_or_hypoid_gear"

Rolling bearings

All rolling bearings connected with the shaft.

shaftID, "bearing", "ANY"

Rolling bearings that sit on the shaft.

shaftID, "bearing", "OUTER"

Rolling bearings that sit in the shaft.

shaftID, "bearing", "INNER"

Plain bearings

All plain bearings connected with the shaft

shaftID, "slide_bearing", "ANY"

Plain bearings that sit on the shaft.

shaftID, "slide_bearing", "OUTER"

Plain bearings that sit in the shaft.

shaftID, "slide_bearing", "INNER"

Load

All load components (forces) on the shaft

shaftID, "force"

Notch

All notches on the shaft

shaftID, "notch"

Shaft contour

All contours

shaftID, "contour", "ANY"

All outer contours

shaftID, "contour", "OUTER"

All inner contours

shaftID, "contour", "INNER"

Feather key

All feather keys on the shafts

shaftID, "feather_key", "ANY"

All feather keys for which the shaft is the inner part.

shaftID, "feather_key", "INNER"

All feather keys for which the shaft is the outer part.

shaftID, "feather_key", "OUTER"

Tapered interference fit

All tapered interference fits on the shaft

shaftID, "cone_interference_fit", "ANY"

All tapered interference fits for which the shaft is the inner part.

shaftID, "cone_interference_fit", "INNER"

All tapered interference fits for which the shaft is the outer part.

shaftID, "cone_interference_fit", "OUTER"

Multiple interference fit

All multiple interference fits on the shaft

shaftID, "multiple_interference_fit", "ANY"

All multiple interference fits for which the shaft is the inner part.

shaftID, "multiple_interference_fit", "INNER"

All multiple interference fits for which the shaft is the outer part.

shaftID, "multiple_interference_fit", "OUTER"

Cylindrical interference fit

All cylindrical interference fits on the shaft

shaftID, "interference_fit", "ANY"

All cylindrical interference fits for which the shaft is the inner part.

shaftID, "interference_fit", "INNER"

All cylindrical interference fits for which the shaft is the outer part.

shaftID, "interference_fit", "OUTER"

Spline connection

All spline connections on the shaft

shaftID, "spline_connection"

All spline shafts on the shaft

shaftID, "spline_shaft"

All spline hubs on the shaft

shaftID, "spline_hub"Ko

Coupling

All couplings on the shaft

shaftID, "clutch"



Table 30. The following rolling bearing components can be queried

Component

Exactly what is queried

getSubComponents(...)

Connected components

All components connected with the rolling bearings

bearingID, "default", "ANY"

Components connected with the inner ring

(shafts or casings)

bearingID, "shaft", "INNER"

bearingID, "gear_casing" ,"INNER"

Components connected with the outer ring

(shafts or casings)

bearingID, "shaft", "OUTER"

bearingID, "gear_casing" ,"OUTER"

Bearing rows

Bearing rows are result components that can only be queried after a successful calculation.

bearingID, "bearing_row"



Table 31. The following plain bearing components can be queried

Component

Exactly what is queried

getSubComponents(...)

Connected components

All components connected with the plain bearing

slideBearingID, "default", "ANY"

Components connected with the inner ring

(shafts or casings)

slideBearingID, "shaft", "INNER"

slideBearingID, "gear_casing" ,"INNER"

Components connected with the outer ring

(shafts or casings)

slideBearingID, "shaft", "INNER"

slideBearingID, "gear_casing" ,"INNER"

Segments

Segments, hydrostatic and hydro dynamic pockets are result components that can only be queried after a successful calculation.

slideBearingID, "slide_bearing_segment"

Hydrostatic pockets

slideBearingID, "hydrostatic_pocket"

Hydrodynamic pockets

slideBearingID, "hydrodynamic_pocket"



Table 32. The following planetary stage components can be queried

Component

Exactly what is queried

getSubComponents(...)

Cylindrical gear stages

All cylindrical stages in the planetary stage

planetaryStageID, "general_stage"

Only the inner stage

planetaryStageID, "general_stage", "INNER"

Only the outer stage

planetaryStageID, "general_stage", "OUTER"

Gears

All gears in the planetary stage

planetaryStageID, "general_gear"

Sun gear

planetaryStageID, "general_gear", "SUN_GEAR"

Planet gear

planetaryStageID, "general_gear", "PLANET_GEAR"

Ring gear

planetaryStageID, "general_gear", "RING_GEAR"

Shafts

All shafts in the planetary stage

planetaryStageID, "shaft"

Sun shaft

planetaryStageID, "shaft", "SUN_SHAFT"

Planet shaft

planetaryStageID, "shaft", "PLANET_SHAFT"

Ring shaft

planetaryStageID, "shaft", "RING_SHAFT"

Carrier shaft

planetaryStageID, "shaft", "RIM_SHAFT"

Planet carrier

One-sided planet carrier

planetaryStageID, "one_sided_planet_carrier"

Two-sided planet carrier

planetaryStageID, "two_sided_planet_carrier"

Pins

planetaryStageID, "planet_pin"

Instances

More information

Cylindrical gear stage in the planetary stage

stageID, "planet_instance"

Planetary gear

planetGearID, "planet_instance"

Planet carrier

planetBearingID, "planet_instance"

Pins

planetPinID, "planet_instance"

Coupling

couplingID, "planet_instance"



Table 33. Additional components that can be queried

Component

Exactly what is queried

getSubComponents(...)

Notch

Shaft on which the notch is located.

notchID, "shaft"

Load

Shaft on which the load component is located.

forceID, "shaft"

Spline connection

Shafts that are connected to each other by the spline connection.

splineConnectionID, "Shaft"

Gears that make up the spline connection.

splineConnectionID, "general_gear"



addSubComponent()
Table 34. Directly connected sub-components can be added to the primary components with the addSubComponent() function.

addSubComponent(baseCompID, compType, {options});

Parameter

Type

Description

baseCompID

int

ID of the primary component to which the sub-component should be added.

compType

string

Component type of the sub-component to be added. The following types are available:

  • Notch on a shaft -> addSubComponent(shaftID, "notch");

  • Load on a shaft -> addSubComponent(shaftID, "force");

  • Shaft section on a shaft -> addSubComponent(shaftID, "contour");

  • Modification on a cylindrical gear -> addSubComponent(gearID, "gear_correction");

{options}

object

The following additional options are available for shaft contours.

If no options are specified, shaft sections are added as outer contours from the left.

Shaft inner/outer contour

side: inner/outer

Specification of shaft contour from left/right

direction: left/right

Return value

int

ID of the newly added component

Possible errors

The primary component does not exist.

The sub-component type cannot be added to the primary component.



Note

Adding or deleting components may take some time, especially for large models, as the 3D model is updated each time.

Transaction mode can be enabled before the addSubComponent() call to speed up the process.

Example 1 Add a notch on a shaft and assign the basic attributes

1let shaftID = 3;
2let notchID = addSubComponent(shaftID, "notch");

3setAttr("notch kind", notchID, 6, EDAT);
4setAttr("position", notchID, 6, EDAT);
5setAttr("notch width", notchID, 5, EDAT);
6setAttr("notch radius", notchID, 2, EDAT);
7setAttr("depth", notchID, 2, EDAT);
8setAttr("surface roughness", notchID, 10, EDAT);

1

The shaftID variable includes the ID of the shaft on which the notch should be added.

2

Adds a new component of type "notch" on shaft 3 via addSubComponent(). The return value of the function, the ID of the new notch, is saved in the notchID variable.

3

Sets the "notch form" combo attribute for the new notch to 6 via setAttr(). The value 6 corresponds to a rectangular notch. (See image for additional options)

notch_kind_combo.png

4

Sets the position of the notch.

5

Sets the width of the notch.

6

Sets the radius of the notch.

7

Sets the depth of the notch.

8

Sets the surface roughness R_z of the notch.

Example 2 Add a contour to an existing shaft

var shaftID = 3;
var nbrOuterContours = 3;
var nbrInnerContours = 2;
var outerContourIDs = [];
var innerContourIDs = [];
var outerContourlenght = [30, 50, 20];
var innerContourlenght = [40, 80];
var outerContourDiameters = [30, 50, 25];
var innerContourDiameters = [10, 20];

for (let i = 0; i < nbrOuterContours; i++){
  let options = {};
  outerContourIDs.push(addSubComponent(shaftID, "contour",{side: "outer", direction: "left"}));
}
for (let i = 0; i < nbrInnerContours; i++){
    innerContourIDs.push(addSubComponent(shaftID, "contour",{side: "inner", direction: "left"}));
}
for(let i = 0; i < nbrOuterContours; i++){
    setAttr("length",             outerContourIDs[i], outerContourlenght[i], EDAT);
    setAttr("beginning diameter", outerContourIDs[i], outerContourDiameters[i], EDAT);
    setAttr("end diameter",       outerContourIDs[i], outerContourDiameters[i], EDAT);
}
for(let i = 0; i < nbrInnerContours; i++){
    setAttr("length",             innerContourIDs[i], innerContourlenght[i], EDAT);
    setAttr("beginning diameter", innerContourIDs[i], innerContourDiameters[i], EDAT);
    setAttr("end diameter",       innerContourIDs[i], innerContourDiameters[i], EDAT);
}
deleteSubComponent()
Table 35. Sub-components can be deleted via the deleteSubComponent() function.

deleteSubComponent(baseCompID, compID);

Parameter

Type

Description

baseCompID

string

ID of the primary component from which the sub-component should be deleted.

compType

string

ID of the component to be deleted.

Possible errors

The primary component does not exist.

The sub-component does not exist.



Example Delete a load component from a shaft

var shaftID = 4;
var forceID = 10;

deleteSubComponent(shaftID, forceID);
addDbComponent()
Table 36. Database components from the Global Database can be added to the model with this function.

addDbComponent(dbType, entryId);

Parameter

Type

Description

dbType

string

Type of the database component to be added.

  • Lubricant -> "lubricant"

  • Material -> "material"

  • Tool -> "tool"

  • Load spectrum -> "spectrum"

  • Wöhler SN curve -> "sn_curve"

  • Resistance characteristic curve dataset -> "resistance_characteristic_data_curve"

  • Measurement series -> "data_curve"

  • Coefficient of friction -> "friction_coefficient"

entryId

string

Unique ID of the database component in the database.

Return value

string

ID of the newly added component

Possible errors

Incorrect database type

Database entry does not exist



Example Add the material 16MnCr5 as a component to the model and allocate it to a cylindrical gear

gearID = 8;
var materialID = addDbComponent("material", "16MnCr5");
setAttr("material", gearID, materialID, EDAT);
deleteDbComponent()
Table 37. This function can be used to delete database components from the model.

deleteDbComponent(compId);

Parameter

Type

Description

compId

string

ID of the database component to be deleted.

Possible errors

Database component does not exist in the model.



Example Delete the database component with the ID 120

deleteDbComponent("120");
refreshDbComp()
Table 38. This function updates a component from the Global Database.

refreshDbComp(dbCompID);

Parameter

Type

Description

dbCompID

int

Unique ID of the database component in the model

Possible errors

Database component does not exist in the model.



Example 1 Update the component with the ID 22 with data from the Global Database.

refreshDbComp(22);

Output

generateReport()
Table 39. This function generates an HTML report from the calculation results for the current model using a specified report template. Existing files will be overwritten.

generateReport(templateFile, outputFile, {options});

Parameter

Type

Description

templateFile

string

Path + name of the report template file

outputFile

int

Path + name of the HTML file

{options}

object

Single-column layout

compactView:true/false

Language

language: "de"/"en"

Hierarchical model tree

completeTree: true/false

Navigation bar

navigationBar: true/false

Calculation messages

notifications: true/false

Possible errors

Access restrictions on folders/files

Missing report template



Notice

The getPredefinedReportTemplate(SYSTEM_REPORT); feature can be used to query the path to the pre-defined "system report" template.

To create reports from model snapshots see Model snapshots in scripting.

Example 1 Generate an HTML report

1var templateFile = "C:\\template.wbrep";
2var outputFile = "C:\\output\\report.html";
3var options = {compactView: false, 
                   language: "de", 
                   completeTree: false, 
                   notifications: true, 
                   navigationBar: true};
4generateReport(templateFile, outputFile, options);

1

Path to report template

2

Path where the output report will be generated

3

Options to be considered when generating the report

4

Function for generating the report

Example 2 Create an HTML report with the pre-defined system report template

var templateFile = getPredefinedReportTemplate(SYSTEM_REPORT);
var outputFile = "C:\\output\\report.html";
generateReport(templateFile, outputFile);
println()
Table 40. This feature writes data to the scripting console. A break is added to the end of each line. If no line break is added, the print() function can be used.

println(data);

Parameter

Type

Description

data

any

Data to be output to the scripting console.

Possible errors

Missing Component ID

Missing Attribute ID



Example 1

1var text = "This is text";
2var array = [1, 2.2, 3, 4];
3println(text);
    for (i=0; i<array.length; i++){
4     println(array[i]);
    }

1

Assigns a string to a text variable.

2

Assigns an array of multiple numbers to an array variable.

3

Outputs the text variable to the scripting console.

4

for-loop that goes through each entry in the array and writes the number to the scripting console.

alert()
Table 41. This function outputs a message as a dialog. The program waits until the user confirms the message with [OK].

alert(data);

Parameter

Type

Description

data

any

Text or data to be shown in the dialog.



Example 1 Output text as a message.

var text = "This is a message. Click OK to continue."
alert(text);
alertbox.png

Example 2 Output multiple messages in a loop.

1for (i = 0; i < 5; i++){
2    alert("This is the " + i + ". run"); 
     }

1

for loop in which the run variable i is increased from 0 to 4.

2

Outputs i as a message.

User input

prompt()
Table 42. This function creates an input dialog with text. This can be used to request data from the user when the script is run. These files can then be further processed in the script.

prompt(data);

Parameter

Type

Description

data

any

Text or data to be displayed as text in the input dialog.



Example 1 Request torque from the user and set the attribute value of the load component accordingly.

1var forceID = 20;
2var torque = prompt("Please enter input torque");
3setAttr("scaled torque", forceID, torque, EDAT);

1

Assigns the variable forceID with the ID of a load component.

2

Writes the return value of the prompt() function to the torque variable.

3

Sets the input value (EDAT) of the torque attribute for load component 20 to the value in specified in the dialog box.

promptbox.png
promptFile()
Table 43. Displays a file selection dialog, which requires the user to enter a filename. Optional parameters can be used to specify a default file path and to suggest a file name and dialog type.

promptFile({options})

Parameter

Type

Description

{options}

object

directory - default file path

filename - suggested file name

type - type of dialog: open ("open") or save ("save"). Default: "open"



Note

This function can only be used in GUI operation, not in batch operation.

Example 1 Write text to a file selected by the user.

1let options = {directory: "c:/example", filename: "myfile.txt", type: "save"};
2let path = promptFile(options);
3let text = "This Text will be written to the ASCII File";
4writeToFile(path, text, "c", "UTF-8");

1

Options for the file selection dialog

2

Opens a file selection dialog in the c:\example directory and writes the selected path and filename to the path variable.

3

Text to be written to the output file.

4

Writes the text to the specified file.

promptDirectory()
Table 44. Displays a folder selection dialog. The optional baseDirectory parameter can be used to specify a standard directory.

promptDirectory(baseDirectory);

Parameter

Type

Description

data

string

Specification of a predefined path

If no parameter is specified, the most recently selected directory is displayed.



Note

This function can only be used in GUI operation, not in batch operation.

Example 1 Write a text file to a user-selected directory.

1let directory = promptDirectory("c:/example");
2let filename = "text.txt";
3let path = directory +"/"+ filename;
4let text = "This Text will be written to the ASCII File";
5writeToFile(path, text, "c", "UTF-8");

1

Opens a directory selection dialog and writes the selected path to the directory variable. C:\example is selected by default.

2

Stores the name of the output file in the filename variable.

3

Assembles the strings into a complete file path and stores it in the path variable.

4

Text to be written in the output file.

5

Writes the text to the specified file.

promptSelect()
Table 45. Creates a dialog with a drop-down selection list, which can be used to request data from the user while the script is running. This data can then be processed in the script.

promptFile(baseDirectory)

Parameter

Type

Description

caption

string

Text shown above the drop down list

dropDownEntries

array of strings

Array of strings: each string corresponds to an entry in the drop down list.



Note

This function can only be used in GUI operation, not in batch operation.

Example 1 Query the user for criteria for the proposed modification and set the corresponding attribute in the FVA-Workbench.

attribute_overview_mod_criterion.png

The possible values for the "3D load distribution tooth modification criterium" combo attribute can be seen in the attribute overview.

1let dropDownEntries = [
                           "Linear increase in pressure", 
                           "Uniform pressure distribution", 
                           "Linear increase of line loads", 
                           "Uniform line loads"
                          ];
2let modCriterion = promptSelect("Select modification criterion for 3d loaddistribution", dropDownEntries);

3switch (modCriterion) {
        case "Linear increase in pressure":   modCriterion = "0"; break; 
        case "Uniform pressure distribution": modCriterion = "1"; break;
        case "Linear increase of line loads": modCriterion = "2"; break;
        case "Uniform line loads":            modCriterion = "3"; break;
        default: break; 
    };

4setAttr("modification_criterion_load_distribution_3d", 1, modCriterion, EDAT);

1

Writes the selection options for the drop-down menu as a string array to the dropDownEntries variable.

2

Opens the drop-down dialog; the return value is written to the modCriterion variable.

3

The switch case statement assigns a valid value for the "modification_criterion_load_distribution_3d" attribute to the strings selected by the user.

4

Sets the input value for the "modification_criterion_load_distribution_3d" attribute in the FVA-Workbench.

drop_down_window.png

Export

exportModel()
Table 46. This function can be used to export the model in various formats. The file extension determines the format to be exported. Additional options can be specified for a REXS export. Existing files will be overwritten.

exportModel(fileName, {options});

Parameter

Type

Description

fileName

string

Path + name of the model file. The following file extensions are supported:

.wbpz

.wbpx

.wbps

.rexs (xml)

.rexsj (json)

{options}

(Only for REXS export)

object

DataClass

Determines whether EDAT or RDAT should be written. If the RDAT data is not valid, EDAT will automatically be written. (EDAT/RDAT)

Version

Specifies the version of the REXS specification to be used. (1.0/1.1/1.2/1.3/1.5)

Possible errors

The user does not have write permissions to the specified directory.



Example 1 Export the file model.wbpz to the C:\temp directory.

exportModel("C:\\temp\\model.wbpz");

Example 2 Export the model in REXS format (version 1.3)

1var options = {DataClass: "RDAT", Version: 1.3};
2exportModel("C:\\temp\\model.rexs", options);

1

Variable options that contain .rexs specific information.

2

Exports the model via exportModel(), including options.

exportGdeFile()
Table 47. Exports a cylindrical gear from the model to a GDE file. The file extension must be xml.

exportGdeFile(fileName, {options});

Parameter

Type

Description

fileName

string

Path + Name of the xml file

gearID

string

ID of the gear in the model

{options}

object

GdeVersion

"2.5.0" | "3.4.0"

DatumnFaceIsLargerUSide

true | false

ExportConfig

"GDE Export Config 1"

"GDE Export Config 2"

"GDE Export Config 3"

"GDE Export Config 4"

Possible errors

The user does not have write permissions to the specified directory.

The specified version does not exist.

The specified gearID does not exist in the model.



Example 1 Export GDE file

let fileName = "C:\\temp\\testGDE.xml";
let gearId = "8";
let exportOptions = {GdeVersion : "3.4", DatumnFaceIsLargerUSide: false, ExportConfig: "GDE Export Config 1"};

try {let returnCode = exportGdeFile(fileName, gearId, exportOptions);	
    if (returnCode==1)
        println("GDE Export successful");} 
catch (exception_text) {        
    alert(exception_text);
}
exportCAD()
Table 48. Exports gearbox components in various CAD formats.

exportCAD(filepath, {options});

Parameter

Type

Description

filepath

string

Path + name of the CAD file

{options}

object

CompIds

Assembled components such as cylindrical stages cannot be exported. The shafts and gears of the stage must be explicitly specified for the export.

A list of all gearbox components to be exported. ID = 1 (gear unit) exports the entire gearbox model. Duplicate IDs are ignored.

CADFormat

The following formats can be exported:

  • STEP

  • IGES

  • CATIA V4

  • CATIA V5

  • VDA-FS

  • SAT

Possible errors

The user does not have write permissions to the specified path.

The specified component cannot be exported (e.g., lubricant).



Example 1 Export the complete gearbox as a STEP file

let filepath = "c:/output/cadmodel.step";
let options = {"CompIds": [1],
               "CADFormat": "STEP"
              };
exportCAD(filepath, options);

Example 2 Export all shafts and gears of a gearbox model as an IGES file

let filepath = "c:/output/cadmodel.iges";
let gearIds = getCompByType("gear");
let shaftIds = getCompByType("shaft");
let componentsToExport = gearIds.concat(shaftIds);
let options = {"CompIds": componentsToExport,
               "CADFormat": "IGES"
              };
exportCAD(filepath, options);
exportCADGear()
Table 49. Exports a single cylindrical gear, including microgeometry (modifications) in various CAD formats.

exportCADGear(filepath, {options});

Parameter

Type

Description

filepath

string

Path + name of the CAD file

{options}

object

CompId

ID of the cylindrical gear

CADFormat

The following formats can be exported:

  • STEP

  • IGES

  • CATIA V4

  • CATIA V5

  • VDA-FS

  • SAT

NumberOfSupportingPointsWidth

The number of supporting points in the width direction is equidistant and has a significant influence on the accuracy with which the flank modifications can be exported. The accuracy of the linear interpolation between the support points depends on the shape and amount of the modification. For example, if a short end relief with a large modification amount is to be specified, the number of support points should be increased.

Possible errors

The user does not have write permissions to the specified path.

The specified component is not a cylindrical gear.



Example Export a cylindrical gear, including modifications

let filepath = "c:/output/cadmodel.step";
let gearId = [6];
let options = {"CompId": gearId,
               "CADFormat": "STEP",
               "NumberOfSupportingPointsWidth": 20
              };
exportCADGear(filepath, options);
exportImage()
Table 50. Exports transmission components as an image.

exportImage(filepath, {options});

Parameter

Type

Description

filepath

string

Path + name of the image file

{options}

object

CompIds

List of all transmission components that should be included in the image.

ID = 1 (gear unit) exports the entire gear model as an image. Duplicate IDs are ignored.

Composite components such as gear stages cannot be exported as an image. The shafts and gears of the stage must be explicitly specified for export.

size

Image resolution

SMALL

640x480

MEDIUM

800x600

LARGE

1280x720

VERY LARGE

1920x1080

orientation

Orientation of the transmission components in the picture.

  • LEFT

  • RIGHT

  • FRONT

  • BACK

  • TOP

  • BOTTOM

  • ISO

showDeformation

Boolean that decides whether the gear components are displayed deformed.

Possible errors

The user does not have write permissions to the specified path.

The specified component cannot be exported as image (e.g., lubricant).



Example 1 Export the complete gearbox as an image file

let filepath = "c:/output/transmission.jpg";
let options = {"CompIds": [1],
               "orientation" : "ISO",
               "size": "SMALL",
               "showDeformation": true
              };
exportImage(filepath, options);

Example 2 Export all shafts and gears of a gear model as an image file

let filepath = "c:/output/shafts_and_gears.jpg";
let gearIds  = getCompByType("gear");
let shaftIds = getCompByType("shaft");
let componentsToExport = gearIds.concat(shaftIds);
let options = {"CompIds": componentsToExport,
               "orientation" : "ISO",
               "size": "LARGE",
               "showDeformation": false
              };
exportImage(filepath, options);

Read & Write

readFile()
Table 51. Imports files in ASCII format. The file is read line-by-line and saved to an array.

readFile(path);

Parameter

Type

Description

path

string

Path + name of the file

Return value

array

Contents of the file in a string array

Possible errors

File does not exist or access is denied.

File is in binary format.



Example 1 Import a text file and output it to the scripting console

1var path = "c:\\textfile.txt";
2var text = readFile(path);

3for (i = 0; i < text.length; i++){
4    println(text[i]);
5    println(parseFloat(text[i])+ parseFloat(text[i]));
     }

1

Assigns the path variable with the path to the text file.

2

Uses readFile() to assign the text variable with an array with a number of entries equal to the number of lines in the textfile.txt file.

3

For loop which increases the counting variable i from 0 to text.length (number of lines in the text file).

4

Outputs every line of the text file to the scripting console.

5

Uses parseFloat() to convert every array entry in the text variable to a floating point number which can then be used for further calculations. If the array entry does not contain a number that can be converted, parseFloat() returns NaN (Not a Number) as a value.

readFileAsString()
Table 52. Reads files in ASCII format and writes the content to a string.

readFileAsString(path);

Parameter

Type

Description

path

string

Path + name of the file

Return value

string

Content of the file in a string

Possible errors

File does not exist or access is denied.

File is in binary format.



Example 1 Read text file as string

1var path = "c:\\textfile.txt";
2var text = readFileAsString(path);
writeToFile()
Table 53. This function writes text to a file. If the specified folder does not exist, it will be created.

writeToFile(path, text, mode, encoding);

Parameter

Type

Description

path

string

Path + name of the text file

Relative paths can also be specified. In this case, the parent directory is the directory where the FVA-Workbench is installed.

text

string

Text to be written to the file

mode

string

a

Adds the text to an existing file. The file will be created if necessary.

c

If the file already exists, the contents will be replaced. Otherwise, the system will create the file and add the text.

encoding

string

If no parameters are specified, the default encoding of the operating system is used. It is recommended to specify the encoding to ensure compatibility between different systems.

UTF-8

UTF-16BE

UTF-16LE

UTF-16

ISO-8859-1

US-ASCII

BINARY

Possible errors

The user does not have write permissions to the specified path.



Example Create a text file and add additional text.

1var path = "C:\\temp\\test.txt";
2writeToFile(path, "Part 1\n", "c", "UTF-8");
3writeToFile(path, "Part 2\n", "a", "UTF-8");
4writeToFile(path, "Part 3",   "c", "UTF-8");

1

Path to the text file

2

Creates a UTF-8 encoded text file with the contents "Part 1." \n adds a line break.

3

Adds the text "Part 2" to the existing file.

4

Writes the text "Part 3" to the file. "Part 1" and "Part 2" will be deleted.

saveModel()
Table 54. This function saves the currently loaded model.

saveModel();

Parameter

Type

Description

Possible errors

Access to the model file is denied.



Example 1 Save the model file

saveModel();

Additional

#include
Table 55. This function includes external script files. For example, this can be used to offload frequently used functions. External scripts can be added to the main script at any location. Relative or absolute paths can be used for external scripts. To use a relative path, the base directory must be specified under Settings -> Directories -> Global scripts.

#include "path\\script.wbjs";

Parameter

Type

Description

Possible errors

The specified script file or path does not exist

The file extension is not .wbjs



Notice

For more examples, see Embedding external scripts

Example 1 Include external scripts

1#include "*";
2#include "folder\\*";
3#include "folder\\script.wbjs";
4#include "c:\\scripting\\folder\\script.wbjs"

1

Includes all scripts in the base directory

2

Includes all scripts in a sub-folder of the base directory.

3

Includes one script in a sub-folder of the base directory.

4

Includes a script via an absolute path.

getModelProperty();
Table 56. Queries various characteristics of the model.

getModelProperty(propertyID);

Parameter

Type

Description

propertyID

string

FILEPATH

Complete path to the model file.

c:/example/modelfolder/model.wbpz

FOLDER

Path where the model file is located.

c:/example/modelfolder/

FILENAME

Name of the model file.

model.wbpz

FILENAME_NO_EXT

Name of the model file without file extension.

model

MODEL_NAME

Name of the project or model.

Project name can be changed under Project -> Properties

Twin-Screw Extruder

PM_VERSION

Product model version

2.2169.0



Example 1 Write a text file to a subdirectory of the model folder.

1let modelpath = getModelProperty("FOLDER");
2let modelname = getModelProperty("MODEL_NAME");
3let filepath = modelpath + "new_directory/textfile.txt";
4writeToFile(filepath, modelname, "c", "UTF-8");

1

Assigns the path of the model file to the modelpath variable.

2

Assigns the name of the model to the modelname variable.

3

Appends the string "new_directory/textfile.txt" to the modelpath variable and writes it to the filepath.

4

Writes a text file that includes the model name as text to the path of the filepath variable.

getDirectory()
Table 57. Returns the paths to directories defined in the settings.

getDirectory(folderID);

Parameter

Type

Description

folderID

string

global_scripts

global scripts

models

preferred location for saving gearbox models

temp

temporary files

report_templates

report templates

reports

preferred output folder for reports



Example Query the directory for report templates and the output folder and create a results report.

1let reportTemplateDirectory = getDirectory("report_templates");
2let templateFile = reportTemplateDirectory +"\\myReportTemplate.wbrep";

3let outputDirectory = getDirectory("reports");
4let outputFile = outputDirectory+"\\report.html";

5generateReport(templateFile, outputFile);

6println("Report was saved here: "+outputFile);

1

Queries the path in which the .wbrep report templates are located and saves it to the reportTemplateDirectory variable

2

Appends the name of the report template to reportTemplateDirectory and saves it to the templateFile variable.

3

Queries the path in which the .html results reports are saved by default and saves it to the outputDirectory variable.

4

Appends the names of the output reports to outputDirectory and saves them to the outputFile variable.

5

Creates a report.

6

Outputs the location of the output report to the Scripting Monitor.