---
title: "MaxScript"
canonical: "https://documentation.chaos.com/space/PHX4MAX/125310915/MaxScript"
format: markdown
---
This page provides information on how MaxScript can be used with Chaos Phoenix.

## **Overview**

---

During the simulation process you can directly access the Simulator's content using Phoenix's MaxScript functions.

You can use these functions to script advanced simulation rules, or to e.g. control a simulation on a remote machine that runs using only a [Simulation License.](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/124528396)

 

## **Callback Functions**

---

These functions are available when you enable **Use Script** in the [Simulation rollout](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125084848) of a Phoenix Simulator.

At different moments of the simulation, Phoenix will call them and you can add your custom MaxScript code inside.

This MaxScript code is separate for each different Simulator and is saved to the 3ds Max scene file.

For example, it is possible to add script for starting another Simulator automatically once a simulation ends, or start of a sequence or single frame rendering (see [this example](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125311346/Tips+and+Tricks#RendMaxScript)).

The following functions are available:

|  |  |
| --- | --- |
| **Function** | **Description** |
| <span style="color: #330000">OnSimulationBegin</span> | Called after the initialization of the simulator is done and before first execution. |
| <span style="color: #330000">OnSimulationStep</span> | Called before each simulation step, after the interaction with the scene. |
| <span style="color: #330000">OnSimulationEnd</span> | Called after the end of the simulation. The simulation core, referred to by the 'this' variable, would be already destroyed during this callback so it should not be accessed. |
| <span style="color: #330000">OnNewFrame</span> | Called after each frame export. |

 

## **Global Variables**

---

The following global variables are initialized before entry in the callback functions:

|  |  |
| --- | --- |
| **Variable** | **Description** |
| this:<simulator> | Points to the simulator that calls the callback function |
| t:<float> | The simulator's internal time |
| dt:<float> | The simulator's internal step duration |

 

## **Global Functions**

---

These are the Phoenix-specific functions you can call from 3ds Max's MaxScript listener, or from the Callback Functions above, or for example from a MaxScript file that you pass to 3ds Max on startup.

Each of the simulation grid channels (temperature, velocity, smoke etc.) exists in two instances - one instance is in the simulation core, while the simulation is running, and the other instance is in the loaded simulation cache files, which you can also access even when no simulation is running. The functions in this section can access both the simulation core and cache files. If the first argument passed to the function specifies a Phoenix Simulator node, then the function accesses the cache file data. If there is no explicit Phoenix Simulator node specified, the function accesses the currently running simulation core, and it's not ambiguous because only one Simulator can be started at a time.

Note that the simulation core exists only during the simulation and can be accessed only in the Callback Functions using the **this** global variable.

 

|  |  |
| --- | --- |
| **Functions** | **Description** |
| A_SetSystem<br>Parameters:<br>system:<integer><br>Available options are:<br>0 - Object space<br>1 - World space<br>2 - Grid (voxel) space<br>Return value:<br>none | Specifies which coordinate system will be used. |
| A_Inject<br>Parameters:<br>where:<point3><br>amount:<float><br>[temperature:<float>]<br>[smoke:<float>]<br>[velocity:<point3>]<br>[RGB:<point3>]<br>Return value :<br>none | Injects fluid in a given point. Using this function, you can create your own procedural sources. The result of the function CAN NOT be achieved by calling one or more A_SetX functions, because they do not affect the quantity of the fluid, but only the parameters carried by the fluid. The injection of fluid in some point causes changes in the content only of the nearest 8 cells, but produces an outgoing flow in the entire grid. Nevertheless the function is not slower than the ordinary A_SetX function, because the outgoing flow appears later, when the simulation is executed. If A_GetV function is executed immediately after A_Inject in some near point, the velocity will not be changed. |
| A_SetV<br>Parameters:<br>x:<integer><br>y:<integer><br>z:<integer><br>velocity:<point3><br>Return value :<br>none | Sets the velocity of a cell. If a Simulator name is used, the function will write to the loaded cache, otherwise the function will write into the grid of the running simulator, if any. |
| A_SetRGB<br>Parameters:<br>x:<integer><br>y:<integer><br>z:<integer><br>RGB:<point3><br>Return value :<br>none | Sets the RGB of a cell. If a Simulator name is used, the function will write to the loaded cache, otherwise the function will write into the grid of the running simulator, if any. |
| A_SetT<br>Parameters:<br>x:<integer><br>y:<integer><br>z:<integer><br>temperature:<float><br>Return value :<br>none | Sets the Temperature of a cell. If a Simulator name is used, the function will write to the loaded cache, otherwise the function will write into the grid of the running simulator, if any. |
| A_SetSm<br>Parameters:<br>x:<integer><br>y:<integer><br>z:<integer><br>smoke:<float><br>Return value :<br>none | Sets the Smoke of a cell. If a Simulator name is used, the function will write to the loaded cache, otherwise the function will write into the grid of the running simulator, if any. |
| A_SetFl<br>Parameters:<br>x:<integer><br>y:<integer><br>z:<integer><br>fuel:<float><br>Return value :<br>none | Sets the Fuel of a cell. If a Simulator name is used, the function will write to the loaded cache, otherwise the function will write into the grid of the running simulator, if any. |
| A_GetFl<br>Parameters<br>where:<Point3><br>Return Value:<br><float> | Gets the Fuel in a given point. If a Simulator name is used, the function will read from the loaded cache, otherwise the function will read from the running simulator, if any. |
| A_GetV<br>Parameters<br>where:<Point3><br>Return Value:<br><point3> | Gets the Velocity in a given point. If a Simulator name is used, the function will read from the loaded cache, otherwise the function will read from the running simulator, if any. |
| A_GetRGB<br>Parameters<br>where:<Point3><br>Return Value:<br><point3> | Gets the RGB in a given point. If a Simulator name is used, the function will read from the loaded cache, otherwise the function will read from the running simulator, if any. |
| A_GetT<br>Parameters<br>where:<Point3><br>Return Value:<br><float> | Gets the Temperature in a given point. If a Simulator name is used, the function will read from the loaded cache, otherwise the function will read from the running simulator, if any. |
| A_GetSm<br>Parameters<br>[node:<Simulator>]<br>where:<Point3><br>Return Value:<br><float> | Gets the Smoke value in a given point. If a Simulator name is used, the function will read from the loaded cache, otherwise the function will read from the running simulator, if any. |
| > Macro (anchor)

A_StartSim<br>Parameters<br>node:<Simulator><br>[cache: <String>]<br>[startframe: <integer>] | Starts the simulation. Passing just the simulator node will start a new simulation. If you pass the path to a cache file, the effect is that of the [Load & Start button](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125084848/FireSmoke+Simulation#Load) in the [Simulation ](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125084848)rollout: the simulation state will be loaded from the cache and the simulation will continue from the specified [Start Frame](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125084848/FireSmoke+Simulation#StartFrame). If you manually pass the **startframe** index too, it takes precedence over the Load function and the simulation will be **restored** from the given frame, the same way that the [Restore button](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125084848/FireSmoke+Simulation#Restore) works.<br>This function will decide between simulation and re-simulation depending on the state of the [Particle Resimulation](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125312243/FireSmoke+Resimulation#EnableParticleResimulation) and [Grid Resimulation](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125312243/FireSmoke+Resimulation#EnableGridResimulation) switches. |
| A_StopSim<br>Parameters<br>node:<Simulator> | Stops the simulation |
| A_Wait<br>Parameters<br>node:<Simulator> | This function halts the execution of the script until the specified simulator has finished running. Usually this function is used along A_StartSim when you want to run certain actions after the simulation is finished.<br>> ⚠️ Use this function extremely carefully because it does not block the GUI of 3ds Max. |
| A_CreateParticle<br>Parameters<br>Particle group:<string><br>where:<Point3><br>[Radius:<float>]<br>[Velocity:<Point3>]<br>Return Value:<br>none | Creates a new particle in a given position with given properties. |
| A_Freeze<br>Parameters:<br>x:<integer><br>y:<integer><br>z:<integer> | Freezes the given cell. The frozen cell acts as a [Solid object](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/124528638). |
| A_Unfreeze<br>Parameters:<br>x:<integer><br>y:<integer><br>z:<integer> | Unfreezes the given cell. Keep in mind that the simulator counts the freezing operations and you have to execute the same number of unfreezing operations to successfully unfreeze a cell. |
| A_QuickSetup<br>Parameters:<br>setup: <integer><br>Available options are:<br>0 - fire  
1 - fuel fire  
2 - explosion  
3 - gasoline explosion  
4 - large smoke  
5 - cold smoke  
6 - cigarette smoke  
7 - candle  
8 - clouds<br>9 - tap water  
10 - milk  
11 - beer  
12 - coffee  
13 - honey  
14 - liquid chocolate  
15 - blood  
16 - paints  
17 - ink in water  
18 - waterfall  
19 - ocean<br>Return Value:<br>none | Creates a [Quick Setup](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/124660109) with the selected objects (the Quick Setup presets can be applied over a selection of several objects). |
| > Macro (anchor)

A_LoadRenderPreset<br>Parameters<br>node: <Simulator><br>preset path: <String> | Loads the specified render preset file. This is the same as using the [Render Presets... menu from the Rendering rollout of the Simulator](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/124396558).<br>The preset path can be a full path or use the *$(dir)* macro, which denotes the current scene file's directory.<br>For example, the following will load "preset.tpr" from the current scene directory:<br>A_LoadRenderPreset (getnodebyname "PhoenixFDFire001") "$(dir)\preset.tpr" |
| A_SaveRenderPreset<br>Parameters<br>node: <Simulator><br>preset path: <String> | Saves a Phoenix render preset to a file with the current render and preview settings.<br>This is the same as using the [Render Presets... menu from the Rendering rollout of the Simulator](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/124396558).<br>The preset path can be a full path or use the *$(dir)* macro, which denotes the current scene file's directory. |
| A_LoadSimPreset<br>Parameters<br>node: <Simulator><br>preset path: <String> | Loads the specified simulation preset file.<br>This is the same as using the [Simulation Presets... menu from the Simulation rollout of the Simulator](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125084848).<br>The preset path can be a full path or use the *$(dir)* macro, which denotes the current scene file's directory.<br>For example, the following will load "preset.tpr" from the current scene directory:<br>A_LoadSimPreset (getnodebyname "PhoenixFDFire001") "$(dir)\preset.tpr" |
| A_SaveSimPreset<br>Parameters<br>node: <Simulator><br>preset path: <String> | Saves a Phoenix simulation preset to a file.<br>This is the same as using the [Simulation Presets... menu from the Simulation rollout of the Simulator](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125084848).<br>The preset path can be a full path or use the *$(dir)* macro, which denotes the current scene file's directory. |
| *[available since Phoenix FD 4.10.04]*<br>A_GetGridSize<br>Parameters<br>node: <Simulator><br>channel name: <String><br>Return Value:<br><point3> | Retrieves the grid size of the running Simulator or the loaded cache file if a simulation is not running.<br>Useful when using adaptive grid, in which case this.xc, this.yc and this.zc will return only the initial grid size.<br>The name of the grid channel is reserved for future use. Currently all grid channels are the same size. |
| *[available since Phoenix 5.01.02 Nightly, Build ID: 2022120531780]*<br>A_ExportSimscene<br>Parameters<br>export path: <String> | Exports a simscene file which you can use for simulation at a later time or on a different machine. See this page for more information on [exporting .simscene files for Phoenix Standalone simulation](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125311148). |

 

 

## **Global Interface**

---

Phoenix also provides a global <span style="color: #172b4d">interface which can be used to obtain data which is not specific to any particular Phoenix node.</span>

> ℹ️ **Example usage:**  
> ℹ️ IPhoenix.getCopyrightsString()

 

The available functions are:

|  |
| --- |
| **getVersionString**<br>Returns a string with the exact Phoenix version. |
| **getTargetString**<br>Returns a string with the 3ds Max version and Phoenix build type. |
| **getCopyrightsString**<br>Returns a string with all credits and copyrights for Chaos Phoenix and all 3rd party software used. |

 

 

## **Per-Node Functions**

---

Phoenix also provides an <span style="color: #172b4d">interface for getting grid data and loading render presets by typing in directly the Simulator node.</span>

> ℹ️ **Example usage:**  
> ℹ️ $PhoenixFDFire001.getFuel (Point3 15 15 15)

 

The available functions are:

**getVersion **– *[available since Phoenix FD 4.10.04] *Gets the currently installed Phoenix version.  
**setCoordSys **– Specifies which coordinate system will be used.

 Available options are:

0 - Object space

1 - World space

2 - Grid (voxel) space

**getGridSize** – *[available since Phoenix FD 4.10.04] *Retrieves the grid size of the running Simulator or the loaded cache file if a simulation is not running.  
**loadRenderPreset **– Loads a previously saved Phoenix render preset from a file.  
**saveRenderPreset **– Saves a Phoenix render preset to a file with the current render and preview settings.  
**loadSimPreset **– Loads a previously saved Phoenix simulation preset from a file.  
**saveSimPreset **– Saves a Phoenix simulation preset to a file with the current render and preview settings.  
**getVelocity** – Gets the Velocity value in a given point.  
**getRGB **– Gets the RGB value in a given point.  
**getTemperature **– Gets the Temperature value in a given point.  
**getSmoke **– Gets the Smoke value in a given point.  
**getFuel **– Gets the Fuel value in a given point.  
**reloadFrame **– Forces a load on the cache frame for the current timeline time.  
**getFrameInfo **– Returns a string with information on the currently loaded cache frame. This is the info that you can find in the [Simulation rollout](https://docs-chaos.atlassian.net/wiki/spaces/PHX4MAX/pages/125084848)'s *Cache File Content* box.