[Closed] how to store format " " result as string?
hi
i am generating few lines through format command but it only returns “OK”…
i want to store the expression as string in an array and then append more string to the array and write it to a file at the end of script
can anyone help this is my first script. thanks
another question…
i will generate the fle which should have a block of code like this
Material Standard
diffuseTexture name
bumpTexture name
Material Blend
diffuseTexture name
bumpTexture name
Material Standard
diffuseTexture name
bumpTexture name
Material Composite
diffuseTexture name
bumpTexture name
Material Standard
diffuseTexture name
bumpTexture name
now i want the above code a bit simplified i.e. group all standard type together, blend together and so on… which should look like:
Material Standard
diffuseTexture name
bumpTexture name
diffuseTexture name
bumpTexture name
diffuseTexture name
bumpTexture name
Material Blend
diffuseTexture name
bumpTexture name
Material Composite
diffuseTexture name
bumpTexture name
is it possible to do this just by opening the text file or will i have to do when i am writing the values… thats why i want to store the values in array and write in the end but i am not sure which one will be more efficient.
please someone help…
matArray = #()
for m in meditMaterials do
(
tempArray = #()
append tempArray (classof m)
try(append tempArray m.DiffuseMap.name)catch(append tempArray "undefined")
try(append tempArray m.BumpMap.name)catch(append tempArray "undefined")
append matArray tempArray
)
txt = ""
txt += "Standard Materials
" --the
is used to start a new line
for m in matArray where m[1] == standardMaterial do
(
txt += "diffuseTexture: " + m[2] + "
"
txt += "bumpTexture: " + m[3] + "
" --two new lines are added to separate the different materials
)
txt += "Blend Materials
"
for m in matArray where m[1] == blend do
(
--repeat for blend and composite materials
)
ok so the way this code works is all materials in the materialEditor are stepped through. a tempArray is created for each and the classof the material, the diffuseMap name and the bumpMap name are appended to the tempArray. the tempArray is then appended to the main array matArray. then we initialize a variable to hold our text. ie txt = “”
Then step through matArray, check if the first element of the nested array is standardMaterial, if so then we continue to add to the txt variable. Repeat for blend and composite materials
after all the info is collected just format txt to your filestream and ta daaaaa that’s it.
things that can be easily changed are meditMaterials to sceneMaterials, the items that are originally collected eg. instead of the map name, collect the filename and/or full path. etc
hope this helps
an alternative would be instead of collecting all the info in a variable and then format to a filestream, you could open your filestream first and just format to it as you go. This way you dont end up with a variable that could be quite large. If it gets too large there could be a memory issue
thats exactly what i have done now… i am formatting into a filestream as i go on… and it working. thanks for your help. now i have to extend the script and add more features to it…
i work in a gaming co. and we have to export out models from max but our exporter only exports the material names with the model file and doesnt create what we call a fragment file that contains all the maps, type of shader and materials…everything related to materials…
and that process of creating the file and entering all the maps etc is too boring and for every small error even like a small typo will give u an error during the build… so thats what i have decided to automate…
its not just finished but yesterday i started doing it (my first script) and i managed to read all the values i wanted and write it to a file… now i have to add some checks for formatting the file a bit more and then add support for checking what material is being used on each layers (not object) and duplicate those materials for our Lods… (having said that, is is possible to find out the material used per layer…?)
if i can do this as planned it will be months of time saving
having said that, is is possible to find out the material used per layer…?
I’m not quite sure what you mean by ‘materials per layer’. Can you be a little more specific?
my objects are stored on say 5 layers… Layer 1, layer 2, layer 3 and so on.
now my main Layer 1 has the first lod, so it uses all the materials
but say in Layer 2 i have deleted some objects so it does not use some materials… thats why i need to find out
materials used by objects in Layer 1 = material1, material2, material3
materials used by objects in Layer 2 = material1, material3
is it possible?
another question if you can help me with…
i am checking for materials in a multisub and the .materialList contains say 12 materials
how can i sort this list in ascending order according to their name… i tried using the sort function but it doesnt work.
and i am using getsavefilename to open the save file dialog when i want to select the file to write the info to… everythins is ok but just that max locks the file until u quit max and you cant edit it…??? any ideas…
thanks for all ur time man
--matArray is already defined with the name of each material
--appended to the nested arrays as the first item.
layerMats = #()
layerNames = #("layer 1", "layer 2") --manually enter layernames
for n in layerNames do
(
tempArray = #()
append tempArray n
for m in matArray do
for g in geometry where g.layer.name == n AND g.material.name == m[1] do
append tempArray m.name
append layerMats tempArray
)
I think something like this answers you layers question.
basically for each layer you create a tempArray again, append the current layer name, and then for each material in matArray, loop though all geometry objects, checking if they are on the current layer ‘n’ with the current material ‘m’. If they are, then append the current material to the tempArray. If not, then the material is not on any object on that layer.
As for your other questions, I can’t think of anything off the top of my head and its 12.30am here so i’ll have another look for you in the morning.
EDIT: changed one of the lines to:
for g in geometry where g.layer.name == n AND g.material.name == m[1] do
–changed g.material to g.material.name and m to m[1]