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
By
Comments (23)
Comment policy
I know this is an old thread but you're right about dotnet:
*CORRECT FILENAME*
fileP = "C:\temp\tempFolder\newFolder\tempFile.xxx"
fn correctString str =
(
str = substituteString str "\n" "\\n"
str = substituteString str "\t" "\\t"
)
correctString fileP
--> "C:\temp\tempFolder\newFolder\tempFile.xxx"
*CLEAN DUBLE PUNKCTION MARKS*
fn cleanDuble str signArr =
(
local newstr = str[str.count]
for i in str.count-1 to 1 by -1 where not ((findItem signArr str[i]) != 0 and str[i] == str[i+1]) do (newstr = str[i]+newstr)
return newstr
)
str = "1,,,,,,,,0,..20,3-........-0,4,,,,,,,,,,,0,..,,-5----0,,,,,,,,,,,--"
cleanDuble str #(",",".","-")
-->"1,0,.20,3-.-0,4,0,.,-5-0,-"
*FIND AND REPLACE ALL IDENTICLE WORD*
str = "were not officially supported for use in your own scripts, not for now"
fn FindAndReplaceAll str fnd rpl =
(
local addpos, fndcount = fnd.count
while ((addpos = findString str fnd) != undefined) do ( str = replace str addpos fndCount rpl )
)
FindAndReplaceAll str "not" "will"
--> "were will officially supported for use in your own scripts, not for now"
*FIND AND REPLACE FIRST IDENTICLE WORD*
str = "were not officially supported for use in your own scripts, not for now"
fn FindAndReplace str fnd rpl =
(
addpos = findString str fnd
if (addpos != undefined) do (replace str addpos fnd.count rpl)
)
FindAndReplace str "not" "will"
--> "were will officially supported for use in your own scripts, not for now"
*FILTER NAME NUMBERS*
fn filterSufix str =
(
local theNumbers = "1234567890"
local str = trimLeft (trimRight str)
if str.count != 0 do for i = str.count to 1 by -1 do
(
if findString theNumbers str[i] == undefined do (str = replace str i 1 "")
) ; str
)
filterSufix " $VRayCamera001"
-->"001"
*CLEAN STRING*
fn cleanString st =
(
local theChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 _-."
st = trimLeft (trimRight st) -- this wil remove white spaces
if st.count != 0 do for i = st.count to 1 by -1 do
(
if findString theChars st[i] == undefined do (st = replace st i 1 "")
)
st
)
str = " >>CA%ME$RA==0~01<<<"
cleanString str
-->"CAMERA001"
*CAPITALIZE ONLY FIRST LETTERS*
fn capitalizeFirstLetter str =
(
if str != "" do
(
fn upperFirst s = ((toUpper s[1]) + (substring s 2 s.count))
local strArr = filterString str " ", resultStr = ""
for s = 1 to strArr.count do
(
if strArr.count == 1 then (resultStr = upperFirst strArr[1]) else
(
if s < strArr.count then resultStr += upperFirst strArr[s]+" "
else resultStr += upperFirst strArr[s]
)
)
resultStr
)
)
msg = "max have very cool string methods but .net is even better"
capitalizeFirstLetter msg
-->"Max Have Very Cool String Methods But .net Is Even Better"
In the next few posts I will show some string functions.
Maybe some of them can be useful. Anyway ...
BTW are you trying to recreate Total Commander "Rename Multipe Files" window? :)
I only use the quick search did not elaborate on researching your script.
in your case:
I see in your script, the variable of 'trailing_leading' is a boolean, not a string
trimleft/trimright need a string (ie:name of object or any string)
for example to using them
a snippet from mxs help:
or see example from barigazy
regards
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.
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.
Attachments
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"
)
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"
Getting somewhere
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
shorter version
for i in selection do i.name = trimLeft (trimRight i.name)
Are you tried this tool
http://www.scriptspot.com/3ds-max/scripts/interactive-universal-renamer
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.
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:
run this script then check to mxs listener
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
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.
Attachments
Not have time to look over the whole code.
Post me a snippet to see what is the problem.
Like this
let say i have en string *str*
--example#1 trimLeft | trimeRight fn
str = "--------------#### 3dwannab code ###--------------"
--to remove symbols you can use
str = trimLeft (trimRight str " ###--------------") "--------------#### "
-->result: "3dwannab code"
--example#2 replace fn
str = "--------------#### 3dwannab code ###--------------"
--define simbols that you want to remove
toDel = "-+*/|#$"
for i = str.count to 1 by -1 where (findstring toDel str[i]) != undefined do str=(replace str i 1 "") ; str
--> result:" 3dwannab code "
Not quite understand what do you want to achive.
Just show me string before and after (result that you want)
Thank you so much.
Your information really helped me a lot!