Rendering Functions

Renderings can be created in the Rendering Editor, but can also be created using a function. The purpose of a rendering function is to provide a way to generate visual representations of objects that can't be generated using only the renderings that can be created in the Rendering Editor.

Typically, it's easier to use the Rendering Editor to create a rendering than it is to create a rendering function. But rendering functions give you more flexibility than the Rendering Editor. When a function is used to generate a rendering, the rendering for that object will specify a function name rather than containing a graphical rendering.

Suppose you have created a new object definition called MyObject in the Math namespace. To create a rendering function for MyObject:

  1. Create a function called GenerateMyObject. The name of the function could be any valid object name and the type for any rendering function must be ObjectObjectRendering. Rendering functions in the existing libraries are in the Render namespace, but this isn't required.
  2. Add one or more clauses to GenerateMyObject. For this example, we will just copy the rendering of the Not object in the Logic namespace and paste it into the right hand side of the clause. There would be no reason to create a rendering function if that was all that was intended, but it keeps this example simple. Now we have a function that looks like this:

    For more information about the expressions that can appear on the right side of rendering function clauses, see Rendering Expressions

  3. Highlight the object definition for MyObject in the object module and select the Add Rendering name option from the context menu.
  4. Enter the appropriate rendering name (Standard, for example).
  5. Right click on the rendering name expression and select Add rendering function.
  6. Enter GenerateMyObject in the empty box after the Function: in the rendering definition expression.

At this point, the object definition will look something like:

To see the function itself, you can highlight GenerateMyObject in the rendering name expression and press F12.

In many cases, the easiest way to create a rendering function is to just copy a rendering and paste into the right-hand side of a clause in the rendering function. What is copied on the clipboard is the rendering expression for the graphical rendering that is selected. Just find a rendering that is somewhat similar to the rendering that you intend to create with the function. If you need to, you can create a temporary object and use the Rendering Editor to create a starting point for the rendering that will be generated by the function.

Note that an object definition can contain a rendering with both a rendering function and a rendering created using the Rendering Editor. In this case, the rendering function is executed first, if this function returns null, then the graphical rendering from the Rendering Editor is used.

If an object doesn't have either a rendering function or and graphic rendering built in the Rendering Editor or if a rendering function exists but returns a null, then the default rendering is used. The default rendering is generated by the DefaultRendering function.