Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

BaseObject::GetHighlightHandle() always returns -1

 Post Reply Post Reply
Author
Message
c4dJack View Drop Down
Member
Member
Avatar

Joined: 2007 Jul 13
Location: Berlin
Online Status: Offline
Posts: 649
Post Options Post Options   Quote c4dJack Quote  Post ReplyReply Direct Link To This Post Topic: BaseObject::GetHighlightHandle() always returns -1
    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
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1052
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post 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 Py-RoundedTube.


(PS: Please post Python related questions to the PYTHON Development sub-forum.)



MAXON
Developer Support
Back to Top
c4dJack View Drop Down
Member
Member
Avatar

Joined: 2007 Jul 13
Location: Berlin
Online Status: Offline
Posts: 649
Post Options Post Options   Quote c4dJack Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1052
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
c4dJack View Drop Down
Member
Member
Avatar

Joined: 2007 Jul 13
Location: Berlin
Online Status: Offline
Posts: 649
Post Options Post Options   Quote c4dJack Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1052
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post 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.





Edited by Yannick Puech - 2017 Nov 03 at 11:27am
MAXON
Developer Support
Back to Top
c4dJack View Drop Down
Member
Member
Avatar

Joined: 2007 Jul 13
Location: Berlin
Online Status: Offline
Posts: 649
Post Options Post Options   Quote c4dJack Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1052
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
c4dJack View Drop Down
Member
Member
Avatar

Joined: 2007 Jul 13
Location: Berlin
Online Status: Offline
Posts: 649
Post Options Post Options   Quote c4dJack Quote  Post ReplyReply Direct Link To This Post 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


Edited by c4dJack - 2017 Nov 09 at 4:57am
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1052
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
c4dJack View Drop Down
Member
Member
Avatar

Joined: 2007 Jul 13
Location: Berlin
Online Status: Offline
Posts: 649
Post Options Post Options   Quote c4dJack Quote  Post ReplyReply Direct Link To This Post 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!


Edited by c4dJack - 2017 Nov 10 at 6:04am
Back to Top
Yannick Puech View Drop Down
Forum Moderator
Forum Moderator


Joined: 2011 Apr 13
Location: Spain
Online Status: Offline
Posts: 1052
Post Options Post Options   Quote Yannick Puech Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.