Announcement

Collapse
No announcement yet.

Calculating ALL lightmeters

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

  • Calculating ALL lightmeters

    I tried to use this script that was on the Chaos Group Help website and tried to use it but would not work. It would still only calculate one lightmeter at a time when I have multiple lightmeters in my scene.

    To recalculate all VRayLightMeter helpers in the scene, you can use the following MaxScript function:


    fn calcAllVRayLightMeters = (
    local lightMeters=getClassInstances VRayLightMeter
    for lightMeter in lightMeters do (
    if lightMeter.active then lightMeter.calculate()
    )
    )



    Can someone verify this if this is written correctly or maybe I am using it wrong. Please help. This would speed up our work flow ten fold. We use the lightmeter often.

    Thank you.

  • #2
    Just need to call the function at the end:

    Code:
    fn calcAllVRayLightMeters = (
    local lightMeters=getClassInstances VRayLightMeter
    for lightMeter in lightMeters do (
    if lightMeter.active then lightMeter.calculate()
    )
    )
    
    --this bit was missing
    
    calcAllVRayLightMeters()

    Comment


    • #3
      I changed the end to what you had;

      macroScript calculateAllLightMeters
      category:"CalcAllVRayLightMeters"
      toolTip:"Calculate All LightMeters"
      (
      fn calcAllVRayLightMeters = (
      local lightMeters=getClassInstances VRayLightMeter
      for lightMeter in lightMeters do (
      if lightMeter.active then calcAllVRayLightMeters ()
      )
      )

      This still didn't work. I edited the Button Macro Script to change the code. Not sure if i might be installing incorrectly.

      Comment


      • #4
        No sorry you're misunderstanding the edit - in maxscript when you make a function, you first define a function by writing either fn or function, the name of the function (in this case calcAllVRayLightMeters) and then the code that follows between the opening and closing "(" and ")" brackets is what gets run when you actually call the function so as a better run through you have:

        First define a function so you can reuse it easily afterwards, in this case the original writer has called it "calcAllVRayLightMeters". After giving your function a name, you have an equals sign and a bracket telling maxscript what to do any time someone runs the function called "calcAllVRayLightMeters"

        Code:
         fn calcAllVRayLightMeters = (
        Next we have the guts of the code which line by line says get all the lightmeter objects in the scene, then for each lightmeter in the scene if the lightmeter is set to active, calculate it's values

        Code:
        local lightMeters=getClassInstances VRayLightMeter
        for lightMeter in lightMeters do
        (
        if lightMeter.active then calcAllVRayLightMeters ()
        )
        Last we have a closing bracket telling maxscript that we're at the end of the function

        Code:
        )
        So if we only have this in our code, we've defined a function but we haven't actually told maxscript to run it. Once you define a function you have to write another line to call it which in this case is just

        Code:
        calcAllVRayLightMeters()
        So your total code is

        Code:
        fn calcAllVRayLightMeters =  (
        local lightMeters=getClassInstances VRayLightMeter    
        for lightMeter in lightMeters do      (        
        if lightMeter.active then lightMeter.calculate()    
        )
        )  
        calcAllVRayLightMeters()

        Comment


        • #5
          Thank you so very much. Your breakdown was really helpful and I got the script to work. I made a macro button for my toolbar to run the script.
          One more question for you,

          Would I be able to modify this script to convert the LUX Luminance (European Units) results to Footcandle (American Units) results?
          The formula to convert is LUX divided by 10.764
          example: 1 LUX = 0.092903 or (1 / 10.764)

          I would like to be able to keep the Calculate All LightMeters with the conversion together as one script.

          Sorry to ask, but I am so new to scripting.

          Thank you

          Comment


          • #6
            No problem!

            I don't have a way to change the values that the lightmeter objects in the viewport display so the closest thing I can do is output values into the script listener at the bottom left of 3dsmax. If you right click on the white / pink bar and choose open listener window, you'll get a print out of values
            after you run the script.

            Code:
            fn calcAllVRayLightMeters =  (
            local lightMeters= for o in objects where classof o == VRayLightMeter collect o 
            for i = 1 to lightMeters.count do      
            (        
                if lightMeters[i].active then lightMeters[i].calculate()
                theLightValues = #()
                for val = 1 to lightMeters[i].total.count do
                (
                    append theLightValues (lightMeters[i].total[i]/10.764)
                )
            
                format "The light meter % has a value of %\n" (lightMeters[i].name as string) (theLightValues as string)
            )
            )
            
            calcAllVRayLightMeters()

            Comment


            • #7
              Thank you so much for your help. Your Script for converting works. I just need to figure out how to have it displayed in the viewport if at all possible. I'll have to experiment around.
              I have a lot to learn in the MaxScript world.

              Thanks

              Comment


              • #8
                Unfortunately that'd have to be done by modifying the code of the light meter object in c++ which is way above my level. There's a way to draw on the viewport with maxscript but I don't think there'd be a way to turn off the lux values from being displayed underneath and cluttering things up.

                Comment


                • #9
                  I just realized in your code to convert to Footcandles, that it only displays one point of the whole grid of point on the meter. Each point on the grid i a specific number (ie. point #1, point #2, point #3 ect.) and looks like it is only displaying point #1 and not all the points on the grid. I know that each grid can have a different number of points depending on how dense you want the lightmeter. I'm not sure how to fix that. I do thank you for what you have done. Much appreciated.

                  Comment


                  • #10
                    You're totally right, quick edit:

                    Code:
                    fn calcAllVRayLightMeters =  (
                    local lightMeters= for o in objects where classof o == VRayLightMeter collect o 
                    for i = 1 to lightMeters.count do      
                    (        
                        if lightMeters[i].active then lightMeters[i].calculate()
                        theLightValues = #()
                        for val = 1 to lightMeters[i].total.count do
                        (
                            append theLightValues (lightMeters[i].total[val]/10.764)
                        )
                    
                        format "The light meter % has a value of %\n" (lightMeters[i].name as string) (theLightValues as string)
                    )
                    )
                    
                    calcAllVRayLightMeters()

                    Comment


                    • #11
                      You're Good!!!!! Works great. So that made me think......to throw another monkey wrench in the mix. How about only displaying an average instead of displaying all the numbers? You don't have to do this if you don't want to but I am enjoying this. I've been neglecting my work here at my job today (which i do use the lightmeter on every project i work on) and reading up about Scripting. I know this will be a long process for me but a little everyday will get me somewhere eventually.

                      Comment


                      • #12
                        So on scripting, here's a great video series, annoyingly the playlist is in reverse order though so you'd be best off making your own custom playlist and reversing it back - https://www.youtube.com/watch?v=e4t9...28874&index=34 - there's another dvd on the same youtube channel called maxscript for the masses which is fantastic for having broad control over large scenes with lots of objects.

                        Here's another code tweak:

                        Code:
                        fn calcAllVRayLightMeters =  (
                        local lightMeters= for o in objects where classof o == VRayLightMeter collect o 
                        for i = 1 to lightMeters.count do      
                        (        
                            if lightMeters[i].active then lightMeters[i].calculate()
                            theLightValues = #()
                            theAverage = 0.0
                            for val = 1 to lightMeters[i].total.count do
                            (
                                append theLightValues (lightMeters[i].total[val]/10.764)
                                theAverage = theAverage + lightMeters[i].total[val]/10.764
                            )
                        
                            format "The light meter % has an average of % and values of %\n" (lightMeters[i].name as string) (theAverage/lightMeters[i].total.count) (theLightValues as string)
                        )
                        )
                        
                        calcAllVRayLightMeters()

                        Comment


                        • #13
                          Too good my friend!!! I hope one day I can do this. I model buildings (mainly church buildings) and use IES files to light up my scene and then use the light meter to calculate the amount of light that will be produced from our light fixtures that we design and manufacture. I will eventually like to
                          stream line my work flow using MaxScript. There are a lot of church buildings that have the same basic shapes and I would like to use script to quickly get the base shape.
                          Thank you for all your help and I will definitely watch these videos.

                          Comment


                          • #14
                            If I turn off the viewport text from the LightMeter parameters rollout, how could I overlay the numbers in the viewport like you mentioned a couple of post ago?

                            Comment


                            • #15
                              Let me chase that up, a really high end character rigger, Paul neale, has a lot of those overlays in his tools so I'll look there.

                              Comment

                              Working...
                              X