PDA

View Full Version : help with script for saving objects in different maxfiles.


lukx
08-24-2006, 11:56 AM
Let's say I have 10 objects (grouped gemotery example: car, bike, aeroplane). Now I want to write a script which will save each grouped objects in separate files. Also it would be nice if this script reset position of group to 0,0,0. Can someone help me with this?

lukx
08-24-2006, 12:04 PM
I know I can save selected with this command:

saveNodes $ "C:\Documents and Settings\pt\Desktop\Untitled.max"

but how to make maxscript to split all selected groups into different files.

handiklap
08-24-2006, 01:53 PM
Try something like:
for obj in selection do
(
isOpen = false
if isOpenGroupHead obj then
(
isOpen = true
setGroupOpen obj false
)

if isGroupHead obj then
(
tempPos = obj.position
obj.position = [0,0,0]
saveNodes obj.children ("c:/temp/" + obj.name + ".max")
obj.position = tempPos
if isOpen == true then
(
setGroupOpen obj true
)
)
)

This should take all groups (open or not) in the current selection and save them each, centered at 0,0,0 in their own file, and then return them to their previous position and state (open or closed).

lukx
08-24-2006, 02:22 PM
thank you Jeff!!! :) It works perfect. I wish I was as smart as you :).

dutch_delight
08-24-2006, 02:28 PM
i have a smaller version but is not fool proof


select $*
for obj in selection do
(
if (classof obj.baseobject) == dummy then
(
if obj.children.count != 0 then
(
save_file = "C:\\" +obj.name +".max"
move $ [0,0,0]
saveNodes obj.children save_file
)
)
)

lukx
08-25-2006, 05:20 AM
thank you guys again. I don't want to push my luck, but is there anyway to save the file with zoom extents all selected? I mean that when using tbumbnail view I can see group I saved. I know I should use this command:

actionMan.executeAction 0 "311"

but where to put it?

Light
08-25-2006, 05:34 AM
After obj.position = [0,0,0] in handiklap's example.




Light

lukx
08-25-2006, 05:50 AM
thanks Light but it doesn't work. In thumbnail I can see the position I had when running the script.

lukx
08-25-2006, 05:56 AM
I just noticed, It's not working like it should. In my gropus I have dummy object. And when using script it's only saving dyummy object not the geometry.

dutch_delight
08-25-2006, 09:08 AM
Is this something you need to do often? otherwise if there are only about ten objects in your scene, you could have probably done it by now by hand.

lukx
08-25-2006, 09:13 AM
believe me I wouldn't ask if it's one time job.

dutch_delight
08-25-2006, 10:22 AM
select $*
for obj in selection do
(
if (classof obj.baseobject) == dummy then
(
if obj.children.count != 0 then
(
save_file = "C:\\" +obj.name +".max"
obj.position = [0,0,0]
max zoomext sel
saveNodes obj.children save_file
)
)
)


well, i;ve tested this with a dummy in the group and it seems to work fine.

lukx
08-25-2006, 10:49 AM
Thank you Richard. But now script is splitting everything apart. I looks like if I have more than one dummy assigne to an object it's creating files for each dummy.

dutch_delight
08-25-2006, 11:15 AM
select $*

for obj in selection do
(
if (classof obj.baseobject) == dummy then
(
if isGroupHead obj == true then
(
save_file = "C:\\" +obj.name +".max"
obj.position = [0,0,0]
max zoomext sel
saveNodes obj.children save_file
)
)
)

if this doesnt work, i give up! What version of max have you got?

lukx
08-25-2006, 11:42 AM
still it save only dummy. I'm working with max 8. I think I will have to remove dummies in the future and will use your first script. Thank you again Richard.

dutch_delight
08-25-2006, 12:02 PM
very strange, i've got max 8 as well and when i create 2 groups with boxes\dummies and seperate dummies, it only saves the groups and when i load them back in they contain just the data required. (using my scripts)

sorry i cant help you any further.

dutch_delight
08-25-2006, 12:22 PM
ok, never one to give up that easily: try this.





select $*
for obj in selection do
(
if (classof obj.baseobject) == dummy then
(
if isGroupHead obj == true then
(
old_pos = obj.position
object_array = #()
for n = 1 to obj.children.count do
(
object_array[n] = obj.children[n]
)
save_file = "C:\\" +obj.name +".max"
obj.position = [0,0,0]
saveNodes object_array save_file
obj.position = old_pos
)
)
)

lukx
08-25-2006, 12:25 PM
ok, never one to give up that easily: try this.





select $*
for obj in selection do
(
if (classof obj.baseobject) == dummy then
(
if isGroupHead obj == true then
(
old_pos = obj.position
object_array = #()
for n = 1 to obj.children.count do
(
object_array[n] = obj.children[n]
)
save_file = "C:\\" +obj.name +".max"
obj.position = [0,0,0]
saveNodes object_array save_file
obj.position = old_pos
)
)
)

Will try that but I also send you pm with testing scene:)

dutch_delight
08-25-2006, 01:55 PM
ah! there were links inside the group



group_array = #()
select $*

for obj in selection do
(
if (classof obj.baseobject) == dummy then
(
if isGroupHead obj == true then
(
group_array[group_array.count + 1] = obj
)
)
)


for n = 1 to group_array.count do
(
select group_array[n]
old_pos = group_array[n].pos
group_array[n].pos = [0,0,0]
save_file = "C:\\mystuff\\new\\" +group_array[n].name +".max"


for obj in selection do
(
if obj.children != undefined do
(
selectmore obj.children
)
)

saveNodes selection save_file
select group_array[n]
group_array[n].pos = old_pos
)

lukx
08-25-2006, 02:15 PM
wow! You're the best! Where did you learn all this?

dutch_delight
08-25-2006, 02:36 PM
Im just an amateur really. ;)

lukx
08-25-2006, 02:40 PM
talented on for sure :thumbsup:

CGTalk Moderation
08-25-2006, 02:40 PM
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.