Help with the trimleft/trimright function

 

I've taken my favourite script and tried to learn from it. It's probably is a bit complicated for a beginner but I really wanted to add a function to trim any leading and trailing whitespace characters and also add an option for Title case and Sentence case. I read the manual and all I can see is:

 ToLower + ToUpper

Is there another way to achieve Title case and Sentence case?

Any code that I've modified has --------------#### 3dwannab code ###-------------- beside it.

The area that needs attention is:

--------------#### 3dwannab code ###--------------

( if trailing_leading = false then

for i in selection do i.name = trimleft trailing_leading

--------------#### 3dwannab code ###--------------

 

I'm completely suck at the minute and I wanted to chat with someone on here to help me figure out what I need to do. I've managed to get the presets working as they should. It's just the function that needs a look at.

Thanks

 

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
3dwannab's picture

Success sort of

Thanks for that. I did see that in the maxscript help but I didn't get it to work, however I did this time but with unfavoured reselts.

(
if trailing_leading = true then
for i in selection do i.name = trimright "Teapot123" "1234567890"
)

I have three objects:

Teapot123 | Lamp123 | Chair123

I selected those objects and ran the script. All three were named to Teapot. I can see what this is doing. But it's not what I was after. It also does this when the box is unticked. trailing_leading is a boolean for the box that you tick. If off names are untouched and on the trailing and leading spaces are removed which is what I was hoping for.

I know for an experienced maxscripter this would be a piece of cake but for my 1 weeks knowledge of this launguage it's a different story.

AttachmentSize
3dwannab-renameobjext.mcr 21.92 KB
barigazy's picture

...

Because you use only "Teapot123" and you need to do it like this

if trailing_leading = true do
(
    for i in selection do i.name = trimright i.name "1234567890"
)

barigazy

3dwannab's picture

Getting somewhere

if trailing_leading = false do
(
for i in selection do i.name = trimright i.name
for i in selection do i.name = trimleft i.name
)

Thank you.

This now works to trim unwanted spaces from left and right but when I run the script it instantly affects the names whereas I want it to toggle when I click/unclick the checkbox.

Further more it doesn't work when I type leading and trailing spaces in the upper left hand corner. And yes this is based on total commander. But obviously credit goes to 'AShim' which were his intentions from what I read over at http://www.scriptspot.com/3ds-max/scripts/rename-objects-extended

barigazy's picture

...

shorter version

for i in selection do i.name = trimLeft (trimRight i.name)

barigazy

barigazy's picture

...

Are you tried this tool
http://www.scriptspot.com/3ds-max/scripts/interactive-universal-renamer

barigazy

3dwannab's picture

...

Yes, I have and also Hyper renamer from TiM Scripts @ http://www.hyperent.com/Hyp-Maxscripts.php which I found to be great too.

I just wanted to use this script to learn as I like the fact you can save your settings to an INI file but I'll just have to cut my losses with this mod and try something easier to get started. Thanks for your help.

Budi G's picture

hi 3dwannab ...about

hi 3dwannab ...
about trimleft/trimright,
Has the problem resolved ?
I see you've understood now, right ?

if you researching some script, you can use print() or format() function and check the mxs listener.

it's useful to get information of any variable,
such as what is result of the variable ?
You can apply this to another variables

it's maybe out of topic but still closest to your case.
if you not familiar with print() and format(), see example:

--------------- example random variables
got = true
counter = 45
arr = #(2,3,4,5,6,7,8)
str = "result ? 0,4,7"
trimstr = trimright str "?,047"
whatisthis = uniquename trimstr + (counter as string)
cc = (234*counter/5)
clearlistener() -- clear listener
 
---- Next ...you want to check several variables or hidden variables from your view
 
----------------------------------------- check some variable by print or format
format "%\n" whatisthis -- check a variable by format
-- or
print cc -- check a variable by Print

run this script then check to mxs listener

3dwannab's picture

Is pressing the F1 key ...

while the flashing cursor is on the variable the same where it takes to to maxs help file or is your method different.

I'm finding it a bit overwhelming at the minute, thanks for your help

barigazy's picture

...

If you want to assigne one unique name to selection you can try this

-- u can use "02d" or "03d" formating
fn uniqSelectionNames arr title: prec: =
(
	for i = 1 to arr.count do arr[i].name = title + formattedprint i format:prec
)
uniqSelectionNames selection title:"Boxes" prec:"03d"

barigazy

3dwannab's picture

Opps..

See the script attached. It'll be much clearer then. Basically when the box is ticked to trim trailing/leading then it does just that.

You're probably familiar with this script but I've changed the UI slightly.

AttachmentSize
3dwannab-renameobjext.mcr 22.73 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.