OpenVSP API Documentation 3.51.3
Loading...
Searching...
No Matches
File Input and Output Functions

This group of functions provides file input and output interfacing through the API. Click here to return to the main page. More...

Functions

void vsp::ReadVSPFile (const std::string &file_name)
void vsp::WriteVSPFile (const std::string &file_name, int set=SET_ALL)
void vsp::SetVSP3FileName (const std::string &file_name)
void vsp::InsertVSPFile (const std::string &file_name, const std::string &parent_geom_id)
std::string vsp::ExportFile (const std::string &file_name, int thick_set, int file_type, int subsFlag=1, int thin_set=vsp::SET_NONE, bool useMode=false, const std::string &modeID="")
std::string vsp::ImportFile (const std::string &file_name, int file_type, const std::string &parent)
std::string vsp::GetBEMPropID ()

Detailed Description

Function Documentation

◆ ExportFile()

std::string vsp::ExportFile ( const std::string & file_name,
int thick_set,
int file_type,
int subsFlag = 1,
int thin_set = vsp::SET_NONE,
bool useMode = false,
const std::string & modeID = "" )
extern

Export a file from OpenVSP. Many formats are available, such as STL, IGES, and SVG. If a mesh is generated for a particular export, the ID of the MeshGeom will be returned. If no mesh is generated an empty string will be returned.

string wid = AddGeom( "WING" ); // Add Wing
ExportFile( "Airfoil_Metadata.csv", SET_ALL, EXPORT_SELIG_AIRFOIL );
string mesh_id = ExportFile( "Example_Mesh.msh", SET_ALL, EXPORT_GMSH );
if ( mesh_id.length() == 0 )
{
Print( "ERROR: ExportFile returned no id" );
__failure++;
}
DeleteGeom( mesh_id ); // Delete the mesh generated by the GMSH export
@ EXPORT_GMSH
Definition APIDefines.h:569
@ EXPORT_SELIG_AIRFOIL
Definition APIDefines.h:580
@ SET_ALL
std::string ExportFile(const std::string &file_name, int thick_set, int file_type, int subsFlag=1, int thin_set=vsp::SET_NONE, bool useMode=false, const std::string &modeID="")
void DeleteGeom(const std::string &geom_id)
std::string AddGeom(const std::string &type, const std::string &parent=std::string())
See also
EXPORT_TYPE
Parameters
[in]file_namestring Export file name
[in]thick_setint Set index to export (i.e. SET_ALL)
[in]file_typeint File type enum (i.e. EXPORT_IGES)
[in]subsFlagint Flag to tag subsurfaces if MeshGeom is created
[in]thin_setint Set index to export as degenerate geometry (i.e. SET_NONE)
[in]useModebool Flag determine if mode is used instead of sets
[in]modeIDstring ID of Mode to use
Returns
string Mesh Geom ID if the export generates a mesh

◆ GetBEMPropID()

std::string vsp::GetBEMPropID ( )
extern

Set the ID of the propeller to be exported to a BEM file. Call this function before ExportFile.

//==== Add Prop Geometry ====//
string prop_id = AddGeom( "PROP" );
SetBEMPropID( prop_id );
ExportFile( "ExampleBEM.bem", SET_ALL, EXPORT_BEM );
// A BEM export of a Geom that is not a propeller has to be rejected.
string pod_id = AddGeom( "POD" );
SetBEMPropID( pod_id );
ExportFile( "ExampleBEM.bem", SET_ALL, EXPORT_BEM );
if ( GetNumTotalErrors() == 0 )
{
Print( "ERROR: BEM export accepted a Geom that is not a propeller" );
__failure++;
}
// That error was raised deliberately, so take it back off the queue.
while ( GetNumTotalErrors() > 0 )
{
ErrorObj err = PopLastError();
}
@ EXPORT_BEM
Definition APIDefines.h:574
See also
EXPORT_TYPE, ExportFile
Parameters
[in]prop_idstring Propeller Geom ID

Get the ID of the propeller that will be exported to a BEM file.

//==== Add Prop Geometry ====//
string prop_id = AddGeom( "PROP" );
SetBEMPropID( prop_id );
if ( GetBEMPropID() != prop_id )
{
Print( "ERROR: GetBEMPropID did not report the propeller that was set" );
__failure++;
}
std::string GetBEMPropID()
See also
SetBEMPropID, ExportFile
Returns
string Propeller Geom ID

◆ ImportFile()

std::string vsp::ImportFile ( const std::string & file_name,
int file_type,
const std::string & parent )
extern

Import a file into OpenVSP. Many formats are available, such as NASCART, V2, and BEM). The imported Geom, mesh, or other object is inserted as a child of the specified parent. If no parent or an invalid parent is given, the import will be done at the top level.

See also
IMPORT_TYPE
Parameters
[in]file_namestring Import file name
[in]file_typeint File type enum (i.e. IMPORT_PTS)
[in]parentstring Parent Geom ID (ignored with empty string)

◆ InsertVSPFile()

void vsp::InsertVSPFile ( const std::string & file_name,
const std::string & parent_geom_id )
extern

Insert an external OpenVSP project into the current project. All Geoms in the external project are placed as children of the specified parent. If no parent or an invalid parent is given, the Geoms are inserted at the top level.

Parameters
[in]file_namestring \*.vsp3 filename
[in]parent_geom_idstring Parent geom ID (ignored with empty string)

◆ ReadVSPFile()

void vsp::ReadVSPFile ( const std::string & file_name)
extern

Load an OpenVSP project from a VSP3 file

string fid = AddGeom( "FUSELAGE", "" ); // Add Fuselage
string fname = "example_fuse.vsp3";
SetVSP3FileName( fname );
// A relative name is resolved against the working directory, so ask for the
// resolved name rather than assuming it comes back verbatim.
string full_name = GetVSPFileName();
//==== Save Vehicle to File ====//
Print( "\tSaving vehicle file to: ", false );
Print( fname );
//==== Reset Geometry ====//
Print( string( "--->Resetting VSP model to blank slate\n" ) );
if ( FindGeoms().size() != 0 )
{
Print( "ERROR: ClearVSPModel left Geoms behind" );
__failure++;
}
ReadVSPFile( fname );
// The Fuselage has to come back, and come back the same shape.
array< string > @geoms = FindGeoms();
if ( geoms.size() != 1 )
{
Print( "ERROR: ReadVSPFile did not restore the model" );
__failure++;
}
else
{
if ( GetGeomTypeName( geoms[0] ) != "Fuselage" )
{
Print( "ERROR: ReadVSPFile restored the wrong Geom type" );
__failure++;
}
if ( GetVSPFileName() != full_name )
{
Print( "ERROR: ReadVSPFile did not set the project file name" );
__failure++;
}
}
void ReadVSPFile(const std::string &file_name)
void SetVSP3FileName(const std::string &file_name)
void WriteVSPFile(const std::string &file_name, int set=SET_ALL)
std::vector< std::string > FindGeoms()
std::string GetGeomTypeName(const std::string &geom_id)
void Update(bool update_managers=true)
void ClearVSPModel()
std::string GetVSPFileName()
Parameters
[in]file_namestring \*.vsp3 file name

◆ SetVSP3FileName()

void vsp::SetVSP3FileName ( const std::string & file_name)
extern

Set the file name of a OpenVSP project

string fid = AddGeom( "FUSELAGE", "" ); // Add Fuselage
string fname = "example_fuse.vsp3";
SetVSP3FileName( fname );
// A relative name is resolved against the working directory, so ask for the
// resolved name rather than assuming it comes back verbatim.
string full_name = GetVSPFileName();
//==== Save Vehicle to File ====//
Print( "\tSaving vehicle file to: ", false );
Print( fname );
//==== Reset Geometry ====//
Print( string( "--->Resetting VSP model to blank slate\n" ) );
if ( FindGeoms().size() != 0 )
{
Print( "ERROR: ClearVSPModel left Geoms behind" );
__failure++;
}
ReadVSPFile( fname );
// The Fuselage has to come back, and come back the same shape.
array< string > @geoms = FindGeoms();
if ( geoms.size() != 1 )
{
Print( "ERROR: ReadVSPFile did not restore the model" );
__failure++;
}
else
{
if ( GetGeomTypeName( geoms[0] ) != "Fuselage" )
{
Print( "ERROR: ReadVSPFile restored the wrong Geom type" );
__failure++;
}
if ( GetVSPFileName() != full_name )
{
Print( "ERROR: ReadVSPFile did not set the project file name" );
__failure++;
}
}
Parameters
[in]file_namestring File name

◆ WriteVSPFile()

void vsp::WriteVSPFile ( const std::string & file_name,
int set = SET_ALL )
extern

Save the current OpenVSP project to a VSP3 file

string fid = AddGeom( "FUSELAGE", "" ); // Add Fuselage
string fname = "example_fuse.vsp3";
SetVSP3FileName( fname );
// A relative name is resolved against the working directory, so ask for the
// resolved name rather than assuming it comes back verbatim.
string full_name = GetVSPFileName();
//==== Save Vehicle to File ====//
Print( "\tSaving vehicle file to: ", false );
Print( fname );
//==== Reset Geometry ====//
Print( string( "--->Resetting VSP model to blank slate\n" ) );
if ( FindGeoms().size() != 0 )
{
Print( "ERROR: ClearVSPModel left Geoms behind" );
__failure++;
}
ReadVSPFile( fname );
// The Fuselage has to come back, and come back the same shape.
array< string > @geoms = FindGeoms();
if ( geoms.size() != 1 )
{
Print( "ERROR: ReadVSPFile did not restore the model" );
__failure++;
}
else
{
if ( GetGeomTypeName( geoms[0] ) != "Fuselage" )
{
Print( "ERROR: ReadVSPFile restored the wrong Geom type" );
__failure++;
}
if ( GetVSPFileName() != full_name )
{
Print( "ERROR: ReadVSPFile did not set the project file name" );
__failure++;
}
}
Parameters
[in]file_namestring \*.vsp3 file name
[in]setint Set index to write (i.e. SET_ALL)