make changes on a collection of max files

I try to make a script that makes some changes on all max files in the same file directory.
The Script shout change:
-the system unit to cm and scale all objects
-give all objects the same layer
-give all objects one group with the name off the max file
-move this group to the center of the scene. The lowest point should be on Z=0
It works all nice except to move the group.
I find a way to move the group the way I like. But when I try to use it in my for loop it don´t works.
I wrote a small script to show my problem:

files = getFiles (maxfilepath+"*.max")
for i=1 to files.count do (
LoadMaxFile files[i]
max select all
str = "$"+getFilenameFile maxfilename+".position = $"+getFilenameFile maxfilename+".boxsize /2"
execute str
max file save
)

I hope someone can help me with this problem.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Perb's picture

Thanks a lot for your answer.

Thanks a lot for your answer. I am not good in explain whats the problem is. Sorry that I had do ask again but I have still no solution for my problem.
When I open my test Scene "move_a_group_testscene_01.max" and execute this lines:

max select all
g = group selection name: "xx"
g.min

then i got as a value for g.min this [1053.19,1539.19,321.903]. Now I have 3 objects selected. When I now deselect this objects and select my group then I got for g.min this value [885.948,1319.04,271.913].
I can´t understand why the value of g.min change. It is the same problem with g.boxsize.
Thanks for your efforts

Perb's picture

Now I have tried a new way to

Now I have tried a new way to move the group. This time without any $:)
I think that this is the same problem.

max select all
mname = getFilenameFile (maxfilename) as string
g = group selection name: mname
--clearSelection()
--max select all
g.pos = g.boxsize/2

When I execute this in the listener it Works. But when I delete the two lines, to clear the Selection and select all again, it don´t work. It also don´t work when I use it in the script "bibliothek_tool".
I attach the test scene that I use.
Can someone understand why it is necessary to clear the selection and select all again?

AttachmentSize
move_a_group_testscene_01.max 180 KB
Anubis's picture

where is the prob?...

After group selection call Max deselect your objects, so no need to clear the selection, nor yet need to select again as you have the group head stored in variable "g". And g.pos = g.boxsize/2 will not move the group to the world center, but only will align it min.z to 0, so after this line add: g.pos = [0,0,g.pos.z] -- thet will align it to zero by X and Y while preserve Z as you need.

my recent MAXScripts RSS (archive here)

Perb's picture

Thank you for your answer. I

Thank you for your answer. I am realy new on scripting. So maybe I use some methods that are not usual or simply crap.
I thought it is more simple for you when I post only the part of the script that don´t works. I attach now the howl script. It works how I like exept the part to move the group. This part works also when I use it in my open scene. It don´t works when I use it in the for loop.
I can´t post the error message becaus ther is no error. It don´t move the group like it shout.
This is the part that don´t work:

str = "$"+getFilenameFile maxfilename+".position = $"+getFilenameFile maxfilename+".boxsize /2"
execute str

the rest of the script is attacht.
Can you unterstand why it works diffrent in the for loop then without a loop?

AttachmentSize
bibliothek_tool_v05.ms 2.32 KB
br0t's picture

Your script does not show

Your script does not show what you described, there is no grouping of the selected objects and no renaming of the group. It would also be helpful if you post the error message from the script listener when you execute your script. Right now there is not much I can do to help you with that little information.

I guess the problem might be how you set the group position. When you create a group, you will get a new node called the group head (isGroupHead = true) which you then have to reposition.

Also your method of constructing a string and then executing that is rather unusual. I dont say its wrong, but maybe you should not make a habit of it as you could run into problems. I dont recommend using the "$" at all.

Never get low & slow & out of ideas

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.