PDA

View Full Version : Simple script help


kiranr
02-17-2009, 01:38 PM
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

Piflik
02-17-2009, 02:14 PM
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"
)

vScourge
02-17-2009, 02:28 PM
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\\teapots.max" #("Teapot01", "Teapot02", "Teapot03") #mergeDups
newObjCount = objects.count
for i in (oldObjCount + 1) to newObjCount do (
objects[i].name = uniqueName objects[i].name
)

ZeBoxx2
02-17-2009, 02:34 PM
This might work...
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"
)

Piflik
02-17-2009, 02:44 PM
OK...that i = 1 inside the loop was stupid...I can admit that :D

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.

ZeBoxx2
02-17-2009, 03:10 PM
But the prefix one should work.
But doesn't :)
It makes me wonder if you've tried ;)

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.

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]

kiranr
02-18-2009, 02:33 AM
Thanks
i am amazed at the amount of response and how quick it was!

CGTalk Moderation
02-18-2009, 02:33 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.