MAXScript / DotNet Value Conversions

MAXScript will automatically convert its native values to DotNet values and DotNet values to MAXScript values.

In addition, value conversion can be performed explicitly using a dedicated function in 3ds Max 2010 and higher.

Automatic Conversion

The following table shows the native MAXScript value types and the converted DotNet value types in 3ds Max 9 and higher.

MAXScript type DotNet type
Integer Byte, SByte, Decimal, Int16, UInt16, Int32, UInt32
Integer64 Int64, UInt64
IntegerPtr IntPtr, UIntPtr
Float Single
Double Double
Boolean Boolean
String String, Char array

Numeric MAXScript values (Integer, Integer64, IntegerPtr, Float, and Double) are also converted to any of the other numeric DotNet types listed above when a DotNet method or property expects that type. For example, an Integer can be passed where an Int64, Single, or Double is expected.

Time values are not converted automatically. To pass a Time value to a DotNet method, convert it first, for example with t.frame (frames as a Float) or t as integer (ticks as an Integer), or use dotNet.ValueToDotNetObject.

The following table shows the DotNet value types and the converted native MAXScript value types.

DotNet type MAXScript type
Byte, SByte, Int16, UInt16, Int32, UInt32 Integer
Int64, UInt64 Integer64
IntPtr, UIntPtr IntegerPtr
Single Float
Double, Decimal Double
Boolean Boolean
String String
Char array Array of single-character Strings

Explicit Conversion

The following method performs a conversion of a MAXScript value to a DotNet value.

Available in 3ds Max 2010 and higher.

dotNet.ValueToDotNetObject <value> { <dotNetClass> | <dotNetObject> }

Returns a dotNetObject value where the MAXScript value passed as first argument is converted to a DotNet object of the type specified by the second argument.

A Time value is converted to a number of frames at the current frame rate, not to ticks. Integer types such as Int32 and Int64 drop any fractional frame, so 5.5f becomes 5. Floating-point types such as Single, Double, and Decimal keep it, so 5.5f becomes 5.5. Time values cannot be converted to String, TimeSpan, or Object.

Available in 3ds Max 2018.2 Update and higher: Some native MAXScript types are converted into .NET arrays, as some .NET libraries do not support these types natively. Point2, Point3, Point4, Quat, EulerAngles, and Matrix3 types are all converted into float\[\] or double\[\] arrays.

Note: EulerAngles are displayed in degrees, but are stored internally as radians, so the converted .NET values are in radians.

This allows for the easy creation of DotNet arrays from MAXScript arrays:

<value> dotnet.DotNetArrayToValue <dotNetObject> <Matrix3 | Point2 | Point3 | Point4 | Quat | EulerAngles>

Available in 3ds Max 2018.2 Update and higher: Converts the .net array to a value of the specified mxs value type. The .net arrays must be of type float or double. For Matrix3, the .net array must be of size [4,4] , for Point2 it must be of size [2] , for Point3 and EulerAngles it must be of size [3] , and for Point4 and Quat it must be of size [4] .

<value> dotnet.DotNetObjectToValue <dotNetObject>

Available in 3ds Max 2018.2 Update and higher: Converts the .NET object to a MAXScript value.

EXAMPLES

   type = dotNetClass "System.Int32[]"
   --> dotNetClass:System.Int32[]
   res = dotnet.ValueToDotNetObject #(11,12,23) type
   --> dotNetObject:System.Int32[]
   res.length
   --> 3
   res.getvalue 2 --DotNet arrays are zero-based.
   --> 23
   typef = dotnetclass "System.Single[]" --> dotNetClass:System.Single[]
   vf = dotnet.ValueToDotNetObject x_axis typef --> dotNetObject:System.Single[]
   vf.get 0 --> 1.0
   typed = dotnetclass "System.Double[]" --> dotNetClass:System.Double[]
   vd = dotnet.ValueToDotNetObject x_axis typed --> dotNetObject:System.Double[]
   vd.get 0 --> 1.0d0
   typefa = dotnetclass "System.Single[][]" --> dotNetClass:System.Single[][]
   vfa = dotnet.ValueToDotNetObject #([1,2],
       [1,2,3],
       [1,2,3,4],
       (quat 0.854433 0.00437304 0.0050751 0.519518),
       (eulerAngles -117.399 -0.757267 0.126046)
       )  typefa  --> dotNetObject:System.Single[]
   vfa0 = vfa.get 0 --> #(1.0, 2.0)
   vfa1 = vfa.get 1 --> #(1.0, 2.0, 3.0)
   vfa2 = vfa.get 2 --> #(1.0, 2.0, 3.0, 4.0)
   vfa3 = vfa.get 3 --> #(0.854433, 0.00437304, 0.0050751, 0.519518)
   vfa4 = vfa.get 4 --> #(-2.049, -0.0132168, 0.00219992)
   typef2 = dotnetclass "System.Single[]"
   vfa2 = dotnet.ValueToDotNetObject (matrix3 [0.99991,0.0127462,0.00412892]
       [0.00219972,-0.460163,0.887832]
       [0.0132164,-0.887743,-0.46015]
       [90,0,-45]) typef2  --> dotNetClass:System.Single[,]
   vfa2.get 0 0 --> 0.99991