RegisterViewportDisplayCallback problem

 
 
 
Posted by:Vincentt
Data created:12 March 2013

Hey, I'm trying to register ViewportDisplayCallback but I'm not sure what its second parameter should be. I know it has to be of type "IviewportDisplayCallback", but do I need to implement this interface? I've tried to implement it but it didn't work at all.

 

IInterface iface = global.COREInterface;
iface.RegisterViewportDisplayCallback(false, ???);

 

I've been able to use RegisterNotification for other "callbacks" but I'm really not sure how to get this one to work.

 

Any help would be greatly appreciated!
Vin

You need to derive your class from Autodesk.Max.Plugins.ViewportDisplayCallback, create an instance of it and pass the instance into RegisterViewportDisplayCallback(...)

For example:

class MyCallback: Autodesk.Max.Plugins.ViewportDisplayCallback
{
    ...}

...

var myCallback = new MyCallback();
iface.RegisterViewportDisplayCallback( false, myCallback );

Marsel Khadiyev (Software Developer, EPHERE Inc.)

Hey, thank you very much for your fast answer! That has fixed my problem! Smile

Hey Marsel,

After a few more test I noticed something strange about the callback. It seems to fire a lot (400-600 times) after I'm done moving the viewport. This makes my plugin do all the viewport changed related stuff even when the viewport isn't moving anymore. I'm guessing this is not normal?

I ve tried both RegisterViewportDisplayCallback and RegisterRedrawViewsCallback both do the same thing... This is how I implemented it:

    class rvCallback : Autodesk.Max.Plugins.RedrawViewsCallback

    {

        int count = 0;

 

        public override void Proc(IInterface ip)

        {

            ++count;

 

            IGlobal global = Autodesk.Max.GlobalInterface.Instance;

 

            global.TheListener.EditStream.Wputs(count.ToString() + Environment.NewLine);

            global.TheListener.EditStream.Flush();

        }

    }

 

            var myCallback = new rvCallback ();

            iface.RegisterRedrawViewsCallback(myCallback);

 

I run this is max and rotate the viewport untill the 'count' is about 100, then I stop rotating/moving the viewport but the 'count' keeps going up until 600-700. Is this something I can fix?

Thanks,

Vin

Hi Vin,

That does seem strange indeed. Unfortunately, I cannot really say why it is happening because it seems that Max is responsible for all the calls. Perhaps an email to Autodesk devs will get you a better answer. Also, maybe there is a way of calculating whatever you're trying to do in a "lazy" way where it will only perform the calculation when something changes (besides the viewport display)? That depends on what you're trying to do though.

Marsel Khadiyev (Software Developer, EPHERE Inc.)