Announcement

Collapse
No announcement yet.

Simple Maxscript help anyone?

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

  • Simple Maxscript help anyone?

    Hi,

    I have no experience at all with maxscript. I need to do a lot similar actions to objects in multiple scenes. I believe maxscritp could help to simplify the process.

    This is what I want to do with one button click, after I select several objects manually:
    - add an edit mesh modifier to the selected objects
    - add a UVW map modifier (planar) on top of that with L=2500 and W=250
    - turn off cast shadows and recieve shadows for these objects
    - apply a material called 'brushed alu' to these objects
    - hide the objects

    I was playing a bit with the maxscript listener but I don't really know what I'm doing and don't have the time right now to start learning maxscript. One problem in the listener is that it records the names of the objects selected, so the script won't work on other files since these names won't match.

    Can anyone help me out with this or is this not as simple as it sounds?

    Thanks,

    wouter
    Aversis 3D | Download High Quality HDRI Maps | Vray Tutorials | Free Texture Maps

  • #2
    Code:
    myMat = VrayMtl()
    myMat.name = "brushed alu"
    
    for a in $ do (
    	addModifier a (Edit_Mesh())
    	addModifier a (Uvwmap maptype:0 width:250 length:2500)
    	a.castShadows = false
    	a.receiveshadows = false
    	a.material = myMat
    	a.ishidden = true
    )
    This should do the trick, it has no error checking in so will not work if you select a light or something.

    Comment


    • #3
      Thank you!! Works except for the material part, but I left that out for now and doing that manually.

      Cheers,

      wouter
      Aversis 3D | Download High Quality HDRI Maps | Vray Tutorials | Free Texture Maps

      Comment


      • #4
        What doesn't work about the "material part"? I owe you for all the free aversis hdri's you've given away let us know if you need anything else.
        Colin Senner

        Comment


        • #5
          Well it assigns a material with the correct name, but it should assign a material with that name already present in the mat editor (not yet assigned to any other object).

          Glad you like the hdri's
          Aversis 3D | Download High Quality HDRI Maps | Vray Tutorials | Free Texture Maps

          Comment


          • #6
            Sorry I did not realise you were after an already existing material. This update will find and apply a material editor material called "brushed alu".

            Code:
            (
            	myMat = VrayMtl()
                    myMat.name = "Alu_NotFound"
            	for m in meditMaterials do (
            		if m.name == "brushed alu" do (
            			myMat = m
            			exit
            		)
            	)
            
            	for a in $ do (
            		addModifier a (Edit_Mesh())
            		addModifier a (Uvwmap maptype:0 width:250 length:2500)
            		a.castShadows = false
            		a.receiveshadows = false
            		a.material = myMat
            		a.ishidden = true
            	)
            )
            Last edited by tiw; 20-09-2011, 10:42 AM. Reason: grabs a material editor material instead of scene material

            Comment


            • #7
              Thanks a lot for all your help!

              But the material part still won't work. Maybe it has something to do that it is a vraymtlwrapper material? Or I maybe did something wrong putting the code on a button? This is how it looks on my button, I tried to change VrayMtl into MtlWrapper and also changed the name of the wrapper material to 'brushed alu wrap' and the wrapped material to 'brushed alu main' to make sure they have different names.

              Code:
              macroScript Macro2
              category:"DragAndDrop"
              toolTip:""
              (
              myMat = VrayMtlWrapper()
              myMat.name = "Alu_NotFound"
              for m in meditMaterials do (
              if m.name == "brushed alu wrap" do (
              myMat = m
              exit
              )
              )
              for a in $ do (
              addModifier a (Edit_Mesh())
              addModifier a (Uvwmap maptype:0 width:250 length:2500)
              a.castShadows = false
              a.receiveshadows = false
              a.material = myMat
              a.ishidden = true
              )
              )
              Aversis 3D | Download High Quality HDRI Maps | Vray Tutorials | Free Texture Maps

              Comment


              • #8
                No worries at all, sorry it is not working yet.

                At the moment the script will look through all of the slots of the material editor and try and find a material by the name "brushed alu". If it cannot find it, it applies a default VRayMtl called "Alu_NotFound". I think the problem is that it is looking in the wrong place for the material "brushed alu". When you say it is in the material editor but not applied are you talking about a loaded material library that you have made?

                If you are, this code should work. Please replace 'myLibraryPath' with the path to your Material library and also update 'myMaterialName' to the correct name. If it is still not working, please let me know precisely where you are getting the material and we can debug.

                Code:
                (
                	myLibraryPath = "O:\Material Libraries\2011\0000_DesignStor_basic_VI.mat"
                	myMaterialName = "MET_bronze"
                	
                	myMat = try((loadTempMaterialLibrary myLibraryPath)[myMaterialName])catch()
                	if myMat == undefined do (myMat = VRayMtl name:"Alu_NotFound")
                
                	
                	for a in $ do (
                		addModifier a (Edit_Mesh())
                		addModifier a (Uvwmap maptype:0 width:250 length:2500)
                		a.castShadows = false
                		a.receiveshadows = false
                		a.material = myMat
                		a.ishidden = true
                	)
                )

                Comment


                • #9
                  Hi,

                  No I'm not loading from an external library. The material just sits in the material editor of the file. Attached is a screenshot (in this file, the material is already applied). Normally before running the script, the material also sits in the mat editor but is not yet assigned to any object.

                  Thanks!!!

                  wouter
                  Attached Files
                  Aversis 3D | Download High Quality HDRI Maps | Vray Tutorials | Free Texture Maps

                  Comment


                  • #10
                    Mmm, I am not too sure what is going on then. I have tested it here and it works fine (Max 2011). I suspect it is most likely to either be a typo in material name or something to do with the button creation process. You could try and save the following script as a .ms file and then go to MAXScript->Run Script... This will determine if it is something to do with the button creation or the script. I have some new code which gets the material in a different way that you could try.

                    Code:
                    (
                    	myMat = VrayMtl()
                    	myMat.name = "Alu_NotFound"
                    
                    	try (myMat = meditMaterials["brushed alu wrap"])catch()
                    
                    	for a in $ do (
                    		addModifier a (Edit_Mesh())
                    		addModifier a (Uvwmap maptype:0 width:250 length:2500)
                    		a.castShadows = false
                    		a.receiveshadows = false
                    		a.material = myMat
                    		a.ishidden = true
                    	)
                    )
                    If you are able to save a part of your scene as a Max2011 file, I will be happy to take a look.
                    Last edited by tiw; 21-09-2011, 09:10 AM.

                    Comment


                    • #11
                      Hi, flipside

                      please try this:
                      Code:
                      global aMatDialog
                      try(destroyDialog aMatDialog)catch()
                      (
                          rollout aMatDialog "Assign a Material" width:200 height:30
                      	(
                      	    button btnAssign "Assign"
                      	    fn FindMaterial mO =
                      	    (
                      		for m in meditMaterials do
                      		(
                      		     if (classof m == VRayMtlWrapper) and (m.name == "brushed alu wrap") then try
                      		     (
                      		         objMat = copy m
                      		         mO.Material = objMat
                      			 mO.Material.name = uniquename m.name
                      			 mO.Material.baseMtl.name = uniquename m.baseMtl.name
                      	             )catch()
                      		)
                      	    )
                      	    fn AddModsAndHide =
                      	    (
                      		if (isValidNode $) then try
                      		(
                      	            for a in $ do
                      		    (
                      		        addModifier a (Edit_Mesh())
                      		        addModifier a (Uvwmap maptype:0 width:250 length:2500)
                      		        a.castShadows = false
                      		        a.receiveshadows = false
                      		        FindMaterial a
                      		        a.ishidden = true
                      	            )
                      	        )catch()
                      	    )
                      	    on btnAssign pressed do
                      	    (
                      		AddModsAndHide()
                      	    )
                          )
                          createDialog aMatDialog style:#(#style_titlebar, #style_minimizebox, #style_sysmenu)
                      )
                      I added dialog with a button. If it not needed - you can quickly change script
                      Last edited by Siger; 21-09-2011, 11:12 PM.
                      Regimantas Valiukas
                      SIGER STUDIO
                      www.sigerstudio.eu

                      Comment


                      • #12
                        Hi Siger,

                        I can't get your script to work either, it also only does something when I select only one object. And then it gets assigned a material with the correct name + 01 behind it.

                        @Tiw, I tried running your new script as you said, and then it works... So it must have something to do with not being able to assign it to a button correctly I did it by dragging it from the listener to the max toolbar, as explained in the max help files.

                        I am still on max 2010...

                        So there must be something wrong in the section before your script:

                        Code:
                        macroScript Macro2
                         category:"DragAndDrop"
                         toolTip:""
                        (
                         myMat = VrayMtl()
                         myMat.name = "Alu_NotFound"
                         try (myMat = meditMaterials["brushed alu wrap"])catch()
                         for a in $ do (
                          addModifier a (Edit_Mesh())
                          addModifier a (Uvwmap maptype:0 width:250 length:2500)
                          a.castShadows = false
                          a.receiveshadows = false
                          a.material = myMat
                          a.ishidden = true
                         )
                        )

                        How would you put your code onto a button in the main toolbar?

                        Thanks for your patience
                        Aversis 3D | Download High Quality HDRI Maps | Vray Tutorials | Free Texture Maps

                        Comment


                        • #13
                          Ok I got it! Did the button creation process again, and now the code looks like this, more ()...

                          Code:
                          macroScript Macro3
                           category:"DragAndDrop"
                           toolTip:""
                          (
                           (
                            myMat = VrayMtl()
                            myMat.name = "Alu_NotFound"
                            try (myMat = meditMaterials["brushed alu"])catch()
                            for a in $ do (
                             addModifier a (Edit_Mesh())
                             addModifier a (Uvwmap maptype:0 width:250 length:2500)
                             a.castShadows = false
                             a.receiveshadows = false
                             a.material = myMat
                             a.ishidden = true
                            )
                           )
                          )
                          Aversis 3D | Download High Quality HDRI Maps | Vray Tutorials | Free Texture Maps

                          Comment


                          • #14
                            Yay! Glad you got it to work in the end. If you need any updates in the future, please let me know. I can even add some error checking but that would take all of the excitement out of running the script.

                            Comment


                            • #15
                              Thanks for all the replies, nice to see that this forum is still as helpfull as it was a few years ago
                              Aversis 3D | Download High Quality HDRI Maps | Vray Tutorials | Free Texture Maps

                              Comment

                              Working...
                              X