How can I obtain IIKeyControl interface from IControl?

 
 
 
Posted by:zarusz
Data created:30 November 2010

Hello,

I am having a reference IControl icontrol wich is a "Transform: Position/Rotation/Scale" of ClassId(PRS_CONTROL_CLASS_ID, 0).

The icontrol.PositionController contains "Position: Linear Positition" of ClassId(LININTERP_POSITION_CLASS_ID, 0).

I am trying to obtain the IIKeyControl interface in the following way:

var keys = (IIKeyControl)icontrol.PositionController.GetInterface(InterfaceID.Keycontrol);

but I always get null from GetInterface. I have also tried InterfaceID.Keycontrol2 and IIKeyControl2 respectively with the same result.

Can anyone give me a clue how can I obtain access to IIKeyControl from a IControl?

My versions are MAX.NET1.2.7.0 and 3ds max 2011 x64.

Thanks,

zarusz

Marsel any ideas how can I get IIKeyControl object from IControl?

Hi Tomasz,

I notice you use InterfaceID.Keycontrol, which is incorrect. In the SDK docs I_KEYCONTROL is 0x00001060, while InterfaceID.Keycontrol = 0x00001100. So try:

var keys = (IIKeyControl)icontrol.PositionController.GetInterface(0x00001100);

instead and see if that works.

 

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Hi Marsell,

Thanks for help, unfortunatley I tried both

var keys = (IIKeyControl)icontrol.PositionController.GetInterface((InterfaceID)0x00001060);

and

var keys = (IIKeyControl)icontrol.PositionController.GetInterface((InterfaceID)0x00001100);

with the same result - a null value in keys.

I noticed that  ((InterfaceID)0x00001060 in the debugger says InterfaceID.Keycontrol, so I am afraid the problem lays somewhere else.

Are you sure the MAX.NET wrapper in version 1.2.7 supports the IIKeyControl interface?

Marsel have you got any more ideas what the solution may look like?

Hi Tomasz,

Yes that is strange indeed (that it'd return null). Perhaps the upcasting code is using the wrong interface ID, I will check that. Meanwhile you can use MaxScript functions to access keys. I had to tackle the same problem in ZK and ended up using maxscript for most of the key handling.

For example, to get number of keys I use:

int keyCount = MaxScript.ExecuteWithReference( "numKeys {reference}", control ).ToInt;

You do need to make sure that {reference} is replaced with your control (you need to be able to get to the control either through the node or object you're editing).

Other examples, to get key time:

int currentKeyTime = MaxScript.ExecuteWithReference( "( getKeyTime {reference} " + ( i + 1 ) + " ) as integer", control ).ToInt;

to delete keys:

MaxScript.ExecuteWithReference( "deleteKeys {reference}", control );

etc. Hope this helps.

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Hi Marsel,

Thanks for the workaround.

By the way I would like to say that the problem still exists in the newest MAX.NET 1.2.8.0

Thanks Tomasz,

I guess this requires more tweaking.

Marsel Khadiyev (Software Developer, EPHERE Inc.)