On 04/11/2015 at 13:23, xxxxxxxx wrote:
Hi all, have a ToolData plugin that I am building. The SubDialog has a Link Box which I want to have the Pick Mode activated for the user when the tool is launched. I can not for the life of me figure out how to do this?? Any idea on how to do this in python? I don't want the user to have to go to and click on the mouse cursor button.
Thank you for the help.
On 05/11/2015 at 02:29, xxxxxxxx wrote:
The Pick Mode can be activated by code but this relies on the internal ID for the LinkBoxGui Pick Object button:
def InitValues(self) :
msg = c4d.BaseContainer(c4d.BFM_ACTION)
Note this code has to be run in the SubDialog InitValues(), not the CreateLayout() because it crashes the application there!
A better solution is to use ViewportSelect helper class in the ToolData::MouseInput() to pick yourself an object and set it in the LinkBoxGui.
Here's some code:
def MouseInput(self, doc, data, bd, win, msg) :
mouse_x = int(msg[c4d.BFM_INPUT_X])
mouse_y = int(msg[c4d.BFM_INPUT_Y])
viewport_select = c4d.utils.ViewportSelect()
# Pick objects
objects = viewport_select.PickObject(bd, doc, mouse_x, mouse_y, rad=10, flags=c4d.VIEWPORT_PICK_FLAGS_0)
if not len(objects)>=1:
# Get first picked object
obj = objects
self.dialog is the SubDialog for the ToolData
SetObjectLink() is a method defined in the SubDialog overriden class that simply calls LinkBoxGui.SetLink() with the picked object
On 05/11/2015 at 13:32, xxxxxxxx wrote:
Yannick Thanks so much! I was able to get both techniques working! I really appreciate your help. I did not know you could control the subdialog instance inside the ToodData Class this makes things easier for me :).
Now I am just trying to replicate the highlight effect that the Pick Mode does.... I feel I am close just don't know what to do next to draw the highlight mode in the viewport. I having trouble finding a good explanation of how highlight mode works. This is what I have so far by using the ToodData::GetCursorInfo() I can figure out which object my mouse is over and can print out the name of the object, now I just need to draw it in highlight mode. But not sure how to do that...
def GetCursorInfo(self, doc, data, bd, x, y, bc) :
if bc.GetId() == -1:
print "SCAN FOR CURSOR OJBECT"
op = c4d.utils.ViewportSelect().PickObject(bd, doc, x, y, rad=int(10), flags=c4d.VIEWPORT_PICK_FLAGS_0)
#This will print the name of the object my mosue is over
# Not sure what do do next... inable highlight handle or something...
highlightHandle = op.GetHighlightHandle(bd)
Anyone have any tips on how do get highlight mode working? Sorry if these are noob questions, I was looking on the forums for a similar question and documentation and could not figure it out.
On 06/11/2015 at 06:31, xxxxxxxx wrote:
The highlight effect that the Pick Mode does can be obtain starting a PickSession in the active document.
Unfortunately this cannot be done with the Python API as BaseDocument.StartPickSession()/StopPickSession() and PickSessionDataStruct are missing.
So far the best and shortest solution is to send an action message to the LinkBox as shown in the first code I posted in my previous message.
On 06/11/2015 at 09:06, xxxxxxxx wrote:
OK thanks for that explanation I appreciate your time. That is a bummer that it can not be done simply with PythonAPI but that is ok. You have helped me make good progress on my first plugin.