dotnetclass

In 3ds Max 9 and higher, the dotNetClass wraps a DotNet System::Type and exposes the static properties, methods, and events associated with the class via reflection.

Property access uses MAXScript number data types (widened as necessary), String, Boolean, dotNetControl, dotNetObject, and dotNetClass values. Properties are accessed via the normal property access specification [control.property] and getProperty() / setProperty() methods.

Accessing a class method will create a dotNetMethod instance, or optionally a dotNetObject wrapping the RuntimeMethodInfo instance.

New methods are used to add and manage event handlers. These methods register and unregister callback functions to be called when the event is fired. The arguments passed back to the functions will include the class, the event name, and the arguments passed by the event handler. See dotNet Struct Methods for details.

Note:

There is a difference between a dotNetClass and a dotNetObject that wraps the same type.

Accessing the dotNetClass accesses the System::Type while accessing the dotNetObject access the object type described by the System::Type.

So, for example, if you called showProperties() on a dotNetObject you will get the properties of the System::Type the dotNetObject wraps, but on a dotNetClass that wraps the same type you will get the properties of System::Type itself.

Constructor:

dotNetClass {<dotNetObject> | <dotNetControl> | <class_type_string> | <c_sharp_type_string> }

Constructs a dotNetClass object. If the argument is a dotNetObject or dotNetControl object, the dotNetClass will wrap the System::Type of that object. If the argument is a string, MXS will attempt to resolve the string as a System::Type name.

EXAMPLE

   theClass = dotNetClass "System.Drawing.Size"

This resolution is done using the following steps:

1. Attempt to resolve as a fully qualified name. A fully qualified name includes both the class name and the assembly name.

EXAMPLE

   dotNetClass "System.Windows.Forms.MonthCalendar, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

2. Attempt to resolve as a class name by looking for the name in each assembly loaded into the current AppDomain.

3. If no match is found, the name is prepended with "System." and another attempt will be made.

4. If no match is found, the name is prepended with "System.Windows.Forms." and another attempt will be made.

5. Finally, an attempt is made to match against built-in C# data type names to the matching .NET system type. The mappings are:

C# Built-in Type Name .NET Framework Type
bool System.Boolean
byte System.Byte
sbyte System.SByte
char System.Char
decimal System.Decimal
float System.Single
int System.Int32
uint System.UInt32
long System.Int64
ulong System.UInt64
object System.Object
short System.Int16
ushort System.UInt16
string System.String

Example

type = dotnetclass "bool[]" --> dotNetClass:System.Boolean[]
v = dotnet.ValueToDotNetObject #(false,true) type --> dotNetObject:System.Boolean[]
v.get 0 --> false
type = dotnetclass "byte[]" --> dotNetClass:System.Byte[]
v = dotnet.ValueToDotNetObject #(1,2) type --> dotNetObject:System.Byte[]
v.get 0 --> 1
type = dotnetclass "char[]" --> dotNetClass:System.Char[]
v = dotnet.ValueToDotNetObject #("A","B") type --> dotNetObject:System.Char[]
v.get 0 --> "A"
Note: C# built-in type string matching was introduced in 3ds Max 2018.2 Update.

Assemblies can be loaded to the Current AppDomain. See the dotNet.LoadAssembly() method in dotNet Struct Methods

An example of adding an assembly to the current AppDomain via methods exposed by the dotNetClass itself:

EXAMPLE

   assembly = dotNetClass "System.Reflection.Assembly"
   r = assembly.loadfrom "F:\\FlashTrackBar\\bin\\Debug\\FlashTrackBar.dll"
Note:

Assemblies can not be unloaded once loaded.

Methods:

getProperty <dotNetClass> <prop name> [asDotNetObject:<boolean>]

Returns the value of the specified property.

If asDotNetObject is false (the default) the value will converted to a native MAXScript value if possible; if true, the value will always be returned as a dotNetControl or dotNetObject value.

Note: You can use the .NET Type.MakeGenericType() method to access static generic methods on classes. See the dotNet Generics topic for an example of how to do so.
Note: Prior to 3ds Max 2020.3 Update, this returned a dotNetMethod if the specified property was a method, even if asDotNetObject was true.

EXAMPLE

   o = dotNetClass "System.String"
   -- o has only one property, .Empty:
   prop = getProperty o "Empty"
setProperty <dotNetClass> <prop name> <value>

Sets the value of the specified property.

If the value specified is a native MAXScript value, it will be converted to the proper DotNet value if possible.

getPropNames <dotNetClass> [showStaticOnly:<boolean>] [declaredOnTypeOnly:<boolean>]

Returns an array of property names exposed by the class.

If showStaticOnly: is true (the default), only static properties are shown; if false both static and instance properties are shown.

If declaredOnTypeOnly: is true, only properties declared on the specified class are shown; if false (the default) properties on the class and the classes it derives from are shown.

The results of this method are sorted by name. The properties returned actually contain two different things in terms of DotNet - properties and fields. The properties are shown first in sorted order, then the fields are shown in sorted order.

showProperties <dotNetClass> ["prop_pat"] [to:<stream>] [showStaticOnly:<boolean>] [showMethods:<boolean>] [showAttributes:<boolean>] [declaredOnTypeOnly:<boolean>]

Displays the properties exposed by the class whose name matches the property pattern.

If to is not specified, the output goes to Listener, otherwise the output goes to the specified stream.

If showStaticOnly: is true (the default), only static properties are shown; if false both static and instance properties are shown.

If showMethods: is true, the signature of the get and set methods (if any) are shown; defaults to false.

If showAttributes: is true, the attributes associated with the property are shown; defaults to false.

If declaredOnTypeOnly: is true, only properties declared on the specified class are shown; if false (the default) properties on the class and the classes it derives from are shown.

The results of this method are sorted by name. The properties returned actually contain two different things in terms of DotNet - properties and fields. The properties are shown first in sorted order, then the fields are shown in sorted order.

showMethods <dotNetClass> ["prop_pat"] [to:<stream>] [showStaticOnly:<boolean>] [showSpecial:<boolean>] [showAttributes:<boolean>] [declaredOnTypeOnly:<boolean>]

Displays the methods exposed by the class whose name matches the property pattern.

The prop_pat is a pattern string. See Pattern Strings for more information about special characters this string can contain.

If to is not specified, the output goes to Listener, otherwise the output goes to the specified stream.

If showStaticOnly: is true (the default), only static properties are shown; if false both static and instance properties are shown.

If showSpecial: is true, methods that are not normally called by the user (such as a method to set a property value or to invoke an event handler) are shown; defaults to false.

If showAttributes: is true, the attributes associated with the property are shown; defaults to false.

If declaredOnTypeOnly: is true, only properties declared on the specified class are shown; if false (the default) properties on the class and the classes it derives from are shown.

The results are sorted by name. Secondary sort is performed based on the number of parameters.

showEvents<dotNetClass> ["prop_pat"] [to:<stream>] [showStaticOnly:<boolean>] [declaredOnTypeOnly:<boolean>]

Displays the events exposed by the class whose name matches the property pattern.

The prop_pat is a pattern string. See Pattern Strings for more information about special characters this string can contain.

If to is not specified, the output goes to Listener, otherwise the output goes to the specified stream.

If showStaticOnly: is true (the default), only static properties are shown; if false both static and instance properties are shown.

If declaredOnTypeOnly: is true, only properties declared on the specified class are shown; if false (the default) properties on the class and the classes it derives from are shown.

The results are sorted by name.

dotNet.showConstructors <dotNetClass> [to:<stream>]

Displays the constructors exposed by the class.

If to is not specified, the output goes to Listener, otherwise the output goes to the specified stream.

The results are sorted by name. Secondary sort is performed based on the number of parameters.