pw:: CaeExporter

The CaeExporter IO mode type.  If you do not require fine-grained control over the CAE export process, use the <pw::Application export> action.

Derives From

pw::Object pw::Mode pw::IOMode

Summary
The CaeExporter IO mode type.
This action gets a list of the file types that can export all of the entities of this mode.
This action verifies the IO mode attributes and the entities of the mode that should be exported.
This action checks if there is data that will be written out when the write action is used.
This action writes the file by converting pw::GridEntity objects into the format required for the exported data.
Example: Code example showing a minimal usage of a CaeExport IOMode.
Code

Instance Actions

getFileTypes

$io getFileTypes

This action gets a list of the file types that can export all of the entities of this mode.

Parameters

This action has no parameters.

Returns

This action returns a list containing file type names that can be used in the <initialize> command.

verify

$io verify

This action verifies the IO mode attributes and the entities of the mode that should be exported.

Parameters

This action has no parameters.

Returns

This action returns a boolean of true if verified, false if not.

Note

This action must be called after initialize, but before write.

Possible Errors

AttributeIsInvalid, UnsupportedEntityDetected, Unknown

canWrite

$io canWrite

This action checks if there is data that will be written out when the write action is used.

Parameters

This action has no parameters.

Returns

This action returns a boolean of true if write will export data, false if not.

write

$io write

This action writes the file by converting pw::GridEntity objects into the format required for the exported data.

Parameters

This action has no parameters.

Returns

This action returns a boolean of true if written, false if not.

Note

This action must be called after initialize and verify.

Possible Errors

AttributeIsInvalid, UnsupportedEntityDetected, Unknown

Glyph Code Examples

Minimal CaeExport IOMode code example

Example: Code example showing a minimal usage of a CaeExport IOMode.

Code

# This sample assumes:
#
# * A grid file is loaded and is ready for CAE export.
# * The solver is set to CGNS.
# * $ents is the list of blocks to export
#
# This CaeExport IOMode code is equivalent to:
#
# pw::Application export -precision Double $ents "C:\test.cgns"
#


# Create the CaeExport mode
set status abort
set caex [pw::Application begin CaeExport $ents]
if { $caex && [$caex initialize "C:\test.cgns"] } {
$caex setAttribute FilePrecision Double
if { [$caex verify] && [$caex canWrite] && [$caex write] } {
set status end
}
}
# abort/end the mode
$caex $status

Output

Full-featured CaeExport IOMode code example

Example

Code

# This sample assumes:
# * A grid file is loaded and is ready for CAE export.


# Capture the folder in which this script is located and append the
# "export" subfolder.
set scriptDir [file normalize [file dirname [info script]]]
set exportDir [file join $scriptDir "export"]

puts "Current solver: [set curSolver [pw::Application getCAESolver]]"

set validExts [pw::Application getCAESolverAttribute FileExtensions]
puts "Valid file extensions: '$validExts'"
# Capture first file extension. Use it below to build filename.
set defExt [lindex $validExts 0]

# Select entities appropriate for dimension.
if { 3 == [pw::Application getCAESolverDimension] } {
set ents [pw::Entity sort [pw::Grid getAll -type pw::Block]]
} else {
set ents [pw::Entity sort [pw::Grid getAll -type pw::Domain]]
}

# Create the CaeExport mode
set caex [pw::Application begin CaeExport $ents]
puts "$caex is a '[$caex getType]'"
puts "Exporting entities: $ents"

# Build an export destination suitable for the current solver. Use
# the script folder as the root output location.
set destType [pw::Application getCAESolverAttribute FileDestination]
switch $destType {
Filename { set dest [file join $exportDir "sample.$defExt"] }
Basename { set dest [file join $exportDir "samplebase"] }
Folder -
default { set dest $exportDir }
}
puts "Exporting to $destType: '$dest'"

# Initialize the CaeExport mode
puts "initialize"
if { [set status [$caex initialize $dest]] } {
# Query CaeExport mode for each attribute definition and value
puts "getAttributeCount = '[$caex getAttributeCount]'"
set attrNameList [$caex getAttributeNames]
foreach attrName $attrNameList {
set attrDefn [$caex getAttributeDefinition $attrName]
puts "attr: [lindex $attrDefn 0]='[$caex getAttribute $attrName]' => [lrange $attrDefn 1 end]"
}
# If the CaeExport mode supports it, set the FileUnits attribute
if { -1 != [lsearch $attrNameList "FileUnits"] } {
puts "setAttribute FileUnits Inches"
$caex setAttribute FileUnits Inches
}
# If the CaeExport mode supports it, set the FilePrecision
# attribute
if { -1 != [lsearch $attrNameList "FilePrecision"] } {
puts "setAttribute FilePrecision Double"
$caex setAttribute FilePrecision Double
}

# Verify that the CaeExport mode is ready for exporting
puts "verify"
if { [set status [$caex verify]] } {
# See if CaeExport mode has anything to export
puts "canWrite"
if { [set status [$caex canWrite]] } {
# Tell CaeExport mode to write export data to disk.
puts "write"
set status [$caex write]
}
}
}
if { $status } {
# Display exported entity count information
puts "export counts: [$caex getForeignEntityCounts]"
} else {
puts "EXPORT FAILED!"
}
# Display any errors/warnings
if { [set errCnt [$caex getErrorCount]] > 0 } {
set ndx 1
while { $ndx <= $errCnt } {
puts "[$caex getErrorCode $ndx]: '[$caex getErrorInformation $ndx]'"
incr ndx
}
}
# end the CaeExport mode
$caex end

Output

Current solver: CGNS
Valid file extensions: 'cgns'
::pw::CaeExporter_1 is a 'pw::CaeExporter'
Exporting entities: ::pw::BlockStructured_1 ::pw::BlockStructured_2 ::pw::BlockStructured_3
Exporting to Filename: 'C:/cae-export/sample.cgns'
initialize
getAttributeCount = '2'
attr: GridStructuredAsUnstructured='false' => boolean {Treat structured blocks as unstructured flag}
attr: FilePrecision='Single' => string {Floating-point precision} Single|Double
setAttribute FilePrecision Double
verify
canWrite
write
export counts: {Structured 3D Zones} 3
$io getFileTypes
This action gets a list of the file types that can export all of the entities of this mode.
$io verify
This action verifies the IO mode attributes and the entities of the mode that should be exported.
$io canWrite
This action checks if there is data that will be written out when the write action is used.
$io write
This action writes the file by converting pw::GridEntity objects into the format required for the exported data.
Base type for all glyph types
The mode base type
The base IO mode type
A boolean is represented as a 0 or 1, with 0 being false and 1 being true.