Deleting last entry in a textField via a command

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  07 July 2013
Deleting last entry in a textField via a command

I'm wondering if there is any way to delete the last entry in a textField via a command?
Sure there's always backspace, but let us assume that this field cannot be modified via the keyboard but only via commands.

You have the
-insertText -flag for inserting new stuff into the field but no flag for deleting things.

NOTE: I'm not interested in textField -e -text "" $field;
I want to delete the last entry.

Tokenizing the field text, store in an array and delete last array entry seems like a sloppy solution, so maybe another approach would be to create some kind of undo-queue for the field by using optionVars?

What are your thoughts?
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.
  07 July 2013
I dont quite understand why you think tokenize would be sloppy. Write a little proc that takes a string and returns the same string with the required number of fields omitted. Once you have that, your actual code would only be 3 lines. 1 to query the current text, 1 to call your truncate proc and 1 to edit the textfield.

The bonus is your truncate proc can be written to be a little more general that omitting just the last field. Pass in a flag that tells it how many fields to remove, from which end, with what delimiter, etc. Then you have something you can re-use in all your other scripts that deal with text strings.

If you did this in python it would be even easier, and you could do it in a single line.

  07 July 2013
Tokenize requires a separation character (: or _ most commonly used by ppl) and that wouldn't be of any help to be as the string I have can be highly random.

Either way, I found the page in the manual for the substring command and I think I'll just do a small procedure using that command (calc size of string, minus one, save substring to the string var).
Nightshade UV Editor (script for Maya) - Extends Maya's default UV Texture Editor with additional tools.
  07 July 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:06 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.