Script Operator accessing scene object properties
#1
Hi!

I have no knowledge about using C# in 3dsmax.
How would I access for example a rectangle's .width value inside a script operator?
  Reply
#2
Accessing regular max properties within a Script operator is more complex than regular maxscript access, but possible.

The following code could be used to access the "width" property of a rectangle named "Rectangle001" in the scene:

Code:
var global = GlobalInterface.Instance;
    
var pointHelper = global.COREInterface.GetINodeByName("Rectangle001"); //get the IINode of the rectangle
    
var pointRef = pointHelper.ObjectRef; //Get the IObjectRef of the IINode
    
var pblock = (Autodesk.Max.Wrappers.IParamBlock)pointRef.GetReference(1); //paramblock 1 of a shape object is its shape property paramblock (paramblock 0 of a shape is its renderable geometry properties)
        
Print (pblock.GetFloat(1,0)); //the width property is the second parameter in the paramblock, so we reference it with ID "1", since its property IDs are 0-based
  Reply
#3
yay, its possible!

So I have to reference this assembly, right?
"$MaxRoot\bin\assemblies\Autodesk.Max.Wrappers.dll"

But then I get this error

Quote:-- Runtime error: „NET runtime exception: Unable to cast object of type 'Autodesk.Max.Wrappers.ReferenceTarget' to type "Autodesk.Max.Wrappers.IParamBlock‘


caused by

Code:
var pblock = (Autodesk.Max.Wrappers.IParamBlock)pointRef.GetReference(1);

ok, the problem occurs when the rectangle as modifiers, so maybe I need to get to the baseobject...
  Reply
#4
Okay, it's working now. Some objects have different paramblocks...
  Reply
#5
Oh woops, yea...forgot to mention you have to reference the assembly. I'll add that assembly to the list of defaults in the next build, since it's a pretty common one to use.
  Reply


Forum Jump: