inheriting IRestoreObj

 
 
 
Posted by:Vincentt
Data created:24 January 2015

Hello again,

 

I’m having some difficulties implementing IRestoreObj. The examples I found in the SDK documentation don’t need to override all the methods I have (I guess this is because how the wrapper works). However, I’ve implemented all of the methods (maybe not correctly), but when I do this:

SelectionRestore test = new SelectionRestore(node, m_Global.Point3.Create(30,30,30));

IHold hold = m_Global.TheHold;
hold.Begin();
if (hold.Holding)
hold.Put(test); //Exception

I get a 'System.InvalidCastException' error: Unable to cast object of type 'AnimateTest.SelectionRestore' to type 'Autodesk.Max.IImplementable'.

public class SelectionRestore : IRestoreObj
{
//datamembers

public SelectionRestore(IINode node, IPoint3 undoValue)
{
//cut because of space
}

public string Description
{get { return "Undo Movement of node"; }}

public void EndHold()
{ }

public IntPtr Execute(int cmd, UIntPtr arg1, UIntPtr arg2, UIntPtr arg3)
{return new IntPtr(-1);}

public void Redo()
{
//cut because of space
}

public void Restore(bool isUndo)
{
//cut because of space
}

public int Size
{get { return 1; }}

public IBaseInterface GetInterface(IInterface_ID id)
{return null;}

public bool Equals(IInterfaceServer other)
{return Equals(other);}

public void Dispose()
{ }

public IntPtr Handle
{get { return new IntPtr(-1); }}
}

 

Any idea what I could do?

Thanks in advance,

Vin

Hi Vin,

You don't need to implement IRestoreObj, instead derive your class from Autodesk.Max.Plugins.RestoreObj.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Aah! Thank you very much! I read the max sdk .net help and it said: "Currently it is not recommended to derive from the Autodesk.Max.Plugins classes." so I didn't even look there! Oops Yell

Not sure why they put that in there. Deriving from classes in the Plugins namespaces is the only way to do it :)

Marsel Khadiyev (Software Developer, EPHERE Inc.)