Notifications
Clear all

[Closed] Simple Script help

This might seem silly but i am just starting to learn mxs so please help me

how can i make an object merge from another file and rename it automatically
i need help especially with the renaming bit

6 Replies

This might work…(You have to replace “path” with the maxfile you want to merge and “newname” with the name you want to give them)

clearSelection()

mergeMaxFile "Path" #select #mergeDups

for o in selection do
(
i = 1
o.name = "newname" + i as string
i += 1
)

or this, if you want to keep the old names but add a prefix

clearSelection()

mergeMaxFile "Path" #select #mergeDups

for o in selection do
(
o.prefix = "prefix"
)
1 Reply
(@zeboxx2)
Joined: 10 months ago

Posts: 0

Except it doesn’t… I’ll get to ‘why’ later.


oldSel = getCurrentSelection()
mergeMaxFile "filename.max" #select #mergeDups
newSel = getCurrentSelection()
for i = 1 to newSel.count do (
	curObj = newSel[i]
	curObj.name = "Merged Object #" + (i as string)
)
clearSelection()
select oldSel

or, foregoing the selection by counting objects (there should be more after you merge one in):


objCount = objects.count
mergeMaxFile "filename.max" #mergeDups
for i = objCount to objects.count do (
	curObj = objects[i]
	curObj.name = "Merged Object #" + ((i - objCount + 1) as string)
)

==================================================

Now as for why the other bits don’t work as intended…


clearSelection()
-- not needed if using #select below as the current selection is already cleared
 
 mergeMaxFile "Path" #select #mergeDups
 
 for o in selection do
 (
 i = 1
-- here you set i to 1
 o.name = "newname" + i as string
-- therefore, all the selected objects will be named "newname1"
 i += 1
-- increasing it here doesn't help as it is now as it gets reset to 1 at
-- the beginning of the loop.
-- 'i = 1'  should go -before- (and thus outside the scope of) the for ... loop
 )

 for o in selection do
 (
 o.prefix = "prefix"
-- there is no such property as 'prefix' on most objects.
-- you'd be looking for something like:
-- o.name = "prefix" + o.name"
 )

Here’s another approach, but by using uniqueName, you’re guaranteed to have no name conflicts in the end. Also doesn’t change your selection, if that matters at all.

oldObjCount = objects.count
mergemaxfile "C:\\maxfiles\	eapots.max" #("Teapot01", "Teapot02", "Teapot03") #mergeDups
newObjCount = objects.count
for i in (oldObjCount + 1) to newObjCount do (
objects[i].name = uniqueName objects[i].name
)

OK…that i = 1 inside the loop was stupid…I can admit that

But the prefix one should work. At least I found ‘prefix’ in the MaxScript Reference under ‘Node Common Properties’ so that should work with about everything you can create in max.

1 Reply
(@zeboxx2)
Joined: 10 months ago

Posts: 0

But doesn’t
It makes me wonder if you’ve tried

true, but only as a construction argument.

E.g.


sphere prefix:"Hello"
$Sphere:Hello01 @ [0.000000,0.000000,0.000000]
sphere prefix:"Hello"
$Sphere:Hello02 @ [0.000000,0.000000,0.000000]

which would be similar to:


mySphere = sphere()
$Sphere:Sphere01 @ [0.000000,0.000000,0.000000]
mySphere.name = uniqueName "Hello"
"Hello03"

However, it doesn’t work as a property:


mySphere2 = sphere()
$Sphere:Sphere01 @ [0.000000,0.000000,0.000000]
mySphere2.prefix = "Hello"
-- Unknown property: "prefix" in $Sphere:Sphere01 @ [0.000000,0.000000,0.000000]

Thanks
i am amazed at the amount of response and how quick it was!