DMM Varkon® Tutorial
A Beginner's Guide to the Varkon Parametric Modeling and CAD Application Development System
By David M. MacMillan

15. Automation, Animation

Because Varkon models are programs and are parametric, it is possible to automate their execution in different circumstances by supplying different parameters, and by controlling them from another source, also a program. These techniques can be used to generate the frames of an animation of the model in motion.

15.1. How I Had Wanted it to Work

My initial attempt at animation failed, but since I still think it would have been the right way had it worked, I'll record it here in case either I'm wrong (and it could have worked) or it might work in a future version of Varkon.

What I tried to do was to invoke and control Varkon 1.15C from the UNIX command line. A UNIX-philosophy program should have a mode of operation in which it works like a filter, reading its input from the standard input (stdin) and writing its output to the standard output (stderr). In this way, programs can be linked together via "pipes" and I/O redirection. When combined with shell script programming, this provides a powerful technique for automation.

In the case of Varkon, what I wanted it to do was to read the compiled object code of an active module as its stdin and to write a plot file to stdout. I achieved only a part of this goal. I wote an Awk language script which took the MBS source of an active module, renamed it with a temporary module name, and added statements to it which ran the active module (run_mbs) and plotted the output. This I invoked via a shell script which compiled the module so modified and fed it into an invocation of Varkon. Unfortunately, I could not find a way to force Varkon to run in the background. It always created windows on the screen and prompted for user interaction.

However, I realized after some consideration that I could achieve my goal of animation from within Varkon itself, as described below.

15.2. Automating and Animatin a Job using Macro Modules

As an example of automating Varkon to produce an animation, consider the following simple model:

local drawing module cutcircle ();

   vector center;
   float  radius;


   center := vec (0, 0);
   radius := 5;
   arc_1pos (#1, center, 5, 0, 360);
   lin_free (#2, vec (-radius, 0), vec (radius, 0));


This module draws a circle and divides it with a single diametrical line. It can be called by an active module such as this:



  csys_1p(#1,"circlesys", vec(0, 0), 0, 0, 0);


Since the cutcircle.MBS module operates in a local coordinate system, in the active module we create a coordinate system for it. As presented, the circle is not rotated (the diametrical line is horizontal). Should we wish to rotate it, we can simply rotate its coordinate system around the Z axis. For example, to rotate it 30 degrees counterclockwise, alter the coordinate system definition in this way:

  csys_1p(#1,"circlesys", vec(0, 0), 0, 0, 30);

To create a circle which spins, we need to repeatedly modify this Z axis parameter. This can be done from a macro module using the get_mbs() and updp_mbs() statements. get_mbs() queries a specified part of the active module and returns the current value of one of its parameters. We use this to get the current value of the Z axis parameter. updp_mbs() modifies (updates) an entity in the active model. The general procedure is to get the Z axis value from the model, add an increment to it, update the model with this new value, and then reexecute and plot the model. The following macro procedure does this 36 times, using 10 degree increments. This causes the circle to appear to rotate on the screen. It also causes the generation of 36 plot files, each of which contains a plot of one "frame" of this animated rotation.

macro module animate ();

string anglestr*8;
float  angle;
int    ix;
float  plotnum;
string plotfile*132;


for ix := 1 to 36 do
   anglestr := getp_mbs (#1, 5);
   angle    := val (anglestr) + 10;
   updp_mbs (#1, 5, str(angle), 1);
   run_mbs  ();
   plotnum  := ix;
   plotfile := str(plotnum, 1, 0);
   plotfile := plotfile+".PLT";
   plot_win(vec(-10,-10), vec(10,10), plotfile);


One difficulty in developing this module is that Varkon (1.15C, at least) loads macro modules into memory the first time they're called within a project and does not reload them when they are called again. If you make a change in a macro module and recompile it, you need to exit the current project and restart it to use the newly modified module.

This macro module produces 36 plot files, named 1.PLT to 36.PLT.

15.3. Automating and Animatin a Job using Drawing and Geometry Modules

I then discovered that the control and I/O structures which enable the generation of animation using MACRO modules are also present in ordinary DRAWING and GEOMETRY modules. The method described above can therefore be implemented directly in a DRAWING or GEOMETRY module without the complexity of a MACRO module level.

For an example of animation in non-MACRO modules, see the chapter "Example: Pendulum Demo" later in this Tutorial.

Legal Matters

With the exception of any material noted as being in the public domain, the text, images, and encoding of this document are copyright © 1998 by David M. MacMillan.

The author has no relationship with Microform AB, and this Tutorial is neither a product of nor endorsed by Microform AB.

"Varkon" is a registered trademark of Microform AB, Sweden.

This document is licensed for private, noncommercial, nonprofit viewing by individuals on the World Wide Web. Any other use or copying, including but not limited to republication in printed or electronic media, modification or the creation of derivative works, and any use for profit, is prohibited.

This writing is distributed in the hope that it will be useful, but "as-is," without any warranty of any kind, expressed or implied; without even the implied warranty of merchantability or fitness for a particular purpose.

In no event will the author(s) or editor(s) of this document be liable to you or to any other party for damages, including any general, special, incidental or consequential damages arising out of your use of or inability to use this document or the information contained in it, even if you have been advised of the possibility of such damages.

In no event will the author(s) or editor(s) of this document be liable to you or to any other party for any injury, death, disfigurement, or other personal damage arising out of your use of or inability to use this document or the information contained in it, even if you have been advised of the possibility of such injury, death, disfigurement, or other personal damage.

All trademarks or registered trademarks used in this document are the properties of their respective owners and (with the possible exception of any marks owned by the author(s) or editor(s) of this document) are used here for purposes of identification only. A trademark catalog page lists the marks known to be used on these web pages. Please e-mail if you believe that the recognition of a trademark has been overlooked.

Version 1.3, 1998/06/17. Feedback to

Go to the: