On 28/06/2013 at 03:57, xxxxxxxx wrote:
I was wondering if it's possible at all to control the cursor position in a EditText field, within a GeDialog. The MultiLineEditText field has a SetMultilinePos() function, but so far I haven't figured out how to do the same with the EditText.
The thing is, that when my plugin opens the dialog, I initialize the field with the SetString() method, which causes Cinema to highlight the whole String, instead of simply setting the cursor to the last position. Apart from the Get/Set methods there don't seem to be any more means of manipulating C4DGadgets. The GeDialog.SendMessage() looks promising, but there's no further documentation on what to put into the BaseContainer.
Is there a way to do this at all?
On 28/06/2013 at 05:05, xxxxxxxx wrote:
BFM_EDITFIELD_SETCURSORPOS might be what your are looking for. have not used it yet, but
from the ccp sdk it looks like you have to write simply the caret position into the ID 1 of the
check the cpp sdk for the message id (its in BFM_Message).
On 28/06/2013 at 05:42, xxxxxxxx wrote:
That looks promising! Didn't get it to work so far but I'll keep at it.
On 28/06/2013 at 09:16, xxxxxxxx wrote:
Here's a script that shows how to Get & Set the cursor position in a text field.
When you press the period key on your keyboard. A popup list opens.
After you make a choice, it adds it to the text field. And then automatically moves the cursor to the end of the text. It's one of my favorite R13 SDK additions.
from c4d import gui
GROUP1 = 1000 #GROUP1 id
TEXTBOX= 1001 #TEXTBOX id
BUTTON = 1002 #BUTTON1 id
class ExampleDlg(gui.GeDialog) :
def CreateLayout(self) :
self.GroupBegin(GROUP1, c4d.BFH_SCALEFIT|c4d.BFV_SCALEFIT, 0, 0, "Press The Period Key", c4d.BFH_SCALEFIT)
self.AddButton(BUTTON, c4d.BFH_SCALE, name="Close")
def InitValues(self) :
#initiate the gadgets with values
def Command(self, id, msg) :
if id==BUTTON: self.Close()
text = self.GetString(TEXTBOX)
bc = c4d.BaseContainer(c4d.BFM_EDITFIELD_GETCURSORPOS) #R13+ flag
pos = dlg.SendMessage(TEXTBOX, bc) #Returns the current index position on the cursor in the text
if pos > 0 and text[pos-1]=='.' :
entries = c4d.BaseContainer()
entries.SetString(c4d.FIRST_POPUP_ID+0, "first") #The &d& code is used to grey out the entry
entries.SetString(c4d.FIRST_POPUP_ID+4, "Fifth") #The &c& code is used to add a checkmark to the entry
mypopup = gui.ShowPopupDialog(cd=None, bc=entries, x=600, y=200)
text += entries.GetString(mypopup)
bc = c4d.BaseContainer(c4d.BFM_EDITFIELD_SETCURSORPOS) #R13+ flag
bc.SetLong(1, len(text)) #Puts the cursor at the end of the text
pos = dlg.SendMessage(TEXTBOX, bc) #Execute the cursor position code
dlg = ExampleDlg()
dlg.Open(c4d.DLG_TYPE_ASYNC, defaultw=300, defaulth=50)
On 28/06/2013 at 09:33, xxxxxxxx wrote:
Thats fantastic! Thanks a ton for this! I actually didn't think it would be possible because it's something so useful, yet so hidden away in the C++ SDK.
This is gonna come in handy in the future for sure (The plugin I originally needed this for sadly got obsolete).
I think I'll have to scan the docs for some more BFM IDs to see what else can be done.