File Input and Output Functions¶
This group of functions provides file input and output interfacing through the API.
|
Load an OpenVSP project from a VSP3 file |
|
Save the current OpenVSP project to a VSP3 file |
|
Set the file name of a OpenVSP project |
|
Insert an external OpenVSP project into the current project. |
|
Export a file from OpenVSP. |
|
Import a file into OpenVSP. |
Set the ID of the propeller to be exported to a BEM file. |
Details¶
- openvsp.ReadVSPFile(file_name)[source]¶
Load an OpenVSP project from a VSP3 file
fid = AddGeom( "FUSELAGE", "" ) # Add Fuselage 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. full_name = GetVSPFileName() Update() #==== Save Vehicle to File ====// print( "\tSaving vehicle file to: ", False ) print( fname ) WriteVSPFile( GetVSPFileName(), SET_ALL ) #==== Reset Geometry ====// print( "--->Resetting VSP model to blank slate\n" ) ClearVSPModel() assert len( FindGeoms() ) == 0, "ClearVSPModel left Geoms behind" ReadVSPFile( fname ) # The Fuselage has to come back, and come back the same shape. geoms = FindGeoms() assert len( geoms ) == 1, "ReadVSPFile did not restore the model" assert GetGeomTypeName( geoms[0] ) == "Fuselage", "ReadVSPFile restored the wrong Geom type" assert GetVSPFileName() == full_name, "ReadVSPFile did not set the project file name"
- Parameters:
[in] – file_name string *.vsp3 file name
- openvsp.WriteVSPFile(*args)[source]¶
Save the current OpenVSP project to a VSP3 file
fid = AddGeom( "FUSELAGE", "" ) # Add Fuselage 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. full_name = GetVSPFileName() Update() #==== Save Vehicle to File ====// print( "\tSaving vehicle file to: ", False ) print( fname ) WriteVSPFile( GetVSPFileName(), SET_ALL ) #==== Reset Geometry ====// print( "--->Resetting VSP model to blank slate\n" ) ClearVSPModel() assert len( FindGeoms() ) == 0, "ClearVSPModel left Geoms behind" ReadVSPFile( fname ) # The Fuselage has to come back, and come back the same shape. geoms = FindGeoms() assert len( geoms ) == 1, "ReadVSPFile did not restore the model" assert GetGeomTypeName( geoms[0] ) == "Fuselage", "ReadVSPFile restored the wrong Geom type" assert GetVSPFileName() == full_name, "ReadVSPFile did not set the project file name"
- Parameters:
[in] – file_name string *.vsp3 file name
[in] – set int Set index to write (i.e. SET_ALL)
- openvsp.SetVSP3FileName(file_name)[source]¶
Set the file name of a OpenVSP project
fid = AddGeom( "FUSELAGE", "" ) # Add Fuselage 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. full_name = GetVSPFileName() Update() #==== Save Vehicle to File ====// print( "\tSaving vehicle file to: ", False ) print( fname ) WriteVSPFile( GetVSPFileName(), SET_ALL ) #==== Reset Geometry ====// print( "--->Resetting VSP model to blank slate\n" ) ClearVSPModel() assert len( FindGeoms() ) == 0, "ClearVSPModel left Geoms behind" ReadVSPFile( fname ) # The Fuselage has to come back, and come back the same shape. geoms = FindGeoms() assert len( geoms ) == 1, "ReadVSPFile did not restore the model" assert GetGeomTypeName( geoms[0] ) == "Fuselage", "ReadVSPFile restored the wrong Geom type" assert GetVSPFileName() == full_name, "ReadVSPFile did not set the project file name"
- Parameters:
[in] – file_name string File name
- openvsp.InsertVSPFile(file_name, parent_geom_id)[source]¶
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.
pid = AddGeom( "POD" ) Update() WriteVSPFile( "TestInsert.vsp3" ) InsertVSPFile( "TestInsert.vsp3", "" ) assert len( FindGeoms() ) == 2, "InsertVSPFile did not bring in the Geom"
- Parameters:
[in] – file_name string *.vsp3 filename
[in] – parent_geom_id string Parent geom ID (ignored with empty string)
- openvsp.ExportFile(*args)[source]¶
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.
wid = AddGeom( "WING" ) # Add Wing ExportFile( "Airfoil_Metadata.csv", SET_ALL, EXPORT_SELIG_AIRFOIL ) mesh_id = ExportFile( "Example_Mesh.msh", SET_ALL, EXPORT_GMSH ) assert len( mesh_id ) > 0, "ExportFile returned no id" DeleteGeom( mesh_id ) # Delete the mesh generated by the GMSH export
See also: EXPORT_TYPE :param [in]: file_name string Export file name :param [in]: thick_set int Set index to export (i.e. SET_ALL) :param [in]: file_type int File type enum (i.e. EXPORT_IGES) :param [in]: subsFlag int Flag to tag subsurfaces if MeshGeom is created :param [in]: thin_set int Set index to export as degenerate geometry (i.e. SET_NONE) :param [in]: useMode bool Flag determine if mode is used instead of sets :param [in]: modeID string ID of Mode to use :rtype: string :return: string Mesh Geom ID if the export generates a mesh
- openvsp.ImportFile(file_name, file_type, parent)[source]¶
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.
pid = AddGeom( "POD" ) Update() SetComputationFileName( COMP_GEOM_TXT_TYPE, "TestImport.txt" ) ExportFile( "TestImport.stl", SET_ALL, EXPORT_STL ) mesh_id = ImportFile( "TestImport.stl", IMPORT_STL, "" ) assert len( mesh_id ) > 0, "ImportFile returned no ID"
See also: IMPORT_TYPE :param [in]: file_name string Import file name :param [in]: file_type int File type enum (i.e. IMPORT_PTS) :param [in]: parent string Parent Geom ID (ignored with empty string)
- openvsp.GetBEMPropID()[source]¶
Set the ID of the propeller to be exported to a BEM file. Call this function before ExportFile.
#==== Add Prop Geometry ====// 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. The # error queue is reached through the error manager singleton in Python. err_mgr = ErrorMgrSingleton.getInstance() pod_id = AddGeom( "POD" ) SetBEMPropID( pod_id ) ExportFile( "ExampleBEM.bem", SET_ALL, EXPORT_BEM ) assert err_mgr.GetNumTotalErrors() > 0, "BEM export accepted a Geom that is not a propeller" # That error was raised deliberately, so take it back off the queue. while err_mgr.GetNumTotalErrors() > 0 : err = err_mgr.PopLastError()
See also: EXPORT_TYPE, ExportFile :param [in]: prop_id string Propeller Geom ID
Get the ID of the propeller that will be exported to a BEM file.
#==== Add Prop Geometry ====// prop_id = AddGeom( "PROP" ) SetBEMPropID( prop_id ) assert GetBEMPropID() == prop_id, "GetBEMPropID did not report the propeller that was set"
See also: SetBEMPropID, ExportFile :rtype: string :return: string Propeller Geom ID