PDA

View Full Version : How do I truncate a string?


Malkalypse
05-03-2009, 03:34 AM
Say I have created an object in my scene called $Object1_Ref, and I want to use MaxScript to create a copy of it simply called $Object1. (In actuality, I will be doing this for more than one object, or I wouldn't really need a script). I've gone through the help files looking for information on how to work with strings, but can't find what I am looking for. I basically just want something that works like the "Remove Last: (x) Digits" in the rename objects tool.

eek
05-03-2009, 03:59 AM
theString = $object_ref.name

theCopy = copy $object_ref

theCopy.name = (filterString theString "_" )[1]


also

trimRight theString "_ref"

and replace

PiXeL_MoNKeY
05-03-2009, 04:07 AM
Substring would probably be the easiest route. From there you would simply make the substring length = to the current string count - the trim amount. Something like this would do it:trim = 4
obj = $Object01_Ref
objNm = substring obj.name 1 (obj.name.count-trim)
obj.name = objNmPlace that inside an array loop and your all done.

Hope that helps,
-Eric

Malkalypse
05-03-2009, 04:36 AM
Thanks so much for the quick responses!

CGTalk Moderation
05-03-2009, 04:36 AM
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.