OpenVSP API Documentation 3.51.3
Loading...
Searching...
No Matches
Advanced Link Functions

The following functions are available for the Advanced Link tool. Click here to return to the main page. More...

Functions

std::vector< std::string > vsp::GetAdvLinkNames ()
int vsp::GetLinkIndex (const std::string &name)
std::string vsp::GetAdvLinkName (int index)
void vsp::SetAdvLinkName (int index, const std::string &name)
void vsp::DelAllAdvLinks ()
void vsp::AddAdvLink (const std::string &name)
void vsp::AddAdvLinkInput (int index, const std::string &parm_id, const std::string &var_name)
void vsp::AddAdvLinkOutput (int index, const std::string &parm_id, const std::string &var_name)
void vsp::DelAllAdvLinkInputs (int index)
void vsp::DelAllAdvLinkOutputs (int index)
void vsp::DelAdvLinkOutput (int index, const std::string &var_name)
std::vector< std::string > vsp::GetAdvLinkInputNames (int index)
std::vector< std::string > vsp::GetAdvLinkInputParms (int index)
std::vector< std::string > vsp::GetAdvLinkOutputNames (int index)
std::vector< std::string > vsp::GetAdvLinkOutputParms (int index)
bool vsp::ValidateAdvLinkParms (int index)
void vsp::SetAdvLinkCode (int index, const std::string &code)
std::string vsp::GetAdvLinkCode (int index)
void vsp::SearchReplaceAdvLinkCode (int index, const std::string &from, const std::string &to)
bool vsp::BuildAdvLinkScript (int index)
void vsp::WriteAdvLinkCodeFile (int index, const std::string &file_name)
void vsp::ReorderAdvLinkInput (int index, const std::string &var_name, int reorder_type)
void vsp::ReorderAdvLinkOutput (int index, const std::string &var_name, int reorder_type)
void vsp::ReadAdvLinkCodeFile (int index, const std::string &file_name)
void vsp::SortAdvLinkInputsVar (int index)
void vsp::SortAdvLinkInputsCGP (int index)
void vsp::SortAdvLinkOutputsVar (int index)
void vsp::SortAdvLinkOutputsCGP (int index)

Detailed Description

Function Documentation

◆ AddAdvLink()

void vsp::AddAdvLink ( const std::string & name)
extern

Add an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
// The link was named, so it has to be findable by that name and by that
// index, and it has to actually drive its output: x is 10 minus the Pod's
// length, so changing the length has to move the Pod.
if ( indx < 0 || GetAdvLinkNames().size() != 1 || GetAdvLinkNames()[0] != "ExampleLink" )
{
Print( "ERROR: the advanced link was not registered under its name" );
__failure++;
}
SetParmValUpdate( length, 6.0 );
if ( !closeTo( GetParmVal( x_pos ), 4.0, 1e-6 ) )
{
Print( "ERROR: the advanced link did not drive its output" );
__failure++;
}
std::string AddGeom(const std::string &type, const std::string &parent=std::string())
std::string FindParm(const std::string &parm_container_id, const std::string &parm_name, const std::string &group_name)
double SetParmValUpdate(const std::string &parm_id, double val)
double GetParmVal(const std::string &parm_id)
std::string GetParm(const std::string &geom_id, const std::string &name, const std::string &group)
void Update(bool update_managers=true)
Parameters
[in]namestring Name for advanced link

◆ AddAdvLinkInput()

void vsp::AddAdvLinkInput ( int index,
const std::string & parm_id,
const std::string & var_name )
extern

Add an input variable to an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
// The link was named, so it has to be findable by that name and by that
// index, and it has to actually drive its output: x is 10 minus the Pod's
// length, so changing the length has to move the Pod.
if ( indx < 0 || GetAdvLinkNames().size() != 1 || GetAdvLinkNames()[0] != "ExampleLink" )
{
Print( "ERROR: the advanced link was not registered under its name" );
__failure++;
}
SetParmValUpdate( length, 6.0 );
if ( !closeTo( GetParmVal( x_pos ), 4.0, 1e-6 ) )
{
Print( "ERROR: the advanced link did not drive its output" );
__failure++;
}
Parameters
[in]indexint Advanced link index
[in]parm_idstring Parameter ID for advanced link input variable
[in]var_namestring Name for advanced link input variable

◆ AddAdvLinkOutput()

void vsp::AddAdvLinkOutput ( int index,
const std::string & parm_id,
const std::string & var_name )
extern

Add an output variable to an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
// The link was named, so it has to be findable by that name and by that
// index, and it has to actually drive its output: x is 10 minus the Pod's
// length, so changing the length has to move the Pod.
if ( indx < 0 || GetAdvLinkNames().size() != 1 || GetAdvLinkNames()[0] != "ExampleLink" )
{
Print( "ERROR: the advanced link was not registered under its name" );
__failure++;
}
SetParmValUpdate( length, 6.0 );
if ( !closeTo( GetParmVal( x_pos ), 4.0, 1e-6 ) )
{
Print( "ERROR: the advanced link did not drive its output" );
__failure++;
}
Parameters
[in]indexint Advanced link index
[in]parm_idstring Parameter ID for advanced link output variable
[in]var_namestring Name for advanced link output variable

◆ BuildAdvLinkScript()

bool vsp::BuildAdvLinkScript ( int index)
extern

Build (ready for execution and perform syntax check) an advanced link.

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
bool success = BuildAdvLinkScript( indx );
// The link built above is well formed, so this has to come back true.
if ( !success )
{
Print( "ERROR: BuildAdvLinkScript did not report success" );
__failure++;
}
if ( success )
{
Print( "Advanced link build successful." );
}
else
{
Print( "Advanced link build not successful." );
}
Parameters
[in]indexint Index for advanced link
Returns
bool Flag indicating whether advanced link build was successful

◆ DelAdvLinkOutput()

void vsp::DelAdvLinkOutput ( int index,
const std::string & var_name )
extern

Delete an output variable from an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
string y_pos = GetParm( pod, "Y_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
AddAdvLinkOutput( indx, y_pos, "y" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
int num_before_del = GetAdvLinkOutputNames( indx ).length();
DelAdvLinkOutput( indx, "y" );
if ( GetAdvLinkOutputNames( indx ).length() >= num_before_del )
{
Print( "ERROR: DelAdvLinkOutput removed nothing" );
__failure++;
}
// The link was named, so it has to be findable by that name and by that
// index, and it has to actually drive its output: x is 10 minus the Pod's
// length, so changing the length has to move the Pod.
if ( indx < 0 || GetAdvLinkNames().size() != 1 || GetAdvLinkNames()[0] != "ExampleLink" )
{
Print( "ERROR: the advanced link was not registered under its name" );
__failure++;
}
SetParmValUpdate( length, 6.0 );
if ( !closeTo( GetParmVal( x_pos ), 4.0, 1e-6 ) )
{
Print( "ERROR: the advanced link did not drive its output" );
__failure++;
}
Parameters
[in]indexint Advanced link index
[in]var_namestring Name for advanced link output variable to delete

◆ DelAllAdvLinkInputs()

void vsp::DelAllAdvLinkInputs ( int index)
extern

Delete an input variable from an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
string y_pos = GetParm( pod, "Y_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
AddAdvLinkInput( indx, y_pos, "y" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
int num_before_del = GetAdvLinkInputNames( indx ).length();
DelAdvLinkInput( indx, "y" );
if ( GetAdvLinkInputNames( indx ).length() >= num_before_del )
{
Print( "ERROR: DelAdvLinkInput removed nothing" );
__failure++;
}
// The link was named, so it has to be findable by that name and by that
// index, and it has to actually drive its output: x is 10 minus the Pod's
// length, so changing the length has to move the Pod.
if ( indx < 0 || GetAdvLinkNames().size() != 1 || GetAdvLinkNames()[0] != "ExampleLink" )
{
Print( "ERROR: the advanced link was not registered under its name" );
__failure++;
}
SetParmValUpdate( length, 6.0 );
if ( !closeTo( GetParmVal( x_pos ), 4.0, 1e-6 ) )
{
Print( "ERROR: the advanced link did not drive its output" );
__failure++;
}
Parameters
[in]indexint Advanced link index
[in]var_namestring Name for advanced link input variable to delete

Delete all input variables from an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
string y_pos = GetParm( pod, "Y_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkInput( indx, y_pos, "y" );
AddAdvLinkOutput( indx, x_pos, "x" );
if ( GetAdvLinkInputNames( indx ).size() != 2 )
{
Print( "ERROR: the inputs were not both added" );
__failure++;
}
// Every input goes; the outputs are left alone.
if ( GetAdvLinkInputNames( indx ).size() != 0 )
{
Print( "ERROR: DelAllAdvLinkInputs left inputs behind" );
__failure++;
}
if ( GetAdvLinkOutputNames( indx ).size() != 1 )
{
Print( "ERROR: DelAllAdvLinkInputs removed an output" );
__failure++;
}
See also
AddAdvLinkInput, DelAdvLinkInput, DelAllAdvLinkOutputs
Parameters
[in]indexint Advanced link index

◆ DelAllAdvLinkOutputs()

void vsp::DelAllAdvLinkOutputs ( int index)
extern

Delete all output variables from an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
string y_pos = GetParm( pod, "Y_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
AddAdvLinkOutput( indx, y_pos, "y" );
if ( GetAdvLinkOutputNames( indx ).size() != 2 )
{
Print( "ERROR: the outputs were not both added" );
__failure++;
}
// Every output goes; the inputs are left alone.
if ( GetAdvLinkOutputNames( indx ).size() != 0 )
{
Print( "ERROR: DelAllAdvLinkOutputs left outputs behind" );
__failure++;
}
if ( GetAdvLinkInputNames( indx ).size() != 1 )
{
Print( "ERROR: DelAllAdvLinkOutputs removed an input" );
__failure++;
}
See also
AddAdvLinkOutput, DelAdvLinkOutput, DelAllAdvLinkInputs
Parameters
[in]indexint Advanced link index

◆ DelAllAdvLinks()

void vsp::DelAllAdvLinks ( )
extern

Delete all advanced links

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
array< string > @link_array = GetAdvLinkNames();
// Should print nothing.
for( int n = 0 ; n < int( link_array.length() ) ; n++ )
{
Print( link_array[n] );
}
if ( link_array.size() != 0 )
{
Print( "ERROR: links were left behind" );
__failure++;
}
// With the link gone, the Pod is no longer driven.
double x_before = GetParmVal( x_pos );
SetParmValUpdate( length, 7.0 );
if ( !closeTo( GetParmVal( x_pos ), x_before, 1e-9 ) )
{
Print( "ERROR: a deleted advanced link is still driving its output" );
__failure++;
}

◆ GetAdvLinkCode()

std::string vsp::GetAdvLinkCode ( int index)
extern

Get the code from an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
string code = GetAdvLinkCode( indx );
if ( code.length() == 0 )
{
Print( "ERROR: GetAdvLinkCode returned nothing" );
__failure++;
}
Print( code );
Parameters
[in]indexint Index for advanced link
Returns
string String containing advanced link code

◆ GetAdvLinkInputNames()

std::vector< std::string > vsp::GetAdvLinkInputNames ( int index)
extern

Get the name of all the inputs to a specified advanced link index

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
array< string > @name_array = GetAdvLinkInputNames( indx );
if ( name_array.length() == 0 )
{
Print( "ERROR: GetAdvLinkInputNames returned nothing" );
__failure++;
}
for( int n = 0 ; n < int( name_array.length() ) ; n++ )
{
Print( name_array[n] );
}
Parameters
[in]indexint Advanced link index
Returns
vector<string> Array of advanced link input names

◆ GetAdvLinkInputParms()

std::vector< std::string > vsp::GetAdvLinkInputParms ( int index)
extern

Get the Parm IDs of all the inputs to a specified advanced link index

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
array< string > @parm_array = GetAdvLinkInputParms( indx );
if ( parm_array.length() == 0 )
{
Print( "ERROR: GetAdvLinkInputParms returned nothing" );
__failure++;
}
for( int n = 0 ; n < int( parm_array.length() ) ; n++ )
{
Print( parm_array[n] );
}
Parameters
[in]indexint Advanced link index
Returns
vector<string> Array of advanced link input Parm IDs

◆ GetAdvLinkName()

std::string vsp::GetAdvLinkName ( int index)
extern

Delete an advanced link specified by index

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
int num_before_del = GetAdvLinkNames().length();
DelAdvLink( indx );
if ( GetAdvLinkNames().length() >= num_before_del )
{
Print( "ERROR: DelAdvLink removed nothing" );
__failure++;
}
array< string > @link_array = GetAdvLinkNames();
// Should print nothing.
for( int n = 0 ; n < int( link_array.length() ) ; n++ )
{
Print( link_array[n] );
}
if ( link_array.size() != 0 )
{
Print( "ERROR: links were left behind" );
__failure++;
}
// With the link gone, the Pod is no longer driven.
double x_before = GetParmVal( x_pos );
SetParmValUpdate( length, 7.0 );
if ( !closeTo( GetParmVal( x_pos ), x_before, 1e-9 ) )
{
Print( "ERROR: a deleted advanced link is still driving its output" );
__failure++;
}
Parameters
[in]indexint Index for advanced link

Get the name of an advanced link.

AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
if ( GetAdvLinkName( indx ) != "ExampleLink" )
{
Print( "ERROR: GetAdvLinkName did not report the name the link was created with" );
__failure++;
}
// The single name and the list of names agree.
array< string > @link_array = GetAdvLinkNames();
if ( link_array.size() != 1 || link_array[0] != GetAdvLinkName( indx ) )
{
Print( "ERROR: GetAdvLinkName disagrees with GetAdvLinkNames" );
__failure++;
}
// An index past the end has to be rejected.
if ( GetNumTotalErrors() == 0 )
{
Print( "ERROR: GetAdvLinkName accepted an index past the end" );
__failure++;
}
// That error was raised deliberately, so take it back off the queue.
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
}
See also
AddAdvLink, GetAdvLinkNames, SetAdvLinkName
Parameters
[in]indexint Advanced link index
Returns
string Advanced link name

◆ GetAdvLinkNames()

std::vector< std::string > vsp::GetAdvLinkNames ( )
extern

Get an array of all advanced link names

//==== Set up an advanced link so there is something to find ====//
string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
array< string > @link_array = GetAdvLinkNames();
if ( link_array.length() == 0 )
{
Print( "ERROR: GetAdvLinkNames returned nothing" );
__failure++;
}
for( int n = 0 ; n < int( link_array.length() ) ; n++ )
{
Print( link_array[n] );
}
Returns
vector<string> Array of advanced link names

◆ GetAdvLinkOutputNames()

std::vector< std::string > vsp::GetAdvLinkOutputNames ( int index)
extern

Get the Parm IDs of all the outputs to a specified advanced link index

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
array< string > @name_array = GetAdvLinkOutputNames( indx );
if ( name_array.length() == 0 )
{
Print( "ERROR: GetAdvLinkOutputNames returned nothing" );
__failure++;
}
for( int n = 0 ; n < int( name_array.length() ) ; n++ )
{
Print( name_array[n] );
}
Parameters
[in]indexint Advanced link index
Returns
vector<string> Array of advanced link output names

◆ GetAdvLinkOutputParms()

std::vector< std::string > vsp::GetAdvLinkOutputParms ( int index)
extern

Get the Parm IDs of all the outputs to a specified advanced link index

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
array< string > @parm_array = GetAdvLinkOutputParms( indx );
if ( parm_array.length() == 0 )
{
Print( "ERROR: GetAdvLinkOutputParms returned nothing" );
__failure++;
}
for( int n = 0 ; n < int( parm_array.length() ) ; n++ )
{
Print( parm_array[n] );
}
Parameters
[in]indexint Advanced link index
Returns
vector<string> Array of advanced link output Parm IDs

◆ GetLinkIndex()

int vsp::GetLinkIndex ( const std::string & name)
extern

Find the index of a specific advanced link.

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
// The link was named, so it has to be findable by that name and by that
// index, and it has to actually drive its output: x is 10 minus the Pod's
// length, so changing the length has to move the Pod.
if ( indx < 0 || GetAdvLinkNames().size() != 1 || GetAdvLinkNames()[0] != "ExampleLink" )
{
Print( "ERROR: the advanced link was not registered under its name" );
__failure++;
}
SetParmValUpdate( length, 6.0 );
if ( !closeTo( GetParmVal( x_pos ), 4.0, 1e-6 ) )
{
Print( "ERROR: the advanced link did not drive its output" );
__failure++;
}
Parameters
[in]namestring Name for advanced link
Returns
int index for advanced link

◆ ReadAdvLinkCodeFile()

void vsp::ReadAdvLinkCodeFile ( int index,
const std::string & file_name )
extern

Read the code of an advanced link in from a text file, the way the File Read button on the Advanced Link screen does. The link is rebuilt from the new code, so any variable the file refers to must already have been declared as an input or an output.

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
WriteAdvLinkCodeFile( indx, "ExampleLink.vspscript" );
// A second link can pick up the same code, so long as it declares len and x.
AddAdvLink( "SecondLink" );
int indx2 = GetLinkIndex( "SecondLink" );
AddAdvLinkInput( indx2, length, "len" );
AddAdvLinkOutput( indx2, GetParm( pod, "Y_Rel_Location", "XForm" ), "x" );
ReadAdvLinkCodeFile( indx2, "ExampleLink.vspscript" );
if ( GetAdvLinkCode( indx2 ) != GetAdvLinkCode( indx ) )
{
Print( "ERROR: ReadAdvLinkCodeFile did not load the code" );
__failure++;
}
See also
WriteAdvLinkCodeFile, SetAdvLinkCode
Parameters
[in]indexint Index for advanced link
[in]file_namestring Name of the file to read

◆ ReorderAdvLinkInput()

void vsp::ReorderAdvLinkInput ( int index,
const std::string & var_name,
int reorder_type )
extern

Move an input variable within an advanced link's input list, the way the move buttons beside the input browser do. The order is presentation only; it does not affect what the link computes.

string pod = AddGeom( "POD", "" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, FindParm( pod, "Length", "Design" ), "len" );
AddAdvLinkInput( indx, FindParm( pod, "FineRatio", "Design" ), "fine" );
array< string > @names = GetAdvLinkInputNames( indx );
if ( names[0] != "fine" || names[1] != "len" )
{
Print( "ERROR: ReorderAdvLinkInput did not move the variable" );
__failure++;
}
@ REORDER_MOVE_UP
See also
SortAdvLinkInputsVar, ReorderAdvLinkOutput
Parameters
[in]indexint Index for advanced link
[in]var_namestring Input variable name
[in]reorder_typeint Reorder type enum (see REORDER_TYPE)

◆ ReorderAdvLinkOutput()

void vsp::ReorderAdvLinkOutput ( int index,
const std::string & var_name,
int reorder_type )
extern

Move an output variable within an advanced link's output list, the way the move buttons beside the output browser do. The order is presentation only; it does not affect what the link computes.

string pod = AddGeom( "POD", "" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkOutput( indx, FindParm( pod, "X_Rel_Location", "XForm" ), "x" );
AddAdvLinkOutput( indx, FindParm( pod, "Y_Rel_Location", "XForm" ), "y" );
array< string > @names = GetAdvLinkOutputNames( indx );
if ( names[0] != "y" || names[1] != "x" )
{
Print( "ERROR: ReorderAdvLinkOutput did not move the variable" );
__failure++;
}
@ REORDER_MOVE_BOTTOM
See also
SortAdvLinkOutputsVar, ReorderAdvLinkInput
Parameters
[in]indexint Index for advanced link
[in]var_namestring Output variable name
[in]reorder_typeint Reorder type enum (see REORDER_TYPE)

◆ SearchReplaceAdvLinkCode()

void vsp::SearchReplaceAdvLinkCode ( int index,
const std::string & from,
const std::string & to )
extern

Search and replace strings in the advanced link code

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
SearchReplaceAdvLinkCode( indx, "10.0", "12.3" );
string code = GetAdvLinkCode( indx );
Print( code );
if ( code.find( "12.3" ) < 0 || code.find( "10.0" ) >= 0 )
{
Print( "ERROR: SearchReplaceAdvLinkCode did not replace" );
__failure++;
}
// The link was named, so it has to be findable by that name and by that
// index, and it has to actually drive its output. The replacement rewrote
// the code, so x is now 12.3 minus the Pod's length.
if ( indx < 0 || GetAdvLinkNames().size() != 1 || GetAdvLinkNames()[0] != "ExampleLink" )
{
Print( "ERROR: the advanced link was not registered under its name" );
__failure++;
}
SetParmValUpdate( length, 6.0 );
if ( !closeTo( GetParmVal( x_pos ), 6.3, 1e-6 ) )
{
Print( "ERROR: the advanced link did not drive its output" );
__failure++;
}
Parameters
[in]indexint Index for advanced link
[in]fromstring Search token
[in]tostring Replace token

◆ SetAdvLinkCode()

void vsp::SetAdvLinkCode ( int index,
const std::string & code )
extern

Get the code from an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
// The link was named, so it has to be findable by that name and by that
// index, and it has to actually drive its output: x is 10 minus the Pod's
// length, so changing the length has to move the Pod.
if ( indx < 0 || GetAdvLinkNames().size() != 1 || GetAdvLinkNames()[0] != "ExampleLink" )
{
Print( "ERROR: the advanced link was not registered under its name" );
__failure++;
}
SetParmValUpdate( length, 6.0 );
if ( !closeTo( GetParmVal( x_pos ), 4.0, 1e-6 ) )
{
Print( "ERROR: the advanced link did not drive its output" );
__failure++;
}
Parameters
[in]indexint Index for advanced link
[in]codestring Code for advanced link

◆ SetAdvLinkName()

void vsp::SetAdvLinkName ( int index,
const std::string & name )
extern

Set the name of an advanced link.

AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
SetAdvLinkName( indx, "RenamedLink" );
if ( GetAdvLinkName( indx ) != "RenamedLink" )
{
Print( "ERROR: SetAdvLinkName did not take" );
__failure++;
}
// The link is now found under its new name and not its old one.
if ( GetLinkIndex( "RenamedLink" ) != indx )
{
Print( "ERROR: the renamed link cannot be found under its new name" );
__failure++;
}
if ( GetLinkIndex( "ExampleLink" ) >= 0 )
{
Print( "ERROR: the renamed link is still found under its old name" );
__failure++;
}
// Looking up the old name raised an error on purpose, so take it back off
// the queue.
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
}
See also
AddAdvLink, GetAdvLinkName, GetLinkIndex
Parameters
[in]indexint Advanced link index
[in]namestring Advanced link name

◆ SortAdvLinkInputsCGP()

void vsp::SortAdvLinkInputsCGP ( int index)
extern

Sort the input variables of an advanced link by the Parm they are attached to, ordering on container name, then group name, then Parm name. This gathers the inputs that come from the same Geom together, which is usually how a link is read.

string pod = AddGeom( "POD", "" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, FindParm( pod, "Length", "Design" ), "a" );
AddAdvLinkInput( indx, FindParm( pod, "FineRatio", "Design" ), "b" );
array< string > @names = GetAdvLinkInputNames( indx );
// FineRatio sorts ahead of Length, so the variables come back swapped.
if ( names[0] != "b" || names[1] != "a" )
{
Print( "ERROR: SortAdvLinkInputsCGP did not sort by Parm" );
__failure++;
}
See also
SortAdvLinkInputsVar, SortAdvLinkOutputsCGP
Parameters
[in]indexint Index for advanced link

◆ SortAdvLinkInputsVar()

void vsp::SortAdvLinkInputsVar ( int index)
extern

Sort the input variables of an advanced link into alphabetical order by variable name. Inputs are otherwise kept in the order they were added, which is rarely the order that reads well once a link has grown.

string pod = AddGeom( "POD", "" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, FindParm( pod, "Length", "Design" ), "zlen" );
AddAdvLinkInput( indx, FindParm( pod, "FineRatio", "Design" ), "afine" );
array< string > @names = GetAdvLinkInputNames( indx );
if ( names[0] != "afine" || names[1] != "zlen" )
{
Print( "ERROR: SortAdvLinkInputsVar did not sort by name" );
__failure++;
}
See also
SortAdvLinkInputsCGP, SortAdvLinkOutputsVar
Parameters
[in]indexint Index for advanced link

◆ SortAdvLinkOutputsCGP()

void vsp::SortAdvLinkOutputsCGP ( int index)
extern

Sort the output variables of an advanced link by the Parm they drive, ordering on container name, then group name, then Parm name.

string pod = AddGeom( "POD", "" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkOutput( indx, FindParm( pod, "Y_Rel_Location", "XForm" ), "a" );
AddAdvLinkOutput( indx, FindParm( pod, "X_Rel_Location", "XForm" ), "b" );
array< string > @names = GetAdvLinkOutputNames( indx );
// X_Rel_Location sorts ahead of Y_Rel_Location, so the variables come back swapped.
if ( names[0] != "b" || names[1] != "a" )
{
Print( "ERROR: SortAdvLinkOutputsCGP did not sort by Parm" );
__failure++;
}
See also
SortAdvLinkOutputsVar, SortAdvLinkInputsCGP
Parameters
[in]indexint Index for advanced link

◆ SortAdvLinkOutputsVar()

void vsp::SortAdvLinkOutputsVar ( int index)
extern

Sort the output variables of an advanced link into alphabetical order by variable name.

string pod = AddGeom( "POD", "" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkOutput( indx, FindParm( pod, "X_Rel_Location", "XForm" ), "zx" );
AddAdvLinkOutput( indx, FindParm( pod, "Y_Rel_Location", "XForm" ), "ay" );
array< string > @names = GetAdvLinkOutputNames( indx );
if ( names[0] != "ay" || names[1] != "zx" )
{
Print( "ERROR: SortAdvLinkOutputsVar did not sort by name" );
__failure++;
}
See also
SortAdvLinkOutputsCGP, SortAdvLinkInputsVar
Parameters
[in]indexint Index for advanced link

◆ ValidateAdvLinkParms()

bool vsp::ValidateAdvLinkParms ( int index)
extern

Validate the input and output parameters for an advanced link

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
bool valid = ValidateAdvLinkParms( indx );
// The link built above is well formed, so this has to come back true.
if ( !valid )
{
Print( "ERROR: ValidateAdvLinkParms did not report success" );
__failure++;
}
if ( valid )
{
Print( "Advanced link Parms are valid." );
}
else
{
Print( "Advanced link Parms are not valid." );
}
Parameters
[in]indexint Index for advanced link
Returns
bool Flag indicating whether parms are valid

◆ WriteAdvLinkCodeFile()

void vsp::WriteAdvLinkCodeFile ( int index,
const std::string & file_name )
extern

Write the code of an advanced link out to a text file, the way the File Write button on the Advanced Link screen does. Only the code is written; the input and output variable lists are not, so a file written here can be read back into any link that declares the same variables.

string pod = AddGeom( "POD", "" );
string length = FindParm( pod, "Length", "Design" );
string x_pos = GetParm( pod, "X_Rel_Location", "XForm" );
AddAdvLink( "ExampleLink" );
int indx = GetLinkIndex( "ExampleLink" );
AddAdvLinkInput( indx, length, "len" );
AddAdvLinkOutput( indx, x_pos, "x" );
SetAdvLinkCode( indx, "x = 10.0 - len;" );
WriteAdvLinkCodeFile( indx, "ExampleLink.vspscript" );
// Overwrite the code, then bring the saved version back.
SetAdvLinkCode( indx, "x = 0.0;" );
ReadAdvLinkCodeFile( indx, "ExampleLink.vspscript" );
if ( GetAdvLinkCode( indx ) != "x = 10.0 - len;" )
{
Print( "ERROR: the code did not survive the round trip" );
__failure++;
}
See also
ReadAdvLinkCodeFile, GetAdvLinkCode
Parameters
[in]indexint Index for advanced link
[in]file_namestring Name of the file to write