Home Technical Talk

Maxscript Help

polycounter lvl 10
Offline / Send Message
MattW polycounter lvl 10
I tried recording a macroscript to update 5 materials in scene since I have to do it a few hundred times across this very large project but I've hit a bit of a wall.

When it gets to the line
meditMaterials[2][#Maps][#Diffuse_Color__Map__188__TSO_Uniform_Pants_jpg].coords.U_Tiling = 1
I'm getting the error:
--Unknown property: "coords" in undefined

That line was taken directly from the macro recorder window. I tried google and reading through the maxscript reference, but according to that either that or eliminating the .coords should work, but both are failing.

I need to change the tiling from 5 on both to 1. Any help would be greatly appreciated. Thanks in advance.

Replies

  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    God damn it, I hit the back button by mistake and the forums destroyed all my typing... gah! I had a little maxscript pseudocode sketch of how you might script it, too :(

    Quick run-down:

    It's probably returning "undefined" because you're looking for a far too specific material. Of course "undefined" has no ".coords" property, which explains the error you're getting.

    Your macro script here is basically looking for a map with a certain name in the 2nd material slot of the material editor. Unless all your scenes in the project are hugely consistent, this is unlikely to be true, since any material can be in the 2nd slot of the material editor, and even if it was the right material, does it even have the same map name (since you're looking that up specifically from that material's Maps array) ?

    You'll want to loop through all materials in the scene, check if they have bitmaps set with filenames which match "TSO_Uniform_Pants.jpg" (or whatever filename this is you're editing properties of) and only then try to set the "coords.U_Tiling" value, since by then you'll know it exists, regardless of which material slot or map name the bitmap texture has.
  • MattW
    Options
    Offline / Send Message
    MattW polycounter lvl 10
    Oof, sorry to hear you had to retype it, but thanks for the reply

    Actually oddly enough they are consistent, that's why I figured I would be able to do this.

    But to be safe, the first thing the script does is put the 5 materials in specific slots then go on from there.

    This is the actual script as recorded:
    macroScript Macro2
        category:"DragAndDrop"
        toolTip:"TSO Mat Update"
    (
        meditMaterials[1] = sceneMaterials["Mtl_body_aaTSO"]
        meditMaterials[2].DirectX_Manager.enabled = off
        meditMaterials[2] = sceneMaterials["Mtl_uniformPants"]
        meditMaterials[2].DirectX_Manager.enabled = off
        meditMaterials[3].DirectX_Manager.enabled = off
        meditMaterials[3] = sceneMaterials["TSA patch"]
        meditMaterials[3].DirectX_Manager.enabled = off
        meditMaterials[4].DirectX_Manager.enabled = off
        meditMaterials[4] = sceneMaterials["HLS patch"]
        meditMaterials[4].DirectX_Manager.enabled = off
        meditMaterials[5].DirectX_Manager.enabled = off
        meditMaterials[5] = sceneMaterials["Mtl_badge"]
        meditMaterials[1].material1.DirectX_Manager.enabled = off
        meditMaterials[1].material1.diffuseMap = Bitmaptexture fileName:"M:#DHS-TSAAvatarsmale_TSOtextureshightower_df-01.jpg"
        meditMaterials[1].material1[#Maps][#Diffuse_Color__body_diffuse__hightower_df_01_jpg].alphaSource = 2
        meditMaterials[1].material1.DirectX_Manager.enabled = off
        meditMaterials[1].material1[#Maps][#Specular_Level__body_spec__eric_bm_jpg].preMultAlpha = on
        meditMaterials[1].material1.DirectX_Manager.enabled = off
        meditMaterials[1].material1.bumpMap = Bitmaptexture fileName:"M:#DHS-TSAAvatarsmale_TSOtextureseric_bm.jpg"
        meditMaterials[1].material1.specularLevelMapAmount = 100
        meditMaterials[1].material1.specularLevel = 1
        meditMaterials[2].DirectX_Manager.enabled = off
        meditMaterials[2].diffuseMap = Bitmaptexture fileName:"M:#DHS-TSAAvatarsmale_TSOtexturesTSO_Uniform Pants.jpg"
        meditMaterials[2][#Maps][#Diffuse_Color__Map__188__TSO_Uniform_Pants_jpg].coords.U_Tiling = 1
        meditMaterials[2][#Maps][#Diffuse_Color__Map__188__TSO_Uniform_Pants_jpg].coords.V_Tiling = 1
        meditMaterials[3].DirectX_Manager.enabled = off
        meditMaterials[3].opacityMap = undefined
        meditMaterials[4].DirectX_Manager.enabled = off
        meditMaterials[4].opacityMap = undefined
        meditMaterials[5].material1.DirectX_Manager.enabled = off
        meditMaterials[5].material1.opacityMap = undefined
    )
    
    I had to clear out a number of things to get it to work, specifically the directX property that occurs everytime I click on a new map, and the alphaSource property as that was coming up undefined too. Pretty much anything that begins with [#Maps][#Diff...

    But if the only problem could be that the material isn't there, well then I'm not sure as like I said, I'm making sure it's there prior.

    Now I found a sneaky solution, since I need them to the 1 and 1, just changing the bitmap reverts them to that value, as long as I change both the type and file. just changing the file not only leaves the tiling the same and isn't recorded anyway.

    But what if that wasn't the case and I just needed to change the tiling on a map? That's the code it would record, but apparently either the syntax is wrong or it's looking for a property that doesn't exist in whatever class it's pulling from.

    Sorry for the wall of text.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    So is the map itself always called "Diffuse_Color__Map__188__TSO_Uniform_Pants_jpg" ?

    Do a test by instead of trying to set it immediately, in that script first list the contents of meditMaterials[2][#Maps], see what it contains.
    Because while you're getting the material from the scene, does that actually guarantee that the map name is the same for that material?
  • MattW
    Options
    Offline / Send Message
    MattW polycounter lvl 10
    hmm, I suppose that the Map_188_ might change, I'm not sure how max assigns those numbers, but it's very possible that that changes. Didn't really notice that specific part until just now.

    ...
    Ok, just checked, A way around having to search for it, which could be time consuming for the machine, is instead to set the diffuse map name first to something, then set the tiling.

    Great catch, thanks MoP

    Edit: nope, I was wrong, can't change the name without knowing the current name. So I guess you're method of looking for the map that contains Uniform.jpg is the only way. I'm not that great with max/macroscript so I'm not sure how to format that, but like I said, now I'm into theory, for my purposes since I need the values set to default, just changing the bitmap is enough for me so I wouldn't sweat it too hard.
  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    This'll do it:
    for m in scenematerials where classOf m == Standardmaterial do
    (
        if classOf m.diffuseMap == Bitmaptexture then
        (
            if findString m.diffuseMap.bitmap.filename "TSO_Uniform_Pants" != undefined then
            (
                m.diffuseMap.coords.U_Tiling = 1.0
            )
        )
    )
    

    This script assumes your materials are standard materials, assumes you're looking for a Bitmap texture in the Diffuse slot, and assumes the filename you want to check contains the string "TSO_Uniform_Pants".

    If all these conditions are met, then it will set the tiling of this texture's map (regardless of the name of the map) to 1.0.
  • MattW
    Options
    Offline / Send Message
    MattW polycounter lvl 10
    awsome Mop, thanks for the help. Much appreciated.
Sign In or Register to comment.