Notifications
Clear all

[Closed] How do I truncate a string?

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.

3 Replies
 eek

theString = $object_ref.name

theCopy = copy $object_ref

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

also

trimRight theString “_ref”

and replace

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 = objNm

Place that inside an array loop and your all done.

Hope that helps,
-Eric

Thanks so much for the quick responses!