Announcement

Collapse
No announcement yet.

Scripting - simple issues here :)

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

  • Scripting - simple issues here :)

    Heya

    I'm trying to script out my workflow so its easier to apply materials edit objects and so on... I have few simple issues..

    Basically

    1. applying texture to slot

    for O in $ do
    $.material = VRayMtl ()
    $.material.texmap_diffuse = Noise ()

    This wont work for some reason...

    2. copying texture from 1 slot to another...



    $.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    $.material.basemtl.texmap_bump = copy texmap_reflection -- in this case I have Blend with Vray in 1st slot. I'm trying to copy my reflection to bump slot - or instance if its possible...
    $.xxxxxxxxxxxxxxxxxxxxxx

    3. and for UI I just want button to enable/disable options or to execute the script I write...

    rollout Shortcuts "On/Off Shortcuts" width:162 height:300
    (
    button ONTS "ON" pos:[8,32] width:57 height:24
    button OFFTS "Off" pos:[88,32] width:57 height:24

    on ONTS press do
    (

    timeSlider.setVisible True
    )
    on OFFTS press do
    (

    timeSlider.setVisible False

    )

    )

    myfloater = (newRolloutFloater "DM Tools" 195 552)
    addRollout Shortcuts myfloater


    I almost got it naild I just still got issue whith these 3 things any idea how to fix them?

    Thanks, bye.
    CGI - Freelancer - Available for work

    www.dariuszmakowski.com - come and look

  • #2
    1.
    This will put a different VRay material on every object you have selected.
    Code:
    for o in $ do
    (
    	o.material = VRayMtl ()
    	o.material.texmap_diffuse = Noise ()
    )
    or this will put the same material on the selection.
    Code:
    myMat = VRayMtl texmap_diffuse:(noise())
    for o in $ do
    (
    	o.material = myMat
    )
    2.
    Code:
    $.material.basemtl.texmap_bump = $.material.basemtl.texmap_reflection
    or
    Code:
    $.material.basemtl.texmap_bump = copy $.material.basemtl.texmap_reflection
    3.
    Code:
    rollout Shortcuts "On Off Shortcuts" width:162 height:300
    (
    	button ONTS "ON" pos:[8,32] width:57 height:24
    	button OFFTS "Off" pos:[88,32] width:57 height:24
    
    	on ONTS pressed do
    	(
    		timeSlider.setVisible True
    	)
    	on OFFTS pressed do
    	(
    		timeSlider.setVisible False
    	)
    )
    
    myfloater = (newRolloutFloater "DM Tools" 195 552)
    addRollout Shortcuts myfloater
    Last edited by DanielBrew; 26-01-2012, 09:46 AM.
    Dan Brew

    Comment


    • #3
      Heya

      Woho u amazing thanks !

      Now all works And I hit another wall heh... the script works if I use 1 selected object, but it crashes when I use multiple selected objects... is there a short way to fix it or I have to creat an array ? I've played with arrays b4 but I rather avoid it as it require more coding and eeeeee headacheeeeee



      Here is example scripts
      Code:
      	for O in $ do
      	$.material = VrayMtl ()
      	$.material.name = "Glass_Simple"
      	$.material.diffuse = color 0 0 0
      	$.material.Reflection = color 255 255 255
      
      [COLOR="#FF0000"]Unknown property: "material" in $selection[/COLOR]
      Thanks
      CGI - Freelancer - Available for work

      www.dariuszmakowski.com - come and look

      Comment


      • #4
        Code:
        for o in getCurrentSelection() do (
           try (
              o.material = VRayMtl name:"Glass Simple"
              o.material.diffuse = color 0 0 0
              o.material.Reflection = color 255 255 255
           ) catch()
        )
        If you have multiple things to be evaluated in a for statement you need ( and ).

        Also, your for statement is working incorrectly (obviously), but what I mean is.

        the $ symbol is a dynamic variable that contains whatever the user has selected already. It's better practice to get the user's selection as a variable by using getCurrentSelection(), that way if you change the user's selection during runtime, you still have access to your old selection.

        Code:
        for o in getCurrentSelection() do (
        the variable o now contains each object that you're iterating over.

        The try()catch() is because some types of objects can't have a material applied and the script will fail. This is just a quick hack to catch all, better practice would be to check for a #material property on the object first, you could do this instead as well:

        Code:
        for o in getCurrentSelection() where (isProperty o #material) do (
        this _should_ eliminate the need for the try/catch. Max isn't really very straightforward though with it's junk.

        Hope this helps.

        -Colin
        Last edited by MoonDoggie; 26-01-2012, 12:46 PM.
        Colin Senner

        Comment


        • #5
          Heya

          wow thanks this 1 works for materials ! But it broke second part of my script (which was broke anyway because of multi selections heh...)

          Heres the issue
          Code:
          	for o in getCurrentSelection() do (
             try (
          	modPanel.addModToSelection (UVWMap ()) ui:on
          	o.modifiers[#UVW_Map].maptype = 4
          	o.modifiers[#UVW_Map].length= .50
          	o.modifiers[#UVW_Map].width = .50
          	o.modifiers[#UVW_Map].height = .50
          	o.modifiers[#UVW_Map].mapChannel = 5
          	o.material = VrayBlendMtl ()
          	   ) catch()
          )
          I'm actually using it to add a set of modifiers and apply texture. What he does now he is applying +1 modifier for each selected object... soo 3 selection 3x uvw. 10 selection 10x uvw and other...

          Any hints how to solve this adding extra mod per object?
          Last edited by Dariusz Makowski (Dadal); 26-01-2012, 01:10 PM.
          CGI - Freelancer - Available for work

          www.dariuszmakowski.com - come and look

          Comment


          • #6
            Your line:
            Code:
            modPanel.addModToSelection (UVWMap ()) ui:on
            is adding a UVWmap to the whole selection with every iteration of the for loop.

            So you need to only add the UVWmap to the object o
            Code:
            for o in getCurrentSelection() where validModifier o UVWmap do
            (
            	addModifier o (UVWmap())
            	o.modifiers[#UVW_Map].maptype = 4
            	o.modifiers[#UVW_Map].length= .50
            	o.modifiers[#UVW_Map].width = .50
            	o.modifiers[#UVW_Map].height = .50
            	o.modifiers[#UVW_Map].mapChannel = 5
            	if isProperty o #material then o.material = VrayBlendMtl ()
            )
            you can also can test whether o can accept a UVWmap by checking if:
            Code:
            validModifier o UVWmap
            returns 'true'.

            The above code works but if your object already has another UVWmap on another mapChannel then a better way would to to construct your UVWmap before applying it:
            Code:
            for o in getCurrentSelection() where validModifier o UVWmap do
            (
            	local UVWmod = UVWmap mapType:4 length:0.5 width:0.5 height:0.5 mapChannel:5
            	addModifier o UVWmod
            	if isProperty o #material then o.material = VrayBlendMtl ()
            )
            Dan Brew

            Comment


            • #7
              Heya

              Thanks alot ! I've been scripting like crazy for past few days but I hit anot her wall doh !

              Its quite simple one I made a delete all modifiers button but it wont work on multiple objects... any hints ?


              Code:
              on deleteAll pressed do
              	(
              	for o in getCurrentSelection() do (
              	try (
              		
              	deleteModifier $ 1
              	deleteModifier $ 1
              	deleteModifier $ 1
              	deleteModifier $ 1
              	deleteModifier $ 1
              	deleteModifier $ 1
              	deleteModifier $ 1
              	deleteModifier $ 1
              	deleteModifier $ 1
              	deleteModifier $ 1
              		) catch()
              	)
              	)
              Any hints how to make it work? :s
              CGI - Freelancer - Available for work

              www.dariuszmakowski.com - come and look

              Comment


              • #8
                "deleteModifier $ 1" is telling maxscript to run the deletemodifier on only the currently selected object, represented by $ in this case. You're using a loop so instead of the dollar symbol, use the letter you're using in the for loop. So in your case:

                Code:
                on deleteAll pressed do
                	(
                	for o in getCurrentSelection() do (
                	try (
                		
                	deleteModifier o 1
                	deleteModifier o 1
                	deleteModifier o 1
                	deleteModifier o 1
                	deleteModifier o 1
                	deleteModifier o 1
                	deleteModifier o 1
                	deleteModifier o 1
                	deleteModifier o 1
                	deleteModifier o 1
                		) catch()
                	)
                	)
                note I haven't run this so it's not guaranteed but that should be your error! Bobo's maxscript for the masses DVD has been uploaded on youtube so I'd suggest a look at that, it covers most of the day to day stuff associated with working with large amounts of objects.

                Comment


                • #9
                  deleteModifier only works on single objects not collections like '$'. Try this:
                  Code:
                  on deleteAll pressed do
                  (
                  	for nd in getCurrentSelection() do
                  	(
                  		for m = 1 to (nd.modifiers).count do
                  		(
                  			deleteModifier nd 1
                  		)
                  	)
                  )
                  Dan Brew

                  Comment


                  • #10
                    woops, joconnell types faster than me
                    Dan Brew

                    Comment


                    • #11
                      Mao u guys are epic !

                      Off to tweak out script and keep on writing !

                      Thanks.
                      CGI - Freelancer - Available for work

                      www.dariuszmakowski.com - come and look

                      Comment


                      • #12
                        And I hit another wall. Which is weird because it work with Turbosmooths but not with UVW maps

                        In any case heres part of script
                        Code:
                        	on UVWPaint pressed do
                        	(
                        		for o in getCurrentSelection() do (
                        	   try (
                        		addmodifier o (UVWMap ())
                        		o.modifiers[#UVW_Map].maptype = 4
                        		o.modifiers[#UVW_Map].length = 0.8
                        		o.modifiers[#UVW_Map].width = 0.8
                        		o.modifiers[#UVW_Map].height = 0.8
                        		o.modifiers[#UVW_Map].mapChannel = 1
                        		o.modifiers[#UVW_Map].gizmo.position = [1,1,1]
                        		addmodifier o (UVWMap ())
                        		o.modifiers[#UVW_Map].maptype = 4
                        		o.modifiers[#UVW_Map].length = 0.8
                        		o.modifiers[#UVW_Map].width = 0.8
                        		o.modifiers[#UVW_Map].height = 0.8
                        		o.modifiers[#UVW_Map].mapChannel = 2
                        		o.modifiers[#UVW_Map].gizmo.position = [.3,-.8,0.7]
                        		addmodifier o (UVWMap ())
                        		o.modifiers[#UVW_Map].maptype = 4
                        		o.modifiers[#UVW_Map].length = 0.8
                        		o.modifiers[#UVW_Map].width = 0.8
                        		o.modifiers[#UVW_Map].height = 0.8
                        		o.modifiers[#UVW_Map].mapChannel = 3
                        		o.modifiers[#UVW_Map].gizmo.position = [-0.86,2,-0.96]
                        				) catch()
                        	)
                        	)
                        If I select 1 object and add it works. If I select more than 1 object it only add 1 uvw, and dont add any more, nor set up the position offsets...

                        Any hints?
                        CGI - Freelancer - Available for work

                        www.dariuszmakowski.com - come and look

                        Comment


                        • #13
                          well that's not very elegant

                          anyway, first get rid of the try/catch. It suppresses errors, so you can't see what's wrong.

                          in this special case you did no do anything wrong really, but you hit a maxscript peculiarity.
                          you add the modifier in a loop and try to change it's position before max knows that it's there, simply put. if you add the line "classOf o" before accessing the gizmo position, the modifier gets "initialized" and it should work. I know that it doesn't make sense, but that's often the case with maxscript. It starts with "simple issues", but as you dig deeper things are not that simple anymore.
                          Marc Lorenz
                          ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___
                          www.marclorenz.com
                          www.facebook.com/marclorenzvisualization

                          Comment


                          • #14
                            It's probably generating an error, because you're applying it to an object that can't have a modifier applied (like a group head or camera), which is suppressed by the try/catch.

                            The below is bad, because it's unclear exactly what you're referring to, it's not bad because it doesn't work (it does), but you should always be explicit when possible .
                            You're referring to the UVW_Map's via this:

                            o.modifiers[#UVW_Map]

                            Best case, is create the UVW_Maps you are going to apply and store them in a variable (or at least name them first) and then apply them.

                            Like this:

                            Code:
                                for o in getCurrentSelection() where (isKindOf o GeometryClass) do -- Now we're doing a simple check to make sure we're applying it to just geometry in the selection
                                (
                                    UVWMap1 = UVWMap name:"UVW_Map1" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:1    -- Created 3 variables to store our modifiers
                                    UVWMap2 = UVWMap name:"UVW_Map2" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:2    -- So it's easier to refer back to them
                                    UVWMap3 = UVWMap name:"UVW_Map3" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:3
                            
                            
                                    -- Add the modifiers, and change the gizmo positions (via the variables we stored it in)
                                    
                                    addmodifier o UVWMap1    
                                    UVWMap1.gizmo.position = [1,1,1]
                                    addmodifier o UVWMap2
                                    UVWMap2.gizmo.position = [.3,-.8,0.7]
                                    addmodifier o UVWMap3
                                    UVWMap3.gizmo.position = [-0.86,2,-0.96]
                                )
                            Last edited by MoonDoggie; 03-02-2012, 10:12 AM.
                            Colin Senner

                            Comment


                            • #15
                              Heya

                              Sorry for being quiet for so long, had loads of work. Anyway heres what I stand on.

                              MoonDoggie - Ur method dont work either, I get

                              Code:
                              -- Error occurred in o loop; filename: D:\Graphics\Install Software\3Ds Max Plugins\Scripts\Important\My\; position: 738; line: 10
                              --  Frame:
                              --   UVWMap1: Uvwmap:UVW_Map1
                              --   o: $Teapot002
                              --   UVWMap2: Uvwmap:UVW_Map2
                              --   UVWMap3: Uvwmap:UVW_Map3
                              -- Unknown property: "gizmo" in Uvwmap:UVW_Map1
                              in Plastic_ idea I get

                              I plug in this, and other ways ( I did try it for like 30 min b4 I give up.)
                              Code:
                                 for o in getCurrentSelection() where (isKindOf o GeometryClass) do -- Now we're doing a simple check to make sure we're applying it to just geometry in the selection
                                  (
                                      UVWMap1 = UVWMap name:"UVW_Map1" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:1    -- Created 3 variables to store our modifiers
                                      UVWMap2 = UVWMap name:"UVW_Map2" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:2    -- So it's easier to refer back to them
                                      UVWMap3 = UVWMap name:"UVW_Map3" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:3
                              
                              
                                      -- Add the modifiers, and change the gizmo positions (via the variables we stored it in)
                                      addmodifier o UVWMap1    
                                      classOf o UVWMap1.gizmo.position = [1,1,1]
                                      addmodifier o UVWMap2
                                      classOf o UVWMap2.gizmo.position = [.3,-.8,0.7]
                                      addmodifier o UVWMap3
                                      classOf o  UVWMap3.gizmo.position = [-0.86,2,-0.96]
                              
                                  )
                              Code:
                              -- Error occurred in o loop; filename: D:\Graphics\Install Software\3Ds Max Plugins\Scripts\Important\My\; position: 748; line: 10
                              --  Frame:
                              --   UVWMap1: Uvwmap:UVW_Map1
                              --   o: $Teapot001
                              --   UVWMap2: Uvwmap:UVW_Map2
                              --   UVWMap3: Uvwmap:UVW_Map3
                              -- No ""="" function for (Global:classOf Local:o (prop position* (prop gizmo Local:UVWMap1)))
                              I also tried this

                              Code:
                              for o in getCurrentSelection() where (isKindOf o GeometryClass) do -- Now we're doing a simple check to make sure we're applying it to just geometry in the selection
                                  (
                                      UVWMap1 = UVWMap name:"UVW_Map1" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:1    -- Created 3 variables to store our modifiers
                                      UVWMap2 = UVWMap name:"UVW_Map2" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:2    -- So it's easier to refer back to them
                                      UVWMap3 = UVWMap name:"UVW_Map3" maptype:4 length:0.8 width:0.8 height:0.8 mapChannel:3
                              
                              
                                      -- Add the modifiers, and change the gizmo positions (via the variables we stored it in)
                                      addmodifier o UVWMap1    
                              		UVWMap.UVW_Map1.gizmo.position = [1,1,1]
                                      addmodifier o UVWMap2
                                      UVWMap.UVW_Map2.gizmo.position = [.3,-.8,0.7]
                                      addmodifier o UVWMap3
                                      UVWMap.UVW_Map3.gizmo.position = [-0.86,2,-0.96]
                              
                                  )
                              And bunch other settings that didnt work , Hands down off to google maybe I'll dig something out hehe
                              CGI - Freelancer - Available for work

                              www.dariuszmakowski.com - come and look

                              Comment

                              Working...
                              X