Error getting object's grips status(c++)

Hi;
My code cannot get the correct object state. How do I solve this problem?

class CRhinoEventWatcherr : public CRhinoEventWatcher 
{
  void OnSelectObjects( CRhinoDoc& doc, const ON_SimpleArray<const CRhinoObject*>& objects );
  void OnDeselectAllObjects( CRhinoDoc& doc, int count );
};

const CRhinoObject* obj = 0;//the object 

void CRhinoEventWatcherr::OnSelectObjects(CRhinoDoc& doc, const ON_SimpleArray<const CRhinoObject*>& objects)
{
	obj = objects[0];

	if (obj != 0)
	{
		RhinoApp().Print(L"obj is not null\n");
		if (obj->GripsOn())
		{
			RhinoApp().Print(L"GripsOn OnSelectObjects\n");
		}
		else
		{
			RhinoApp().Print(L"GripsOff OnSelectObjects\n");
		}
	}
	else
	{
		RhinoApp().Print(L"obj is null\n");
	}
}
void CRhinoEventWatcherr::OnDeselectObjects(CRhinoDoc& doc, const ON_SimpleArray<const CRhinoObject*>& objects)
{
	if (obj != 0)
	{
		RhinoApp().Print(L"obj is not null\n");
		if (obj->GripsOn())
		{
			RhinoApp().Print(L"GripsOn OnDeselectObjects\n");
		}
		else
		{
			RhinoApp().Print(L"GripsOff OnDeselectObjects\n");
		}
	}
	else
	{
		RhinoApp().Print(L"obj is null\n");
	}
}

Maybe check the status only when the program has become idle after deselect is completed?

https://developer.rhino3d.com/api/cpp/class_c_rhino_is_idle.html

Hi@menno ;
May be this guy will be ok, but I don’t know how to get the objects in this class :rofl:
Rhino C++ API: CRhinoOnChangeObjectSelectState Class Reference

Hi @pythonuser,

Can you explain what problem you are trying to solve?

– Dale