Announcement

Collapse
No announcement yet.

MaxScript noob needs a little help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MaxScript noob needs a little help

    I'm tying to write a little spript that adds a material modifier to all selected objects and sets its ID.
    After stealing ideas from Lele's One liner thread, the macro recorder and a little bit chat gpt I got this:

    Click image for larger version  Name:	Screenshot_59.png Views:	0 Size:	8.8 KB ID:	1213815

    Which works very good, if there is only one object selected. When I select multible objects i get:
    Click image for larger version  Name:	Screenshot_60.png Views:	0 Size:	6.4 KB ID:	1213816

    Needless to say I dont really have a clue of what Im doing here.
    I can't be far off but im kinda stuck now and I need this to work, I have to set material id's for >100k objects.

    for some reason the forum doesent like if i write code in here even in the [ Code ] tag. I allways get a 403 error... so I posted images. Sorry for that
    Last edited by Ihno; 12-08-2024, 11:48 PM.
    German guy, sorry for my English.

  • #2
    Do all of the Material Modifiers need to be unique or can they be instanced?
    www.dpict3d.com - "That's a very nice rendering, Dave. I think you've improved a great deal." - HAL9000... At least I have one fan.

    Comment


    • #3
      Instaced for the objects I selected is fine.
      My Process would be: selecting a bunch of objects that I now need a certain mat ID - hit the button for that ID - Assign them to a hidden layer so they are gone and I can move on to the next bunch of objects.
      A few days of that and I should be done.

      (yes I'll put macroscrpt buttons for like 20 ids in a toolbar, I know a script with a dialoge and proper UI would be waay cooler but would take me a few days to malke probably an I dont have those)
      Last edited by Ihno; 12-08-2024, 08:06 AM.
      German guy, sorry for my English.

      Comment


      • #4
        This should do it then...

        Code:
        modPanel.addModToSelection (Materialmodifier())
        for mod in selection[1].modifiers do (if (classOf mod EQUALEQUAL Materialmodifier) then (mod.materialID = 17))
        IMPORTANT: You need to replace the EQUALEQUAL in the code to two equal signs. It's the double equal sign that throws the 403 error.

        The addModToSelection will add an instanced Material ID modifier to all of the objects but you only need to change the modifier on one of them ("selection[1]") to the new value rather than cycling through all of them. Fast enough on a few items but if you had hundreds it might take a bit of time and isn't necessary.

        Probably easier ways to do this but it'll work.
        Last edited by dlparisi; 12-08-2024, 10:14 AM.
        www.dpict3d.com - "That's a very nice rendering, Dave. I think you've improved a great deal." - HAL9000... At least I have one fan.

        Comment


        • #5
          Thanks man, you saved my life!
          German guy, sorry for my English.

          Comment


          • #6
            Here's a quick version with a dialog box to set the Material ID. Same EQUALEQUAL change as before...
            Code:
            rollout matID "Set Material ID" width:160 height:96
            (
                spinner 'spn1' "New Material ID" pos:[12,14] width:68 height:16 range:[1,100,1] type:#integer scale:1 align:#left
                button 'btn1' "Set Material ID" pos:[8,43] width:144 height:40 align:#left
                
                on btn1 pressed do
                (
                    if selection.count != 0 then 
                    (
                        modPanel.addModToSelection (Materialmodifier())
                        for mod in selection[1].modifiers do (if (classOf mod EQUALEQUAL Materialmodifier) then (mod.materialID = spn1.value))
                    )
                )
            )
            CreateDialog MatID()
            www.dpict3d.com - "That's a very nice rendering, Dave. I think you've improved a great deal." - HAL9000... At least I have one fan.

            Comment

            Working...
            X