Personal tools
You are here: Home / cmgui / Wiki / Writing out field values to a file from cmgui
Navigation
Log in


Forgot your password?
 

Writing out field values to a file from cmgui

If you create a new field in cmgui you may then want to write out the field values at your node or data points. For example, you may want to offset all your coordinates for the nodes in group mynodes and then write out the new coordinates.

This is possible, but only indirectly, using a fairly simple trick.

The key thing to remember is this: you can only write out a field that has already been previously read in from a file (eg from a .exnode or .exdata file).

Here is an example that will NOT work:

# read in nodes
gfx read node mynodes
# create offset field
gfx def field offset_coords offset field coordinates offsets 10 -10 0
# write out field
gfx write node group mynodes field offset_coords new_file

cmgui will complain about an unknown field offset_coords.

To get around this you need to read in another field that you can change the values of and then write out. The easiest way to do this is to take the .exnode file and make a copy of it, with a different name for the coordinates field. Lets say I copy my node file to mynodes2 and change the word coordinates in the file to the word modified_coordinates. I can now read in a coordinates field AND a modified_coordinates field for the nodes.

I do the following to write out my offset field:

# read in nodes with first field (coordinates)
gfx read node mynodes
# read in nodes with second field (modified_coordinates)
gfx read node mynodes2
# create offset field
gfx def field offset_coords offset field coordinates offsets 10 -10 0
# evaluate the field offset_coords at all the node values in the
# node group and store the results in the modified_coordinates field
gfx eval ngroup mynodes source offset_coords destination modified_coordinates
gfx write node group mynodes field modified_coordinates new_file

A word of caution! You may wonder why you can't just evaluate your field using the coordinates field as your desination field like so:

gfx eval ngroup mynodes source offset_coords destination coordinates

This would save having to create a new file and edit the word coordinates BUT wierd things happen when you play with your coordinates field. It is best left alone, create a second one to play with instead.