7 Sep 2021

Using Tcl Command Module for Multi-File OBJ Export

The Tcl Command Module makes it easy to export the surfaces of single objects from a multi-object surface as OBJ (Wavefront) files.


The example project:

This project demonstrates the use of the "Tcl Command Module" by controlling the "Surface View" module for only displaying the surface of one material at a time, and to export those surfaces to individual Wavefront (OBJ) files.

Before pressing "Apply", you need to set the output directory to something appropriate (for example, a writable directory), by changing that line (or you create that directory):

set outDir "c:/temp"

(Note: Use "/" as directory separator, also on Windows!)

Using the approach in your own project:

For doing the same in your own project:

  • Create a "Tcl Command Module" object by right-clicking on the Project View's background, selecting "Create object ...", and selecting "Animations and Scripts"->"Tcl Command Module"

  • Connect its "Input" port to the "Surface View" object connected to your surface data

  • Paste the following Tcl code into the text-field:
set sv [$this input source]
set numMaterials [$sv  materials getNum]
echo $numMaterials
for {set i 2} {$i < $numMaterials} {incr i} {
  echo $i
  $sv materials setValue 0 0
  $sv materials setValue 1 0
  $sv fire
  $sv showBox
  $sv fire
  $sv buffer setValue 1
  $sv fire
  $sv materials setValue 0 $i
  $sv fire
  $sv showBox
  $sv fire
  $sv buffer setValue 0
  $sv fire
  set surf [$sv createSurface]
  echo $surf
  set outDir "c:/temp"
  set outFile "$outDir/$surf.obj"
  $surf exportData "Wavefront" $outFile
  • Adapt the value of "outDir"

  • Click "Apply"


  • If you want to change the output file-format to something other than OBJ:

    The line
    $surf exportData "Wavefront" $outFile
    is exporting the extracted surface to a file. The file-type is specified by the first parameter of "exportData". The currently supported file-types for surface data are:

    "Avizo Binary Surface", "HxSurface binary", "HxSurface ascii", "Open Inventor ascii", "Open Inventor binary", "Open Inventor ascii compressed", "Open Inventor binary compressed", "Wavefront", "ABAQUS Input", "ANSYS Input", "AVS UCD ascii", "AVS UCD binary", "CGNS", "COMSOL ascii", "COMSOL binary", "DXF", "Ensight Gold binary", "FLUENT/UNS", "Hypermesh ascii", "MSC/NASTRAN Bulk Data", "Matlab m-file", "SDRC/IDEAS Universal", "STL ascii", "STL binary Big Endian", "STL binary Little Endian", "Stanford PLY", "Tecplot 10 binary", "Trimesh Demo Format"

    If you change the file-type, you should adapt the file-extension in the line

    set outFile "$outDir/$surf.obj"
    as well.

  • The variable "$this" is referring to the object itself, in this case to the "Tcl Command Module". Therefore, the code
    [$this input source]

    returns the name of the object connected to the input-port of the "Tcl Command Module".