On 05/11/2015 at 02:29, xxxxxxxx wrote:
Hi,
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)
msg.SetInt32(c4d.BFM_ACTION_ID, 1005)
self.SendMessage(LINKBOX_ID, msg)
return True
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:
return True
# Get first picked object
obj = objects[0]
if obj:
self.dialog.SetObjectLink(obj)
return True
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