Print Page | Close Window

BaseObject::GetHighlightHandle() always returns -1

Printed From: Plugin Cafe
Category: Plugin Cafe
Forum Name: SDK Help
Forum Discription: COFFEE, C++ and Xpresso Q&A
URL: http://www.plugincafe.com/forum/forum_posts.asp?TID=13757
Printed Date: 2017 Dec 17 at 9:02pm
Software Version: Web Wiz Forums 9.61 - http://www.webwizforums.com


Topic: BaseObject::GetHighlightHandle() always returns -1
Posted By: c4dJack
Subject: BaseObject::GetHighlightHandle() always returns -1
Date Posted: 2017 Aug 24 at 3:00am

User Information:

Cinema 4D Version:   18 
Platform:    Mac  ;  Mac OSX  ; 
Language(s):       PYTHON  ; 

---------

Hi,

I'm currently using Python to write an ObjectData plugin. I'm also using the automated handle interface there (with GetHandleCount(), GetHandle(), and SetHandle()). When I draw the handles in Draw(), I want to highlight the handle that the mouse cursor is hovering over. But it doesn't work, op.GetHighlightHandle(bd) always returns -1.

Is there anything I could have done to break it, it anything I should do to make it work? Unfortunately, about 90% of the code can't be shown in public, otherwise I'd post it here.

Cheers,
Frank


-------------
https://www.frankwilleke.de - www.frankwilleke.de
https://fwilleke80.github.io - My GitHub page



Replies:
Posted By: Yannick Puech
Date Posted: 2017 Aug 25 at 2:21am
Hi Frank,

If GetHighlightHandle() always returns -1, make sure GetHandleCount() returns the right number of handles, and that GetHandle() sets the handle information.
Also check the declaration of GetHandleCount()/GetHandle()/SetHandle() so that Cinema can call these functions:
def GetHandleCount(self, op)
def GetHandle(self, op, i, info)
def SetHandle(self, op, i, p, info)

For an example of how to deal with handles, look at https://github.com/PluginCafe/cinema4d_py_sdk/blob/master/plugins/Py-RoundedTube/Py-RoundedTube.pyp - Py-RoundedTube .


(PS: Please post Python related questions to the http://www.plugincafe.com/forum/forum_topics.asp?FID=7 - PYTHON Development sub-forum.)





-------------
MAXON
Developer Support


Posted By: c4dJack
Date Posted: 2017 Aug 29 at 2:55am
Oops, yeah, sorry. Wrong sub forum.

Anyway, these three functions are all implemented and called. The handles work fine, too. Just the highlighting does not. I actually used Py-RoundedTube as a model for my plugin. The only difference is that my handles do not relate to values in the Description, but to values I store internally as class members. But that shouldn't make any difference, I guess.


-------------
https://www.frankwilleke.de - www.frankwilleke.de
https://fwilleke80.github.io - My GitHub page


Posted By: Yannick Puech
Date Posted: 2017 Aug 30 at 2:24am
In the C++ API source c4d_objectplugin.cpp you can see how GetHandleCount()/GetHandle()/SetHandle() are called from ObjectData::DetectHandle() and ObjectData::MoveHandle().

Also, check that the view Filter->Highlight Handles is enabled, otherwise BaseObject::GetHighlightHandle() always returns -1.





-------------
MAXON
Developer Support


Posted By: c4dJack
Date Posted: 2017 Nov 03 at 4:24am
I have to get back to this issue...

GetHandle(), SetHandle(), and GetHandleCount() are correctly called and return correct values. The "Highlight Handles" filter is enabled, too. Still, GetHighlightHandle() always returns -1.

 Is it possible that this has something to do with the fact, that my plugin object is a PointObject (info = c4d.OBJECT_GENERATOR | c4d.OBJECT_POINTOBJECT on plugin registration)?

I even overwrote DetectHandle() and made it return always 1. And still, GetHighlightHandle() returns -1.

Cheers,
Frank


-------------
https://www.frankwilleke.de - www.frankwilleke.de
https://fwilleke80.github.io - My GitHub page


Posted By: Yannick Puech
Date Posted: 2017 Nov 03 at 11:25am
Hi Frank,

Indeed, GetHighlightHandle() returns -1 for point objects. They aren't supposed to have handles because their points are edited directly in point mode.





-------------
MAXON
Developer Support


Posted By: c4dJack
Date Posted: 2017 Nov 07 at 2:53am
Have you considered that a generator that is a PointObject may want to change other things than just the point positions? We have points that make up the object's basic shape, and then a handle for each point that changes the shape at that point. I don't really get why GetHighlightHandle() has to return -1 in that case, where it could simply return the value internally given by DetectHandle() Cry

Cheers,
Frank


-------------
https://www.frankwilleke.de - www.frankwilleke.de
https://fwilleke80.github.io - My GitHub page


Posted By: Yannick Puech
Date Posted: 2017 Nov 07 at 8:07am
I'll ask the developers if the behavior of BaseObject::GetHighlightHandle() with point objects is intended.

A solution is to implement ObjectData::DetectHandle() storing the index of the highlighted handle, then using it in Draw().





-------------
MAXON
Developer Support


Posted By: c4dJack
Date Posted: 2017 Nov 09 at 4:47am
Trying to write my own DetectHandle() function now, and calling it from Draw(), as you suggested...

How would I query the mouse position, though? I tried with BaseDraw::GetInputEvent() and BaseDraw::GetInputState(). The first returns a correct mouse position, but only when I press the mouse button. The latter never returns any mouse position except (0;0), regardless of the channel I use. Of course, to detect a handle and highlight it, I'd have to monitor the mouse constantly.

Thanks for help!

Cheers,
Frank


-------------
https://www.frankwilleke.de - www.frankwilleke.de
https://fwilleke80.github.io - My GitHub page


Posted By: Yannick Puech
Date Posted: 2017 Nov 09 at 6:08am
Originally posted by c4dJack

Trying to write my own DetectHandle() function now, and calling it from Draw(), as you suggested...
I will try to explain better my solution.

Usually implementing ObjectData::DetectHandle() is not needed if GetHandle()/SetHandle()/GetHandleCount() are overriden.
Cinema 4D calls ObjectData::DetectHandle() for object plugins and caches the highlight handle ID returned. This ID is, normally, returned by BaseObject::GetHighlightHandle().
But for point objects BaseObject::GetHighlightHandle() returns -1.
So, the solution is to implement ObjectData::DetectHandle() in point object data classes storing the highlight handle ID (in a member variable for instance).
This ID can then be accessed from ObjectData::Draw().

Note you can find the standard implementation of ObjectData::DetectHandle() in the C++ API c4d_objectplugin.cpp file.





-------------
MAXON
Developer Support


Posted By: c4dJack
Date Posted: 2017 Nov 10 at 5:34am
Oh right, that makes sense. Thanks for the workaround, Yannick!

The only thing that makes me a bit nervous is that this method forces me to rely on the order of function calls that come in from Cinema. If that's to change one day, this workaround won't work anymore. But until then, everything is fine. Thanks again!


-------------
https://www.frankwilleke.de - www.frankwilleke.de
https://fwilleke80.github.io - My GitHub page


Posted By: Yannick Puech
Date Posted: 2017 Nov 28 at 8:58am
Hi Frank,

Finally, BaseObject::GetHighlightHandle() returning -1 for point objects is a bug in the API. Note this also happens for polygon objects.
The issue will be fixed in one of the next release.





-------------
MAXON
Developer Support



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums® version 9.61 - http://www.webwizforums.com
Copyright ©2001-2009 Web Wiz - http://www.webwizguide.com