Simple script help

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2009   #1
Unhappy 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
 
Old 02 February 2009   #2
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"
)
 
Old 02 February 2009   #3
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
)
__________________
Adam Pletcher
Technical Art Director, Volition, Inc. / THQ
blog: Tech Art Tiki
 
Old 02 February 2009   #4
Originally Posted by Piflik: 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"
 )
 
Old 02 February 2009   #5
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.
 
Old 02 February 2009   #6
Originally Posted by Piflik: But the prefix one should work.

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

Originally Posted by Piflik: 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]
 
Old 02 February 2009   #7
Cool

Thanks
i am amazed at the amount of response and how quick it was!
 
Old 02 February 2009   #8
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 09:39 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.