7 Sep 2021

Using Tcl Command Module for multi-file OBJ export

Using the Tcl Command Module, it is 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 "Tcl Command Module" by controlling the module "Surface View" for only displaying the surface of one material at a time, and to export those surfaces to individual Wavefront (OBJ) files.

Before pressing "Apply", one needs to set the output directory to something appropriate, i.e. 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, select "Create object ...", and select "Animations and Scripts"->"Tcl Command Module"

  • connect its "Input" port to the "Surface View" object which is 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"

  • press "Apply"


  • If you want to change the output file-format to something else 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". Thus the code
    [$this input source]

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