Logo annotation helper

Problem statement: Most EnSight graphics and annotations will resize automatically with the graphics window or output image size, however, the logo annotation does not. Also, the location of the logo is fixed by the bottom-left corner, which means it won’t stay fixed in the upper-right corner when the resolution changes.

Value proposition: This tools makes it easy to set the logo size, aspect ratio, and location in ways useful for image and animation output.

The current state of this python is a script with a simple GUI. It is unfinished but in a usable state and lacking documentation. The GUI options are a bit long and confusing at first.

Download the script: logo_helper.zip

Texture mapping tool

This code enables a very simple and handy way of texture mapping. The code can handle pre-selected (multiple) parts or the user can select a single part within the script GUI. Additionally the mapping direction and the texture image must be chosen. Now click “Create” and the code will automatically grab the dimension of all selected parts and map the texture over the whole part surface. The GUI remains open so the user can rotate the plane tool for adjusting the texture.


Continue reading

Quick save a plot as an image

This simple script provides a fast way to save a singular plot as an image, with no other objects from the graphics window visible.

It provides a few options that need to be edited in the file (notably the image save path) and a few other options that are specified in a pop-up window. I think usage is fairly straight forward. If this script is used often, one will probably want to remove the pop-up window and set the options to the desired defaults inside the script. The script should work regardless of whatever else is visible in the graphics window, and should restore the view to it’s original state after running. Multiple viewports are supported, but the script may fail if the maximum allowed 16 viewports exit.

The saved images will be named after the Plot name. In a duplicate filename exists the new name will be modified (existing images will not be overwritten).

Added a toggle in the GUI to allow toggling the background color automatically using EnSight.

Download the script image_plot2.py (updated April 23, 2014)

Gradient textures for coloring with two variables

EnSight has the ability to color a single part by 2 different variables by using a bitmap texture. Each axis of the texture is assigned to one variable. A sample image is included with EnSight (dual_gradient.png in the cube data directory) which has one axis as color and the other axis as transparency. Sometimes the user may want to use different colors for each axis instead of transparency, but this requires having the texture to use.

This script uses EnVe to create a custom image for this purpose, by letting the user define the colors of the 4 corners of a 256×256 square, and interpolating the color values between them. It is a barebones script with little documentation, but is also short and simple to use. In this post is also an archive with a few images created with the script.

Images: gradient_textures.zip

Script: make_image_4_color_square.py

Below is a screenshot of the textures dialog, with the settings changed to the optimal settings for using gradient textures (in most cases).

Texture Mode: Decal or Replace

Repeat Mode: Clamp or Clamp to Texture

Interpolation: Nearest

Compute Texture Coordinates by: Variables

S Variable and T Variable: select 2 scalar variables. Ideally the range of these variables are between 0 and 1. Read the How To manual for more information.

Note that if your variable values var1 + var2 <= 1 (for example mass, volume, or mole fraction) then you will only use the bottom-left triangle half of the square.


Creating Custom Color Palette from Image

Suppose you have an image that was created in another package, and you would like to replicate the color palette used in the image within EnSight? Well, EnSight can easily accept custom Color Palettes (see UserManual). The only “tough” part is getting from original image file the RGB values used and into a form of the EnSight Color Palette (.cpal) file. Well, guess what, Python (and more specifically EnVe) can be used to grab out the color legend information, and create your own color palette file (.cpal) for EnSight.

So, how you go about doing this:

1. Start with an image created in another package, which has a color legend. Crop the image to just the color legend palette. You now have an image file which has (in this example) a vertical specification of the color palette.

2. Use the attached python routine below on this file image file. This python routine uses EnVe to query the image file for the RGB values of the pixels in the image, and grab those values off, and write out an EnSight Color Palette file (.cpal) with the appropriate information in it. (If your image has a horizontal legend, then you can switch the x,y values around to perform the same operation).

3. You can thus create a new EnSight Color Palette File (.cpal) from the original image created in another package. EnSight has a limit of 21 bands, but handles 16 colors per band for smooth palette range.


As always, please contact us here at CEI should you have any questions, comments, having trouble, or would like routines this customized to your needs. We are here to help.

Click here for Color Palette Create Tool


Dynamic Range Plotter

Suppose that you have a transient domain, where you have some information at a high temporal frequency, but your time domain is relatively large. If you make a default plotter, the temporal range is too large to see the high frequency information. But, if you zoom in the time range, you are “fixed” to a particular time. Suppose you’d like to see both the higher frequency information, but also the whole time domain?

Python to the rescue again. Using Python, we can dynamically adjust the time range of the graph at each timestep… and thus create a plotter with a relatively small time “window”, but that window moves with the current timestep, so that you can see the whole time domain.

Here is a short example of what such a “dyanmic range plotter” would look like:


Here is a short tutorial on using this python tool:


And here is the tool itself:

dynamic range plotter python

Vector length legend for vector arrows

This script requires some effort from the user and if used incorrectly it could lead to wrong or misleading information.

One of the EnSight created part types is a “Vector Arrow” part. The length of these arrows can be in proportional to the magnitude of the vector used to create them (the arrows can also be set to have uniform length). So the length of the arrows has definite meaning, but there is no ‘legend’ like the color palette legend which indicates what the length of a vector arrow means.

This script can create such a legend semi-automatically, but the legend is only accurate in certain situations. Since the arrows and the legend are in a 3D space, the direction the arrows are viewed from will affect how large the arrows appear. So I recommend using this legend only in certain situations such as:

  1. When all the arrows lay in a 2D plane, and they are viewed orthogonally with perspective view turned off (orthographic view mode)
  2. When the viewer can rotate the view, and therefore gauge the 3D scene and have an intuitive feeling about the distortion in size due to the viewer’s perspective

Example: The arrow length shows velocity while color indicates temperature.

The script performs a few simple steps:

  1. Create a single node using a point part
  2. Create a vector variable of unit magnitude on the node using MakeScalNode and MakeVect
  3. Create a vector arrow part on this node using this vector variable

The script will prompt you for the location and direction of the arrow. If desired, the location of the arrow can be changed by editing the point part. After the script runs the user should do two things:

  1. Adjust the arrow length by changing the scale factor of the Vector Arrow Legend part
  2. Create a text annotation indicating the meaning of the length of the reference arrow

One must be careful when scaling the legend arrow so that it represents the correct value. One could follow these steps:

  1. Adjust the scale factor of your vector arrow part(s) (not the legend part) to get the desired vector lengths. Call the scale factor “A”.
  2. Choose a vector value that you want the legend to represent, call this value “B”
  3. A * B = C, C is the scale factor you should use for the Vector Arrow Legend part (since the original vector magnitude is one). Now the legend arrow should be the same length in 3D space as an arrow that has vector value B.
  4. The text annotation should use the value B

Download the script. vector_legend.py

If you like the idea of a vector arrow length legend and would like to see it added as a standard feature of EnSight you can vote for it and other features at ideas.ceisoftware.com. Link to the arrow legend request

Assign Unique Node IDs

EnSight allows nodes and elements on different parts to have the same node ID numbers. For example it is perfectly fine to have a node #1 on every part even though those nodes are not the same node. In most cases EnSight provides a way to distinguish between these nodes, for example if you query a node ID, EnSight will query the node on the part(s) that you have selected.

However, there are a few somewhat uncommon situations when one does need unique node ID numbers. Two example are when using a Periodic Matchfile (for periodic boundaries), and when positioning the plane tool using 3 nodes.

This script will assign a unique node ID to every node in the geometry.

  • Run the script and select a .geo file
  • Requires the .geo file to be ascii (not binary)
  • Starts with node ID 1 and goes up from there
  • Ignores the current node IDs, accepts any type (none, assign, given)
  • Creates a new file with the old .geo name, and renames the original to “…_original.geo”

Possible enhancements (does not do this now):

  • Automatically convert all the .geo files in a transient simulation
  • Read and write binary .geo files
  • Change element IDs

Download the script. assign_unique_node_id.py

Moving Clip Plane

In EnSight we can move a clip plane depending on a selected part (e.g. a piston surface) over time. This can be done by this command:

test: special xyz clip

Recently a user asked me to automatize this feature. For this it’s necessary to create a new variable which has to be selected. No problem within the GUI but this was not possible in former EnSight versions by script. Thus this routine will only run on EnSight 10.0.2(f) or later. The result should look like this:


This routine is written as a user defined tool. If you have an existing directory for your own tools just put it together with the image into that directory. Otherwise it can be used as a standalone tool as well if line 156 is activated. Please contact me if you have any problems (david@ceisoftware.com).

The tool will launch a GUI which asks for the fluid part which is clipped, the piston part surface and the moving direction. The tool is capable to create a new clip plane if toggled. Otherwise the name of an existing clip has to be typed in.



Custom Image Save Shortcut

A customer recently asked if a more custom save image could be created. He always wants to use the “Default Print Colors”, and always wants to save out a certain image type and size. His main concern was always having to toggle on the “default print colors”, (as they are turned off after the image is saved), and the 6 mouse clicks/operations to save an image (File (1), Export(2), Image (3), specify filename (4), Default Print colors (5), and Ok (6)).

One option is to use the right Click (Right Click to Viewport — > default print colors), the Right Click again to Save image to file, then specify file name, and Ok. These are perfectly okay when saving a few images, but having to save 20 or 30 images, and you would want to look for a shortcut way to do this.

With EnSight’s scripting, and two lines of python, this can be made into a nice short macro, which would do the above steps in a single keystroke.

Here is the python macro (you can directly assign this to any of your favorite keyboard short cuts):

# Example Python to Create new Output image
import datetime
Basename = "EnSight_Image_"

# Use datetime to generate a filename with unique name
now = datetime.datetime.now()
unique_part = now.strftime("%Y-%m-%d_%H-%M-%S")
new_filename = str(Basename) + str(unique_part)

# Save the image


Here, the three lines of python obtain the current time, and append that to the name “EnSight_Image_” in order to create a unique filename to be saved. The remaining lines in the file are direct EnSight journal commands converted to Python. Note here the use of the “image_convert” lines which do the operation of the default print colors.

So, with only three lines of python, you now can take the journal commands from a file save and make them into a quick shortcut to save an image out.