<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Betreff: Remove number sequence from object name in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987176#M508</link>
    <description>&lt;P&gt;The cool kids might simply use regular expressions in dotNet to get the new name but here is how to do it with only built-in MAXscript tools:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;fn isChar txt =  (toUpper (toLower txt)) != txt
-- hack: test if changing case of txt changes txt - if yes then txt is not characters

fn trimNonChar txt = (
	-- remove any non-letter from the end of txt
	local pos = txt.count
	local cont = true
	for i = txt.count to 1 by -1 while cont do (
		pos = i
		if (isChar txt[i]) then cont = false
	)
	substring txt 1 pos
)

-- select all objects you want to be renamed
for o in selection do (
	local newName = trimNonChar o.name
	format "Renaming % to %\n" o.name newName
	-- comment next line out for a dry run
	o.name = newName
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Aug 2024 17:38:08 GMT</pubDate>
    <dc:creator>MartinBeh</dc:creator>
    <dc:date>2024-08-28T17:38:08Z</dc:date>
    <item>
      <title>Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987003#M505</link>
      <description>&lt;P&gt;As the title says, I'm trying to remove the ending number sequence from a selection of objects. Sometimes it's 2 digits, sometimes 3 digits, depending on how the object was copied/instanced. And sometimes it's many more digits if it's a CAD import. So if I have something named, LP45_Object039871, I want to have it identify the sequence 039871 at the end of the name and remove it so it will be LP45_Object with no sequence at the end. Sometimes there's an "_" or "-" before the sequence that should be removed as well. Is this possible in Maxscript?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 16:18:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987003#M505</guid>
      <dc:creator>chad_voller</dc:creator>
      <dc:date>2024-08-28T16:18:10Z</dc:date>
    </item>
    <item>
      <title>Betreff: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987147#M506</link>
      <description>&lt;P&gt;Sure!&lt;/P&gt;
&lt;P&gt;For each object get name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; walk forward from the end of the name until you hit a letter&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; use the remaining part as new name&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:16:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987147#M506</guid>
      <dc:creator>MartinBeh</dc:creator>
      <dc:date>2024-08-28T17:16:54Z</dc:date>
    </item>
    <item>
      <title>Betreff: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987153#M507</link>
      <description>&lt;P&gt;How exactly is that done? I can't seem to figure out how to differentiate between characters in the name. What tells it that it is a number, or _ or -?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:22:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987153#M507</guid>
      <dc:creator>chad_voller</dc:creator>
      <dc:date>2024-08-28T17:22:18Z</dc:date>
    </item>
    <item>
      <title>Betreff: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987176#M508</link>
      <description>&lt;P&gt;The cool kids might simply use regular expressions in dotNet to get the new name but here is how to do it with only built-in MAXscript tools:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;fn isChar txt =  (toUpper (toLower txt)) != txt
-- hack: test if changing case of txt changes txt - if yes then txt is not characters

fn trimNonChar txt = (
	-- remove any non-letter from the end of txt
	local pos = txt.count
	local cont = true
	for i = txt.count to 1 by -1 while cont do (
		pos = i
		if (isChar txt[i]) then cont = false
	)
	substring txt 1 pos
)

-- select all objects you want to be renamed
for o in selection do (
	local newName = trimNonChar o.name
	format "Renaming % to %\n" o.name newName
	-- comment next line out for a dry run
	o.name = newName
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:38:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987176#M508</guid>
      <dc:creator>MartinBeh</dc:creator>
      <dc:date>2024-08-28T17:38:08Z</dc:date>
    </item>
    <item>
      <title>Betreff: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987185#M509</link>
      <description>&lt;P&gt;But note: This will rename "Sphere001", "Sphere_002" and "Sphere0003" all into "Sphere".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3ds max allows you to have multiple objects with the same name, but IMO this is a very bad idea.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:40:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987185#M509</guid>
      <dc:creator>MartinBeh</dc:creator>
      <dc:date>2024-08-28T17:40:48Z</dc:date>
    </item>
    <item>
      <title>Betreff: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987214#M510</link>
      <description>&lt;P&gt;Or you get the integer representation of a single character and compare that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;fn isChar txt = bit.charAsInt txt &amp;gt;= 65
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See&amp;nbsp;&lt;A href="https://www.ascii-code.com/" target="_blank" rel="noopener"&gt;https://www.ascii-code.com/&lt;/A&gt;&amp;nbsp;for the numbers. If you also want to remove "_" you need to test for value 95&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 17:52:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987214#M510</guid>
      <dc:creator>MartinBeh</dc:creator>
      <dc:date>2024-08-28T17:52:41Z</dc:date>
    </item>
    <item>
      <title>Betreff: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987259#M511</link>
      <description>&lt;P&gt;Here is a drop-in replacement that uses dotNet regex:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;fn trimNonChar txt = (
	local regex = dotnetobject "System.Text.RegularExpressions.Regex" @"[_-]*\d{3,}$"	-- search for 3 or more digits at the end, optionally preceeded by one ore more _ or - characters
	local match = regex.matches txt
	if match.count == 1 then (
		substring txt 1 (txt.count - match.item[0].length)		-- trim away end
	) else txt
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 18:19:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987259#M511</guid>
      <dc:creator>MartinBeh</dc:creator>
      <dc:date>2024-08-28T18:19:35Z</dc:date>
    </item>
    <item>
      <title>Betreff: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987304#M512</link>
      <description>&lt;P&gt;And one more variant, even shorter - this time using Python and the same regular expression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;global py_re = python.import "re"   -- load Python's regular expression module
fn trimNonChar txt = (
	::py_re.sub @"[_-]*\d{3,}$" "" txt  -- using Python, replace _-ddd... with nothing and return
)

-- select all objects you want to be renamed, then run this
for o in selection do (
	local newName = trimNonChar o.name
	format "Renaming % to %\n" o.name newName
	-- comment next line out for a dry run
	o.name = newName
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 18:42:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987304#M512</guid>
      <dc:creator>MartinBeh</dc:creator>
      <dc:date>2024-08-28T18:42:28Z</dc:date>
    </item>
    <item>
      <title>Betreff: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987401#M513</link>
      <description>&lt;P&gt;That is exactly what I am looking for. And yes, I do agree that having objects of the same name is a bad idea. I'm working with 3rd party software that requires the names to be exactly the same, and removing the number sequence fixes that. I will be putting in some safeguards that it is only applied to the correct objects, and possibly on export only. I appreciate the different options you gave to get the result.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2024 19:13:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12987401#M513</guid>
      <dc:creator>chad_voller</dc:creator>
      <dc:date>2024-08-28T19:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12988385#M514</link>
      <description>&lt;LI-CODE lang="general"&gt;fn trimTailDigits str spec:" _-." = trimright str ("0123456789" + spec)

trimTailDigits "string_test_0001"
trimTailDigits #string_test_02&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 29 Aug 2024 07:26:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12988385#M514</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2024-08-29T07:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Remove number sequence from object name</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12988400#M515</link>
      <description>&lt;P&gt;here is specifically for node object names:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;mapped fn trimName node chars:" _-.0123456789" = (node.name = trimright node.name chars)

for k=1 to 10 do box()
trimName objects&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2024 07:34:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/remove-number-sequence-from-object-name/m-p/12988400#M515</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2024-08-29T07:34:21Z</dc:date>
    </item>
  </channel>
</rss>

