Home Technical Talk

MAXScript Query

Hi guys,

okay, I haven't done any MAXScripting at all but now I'm in need of some desperate coding (I'm a Max noob in general)!!

What I need is a little script that will assign all selected objects a unique object ID (starting at 00 and an increment would work fine).

Anyone have any ideas where I should start with this?

I think eventually I would like it to give the id's and then create and prefill the exact amount of VRay Multimatte elements for the scene.

Any help would be greatly appreciated.

Thanks in advance.

C

Replies

  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    do you have any programming knowledge? have you done the learning maxscript tutorials included with max?

    Im confused whether this is a genuine 'please help me learn' thread or a 'please post the finished script'

    off the top of my head this is what you need.

    selectionCount = selection.count -- get how many objects we have selected.
    for i = 1 to selectionCount do  -- step from 1 to the number of selected objects
    (
     currentObject = selection[i] --get the contents of the list at i. eg if i =4 then we are getting the 4th selected object
     currentObject.gbufferchannel = i -- set the objects gbufferChannel/Object ID to a new number. we can use I for this
    )
    
  • monster
    Offline / Send Message
    monster polycounter
    I used the MacroRecorder to find the gbufferchannel property. Then I just stuck it inside a loop on the current selection.
    for i = 1 to selection.count do
    (
    	selection[i].gbufferchannel = i
    )
    
  • mLichy
    hm... I need to look into gbuffer stuff... :)
  • javashrine
    r_fletch_r wrote: »
    do you have any programming knowledge? have you done the learning maxscript tutorials included with max?

    Im confused whether this is a genuine 'please help me learn' thread or a 'please post the finished script'

    off the top of my head this is what you need.

    selectionCount = selection.count -- get how many objects we have selected.
    for i = 1 to selectionCount do  -- step from 1 to the number of selected objects
    (
     currentObject = selection[i] --get the contents of the list at i. eg if i =4 then we are getting the 4th selected object
     currentObject.gbufferchannel = i -- set the objects gbufferChannel/Object ID to a new number. we can use I for this
    )
    


    Hey Fletch, I didn't mean to be so rude, so I'll come clean! I have a little programming knowledge, but it's been years since I've done anything, and even then I wasn't to good at it. And yes, it was basically can someone write this for me. Shame shame, I know!

    Max isn't my software, I work in post with Nuke. What I'm trying to do is set up a workflow that will make things ten times easier for me. Using the MME for this is something I've worked with before and it's a Godsend. When I need masks, they are there, animated and all. It saves so much time in post you wouldn't believe. The thing is, my two 3D guys don't care for such things (and aren't that great at scripting either) so I'm the one that has to do all the legwork (since it's for my benefit they say, the cheeky feckers!).

    Anyway, I got the ID setter working, it took me ages to find the gbufferchannel. That's what was killing me.

    So anyway, I'm going to come straight out here and ask for part two (or some pointers) of this little workflow that I'd need...

    What I would like would be that after the ID's are set the script creates as many VRay MultiMatteElement's as are needed and prefills them with all the ID's to create the mattes that will be included in the EXR's.

    Again, sorry if I'm being rude, but I really don't know where to start on this, like I said, I don't use Max. (Plus, to win some brownie points, I'd highly recommend that you suggest this workflow to your inhouse compositors, they'd love you for it!)

    Any help would be greatly appreciated.

    Thanks again guys.

    C
  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    You weren't rude, just a little ambiguous. I was being grumpy anyway :D. I dont mind helping folks out i just wanted to know if i was wasting my time explaining stuff

    Im afraid i dont have Vray, but it shouldnt be to hard to get the information you need.
    90% of script commmands in max can be really easily found simply using the listener.
    in max press f11 of go to "maxscript->maxscript listener"

    in the listener window there is the 'macro recorder' menu. click it and make sure its enabled. now when you do something the equivilent script command will be output in the pink area of the window.

    if you create the element manually you should see its name in the listener. or else it should be in the Vray reference.

    out of interest what are you using this for? per object masks or something? if so this does the job, it collects the objects. gives them obj ids, adds a matte element for each object and names it after the objects scene name
    manager = maxOps.GetCurRenderElementMgr() 
    
    for i = 1 to selection.count do
    (
    	selection[i].gbufferchannel = i
    	element = MatteRenderElement()
    	element.elementName = (selection[i].name + "_matte")
    	element.gbufIDOn = true
    	element.gbufID = i
    	element.filterOn = true
    	manager.AddRenderElement element
    )
    
  • javashrine
    Ah no problem, but I just really have the time to start learning stuff, I've enough on my plate at the minute.

    The macro recorder sounds like it just might work, even to get the basic set up, ie, to show me how to create the MME's with a script, but I still might need some help elobrating on the script!

    - What it does is create an RGB pass in the EXR file with the name MultiMatteElement and assigns one object ID to one colour.

    - You can create as many MME's as you need for the objects, ie, 6 objects would require two MME's.

    - You can custom name and number the MME's too, so you would know that object 5 would be in MME_02 Green channel and can thus (as I use Nuke it would be the shuffle node to pull out the green channel for MME_02, a simple operation) create a perfect matte from it, completely animated for post work. It's a savage little tool.

    Anyway, thanks for helping a fellow out ;) I'm sure I'll be back in order to get this working the way I want, ha, or just working even at a basic level.

    Go raith maith agat (sorry, can't remember where the fada's go, lol)
  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    You welcome. check out the code i added to the above post. it uses standard mattes but it might get you out of a scrape.
  • javashrine
    Okay, I'll check out the code above and see what it does.

    The recorder thingy didn't work when I changed options in the render settings, it just showed how to open it and that was all :(

    Again, muchos gracias for the help.
  • javashrine
    That little script is cool, so I'm trying to customise it to suit my needs (if ye don't mind?).

    So by switching out the MatteRenderElement for MultiMatteElement I can get the MME created. Perfect, but now is where the real fun starts... :poly121:

    Okay, I see how you are turning on the gbufID but the thing with the MME is that it has three, one each for RGB.

    gbufIDOn doesn't work, it doesn't exist in the MME so I need to find out what these are called. The VRay help page is not the best, if anyone knows off the bat then that's cool, otherwise I'll keep looking then I can turn them on.

    I'm sure there'll be similar names for the actual ID number, so hopefully that should be okay (once I find the names within the elements).

    Right, so here's another thing, it creates one MME per object, but I only want one per 3 objects. I need to increment the creaton of the MME's to every third gbufID.

    Thanks again folks for any help.
  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    these properties arent allways going to work for all elements. i checked the vray docs online and they dont say anything about maxscript interfaces to render elements. im sure they are there but they arent documented.

    without being able to see how to interface with the elements i cant really help.
  • javashrine
    Okay I found the properties here

    http://www.cgplusplus.com/online-reference/vray-properties/

    And have created this...
    manager = maxOps.GetCurRenderElementMgr()
    
    for I = 1 to selection.count do
    
    (
    selection[i].gbufferchannel = i
    element = MultiMatteElement()
    element.elementName = ("MMRE_00") -- I'll want this to start at 00 and increment per MMRE instance --
    element.R_gbufIDOn = true
    element.R_gbufID = i
    element.G_gbufIDOn = true
    element.G_gbufID = i + 1
    element.B_gbufIDOn = true
     element.B_gbufID = i + 2
    element.MatID = false
    manager.AddRenderElement element
    )
    
    This will create one MME and fill it out 123 for RGB. But if I select more than one object (I'm using 3 in my test scene) it will create 3 MME's and fill out the RGB as 123, 234 and 345. I only want it to create one MME per 3 object selected and when there are more then it will start at 456, then 789 etc...

    If you know what I mean....:poly122:

    Okay BIG EDIT...




    okay, I think I know how to do it, but I just don't know the syntax...

    If I do something like this...
    manager = maxOps.GetCurRenderElementMgr()
    
    selectionCount = selection.count
    for I = 1 to selection.count do
    (
    currentObject = selection[i]
    currentObject.gbufferchannel = i
    )
    
    --  So this sets the GBuffer numbers.
    
    -- Then I'll need to do another loop here to create the MME's for every  fourth gbuffer ID, right?
    -- So it would be something like
    
    for gbufferchannel = 1 to gbufferchannel + 3 do
    
    (
    element = MultiMatteElement()
    element.elementName = ("MMRE_00") -- I'll want this to start at 00 and  increment per MMRE instance --
    element.R_gbufIDOn = true
    element.R_gbufID = i
    element.G_gbufIDOn = true
    element.G_gbufID = i + 1
    element.B_gbufIDOn = true
     element.B_gbufID = i + 2
    element.MatID = false
    manager.AddRenderElement element
    )
    
    I know this doesn't work. What I think I need to do is this - set a new vaiable for the gbuffer that will increment by three everytime the loop ends and keep going until it reaches the end of the selection.count.

    Something like
    MME.count = gbuffer
    gbuffer = gbuffer + 3
    
    And stick it in at the start of the MME creation loop??
  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    cross your fingers. it should work but without vray i have no means of testing it
    manager = maxOps.GetCurRenderElementMgr() 
    
    remainder = ((mod selection.count 3) as integer) -- the remainder of the count divisable by 3
    count = selection.count - remainder -- the count divisable by 3
    
    mmreCount = 1
    
    for i = 1 to count by 3 do
    (
    	
    	mmreCount = mmreCount + 1
    	
    	selection[i].gbufferchannel = i
    	selection[i+1].gbufferchannel = i+1
    	selection[i+2].gbufferchannel = i+2
    	
    	element = MultiMatteElement()
    	element.elementName = ("MMRE_" + mmreCount) -- I'll want this to start at 00 and increment per MMRE instance --
    	element.R_gbufIDOn = true
    	element.R_gbufID = i
    	element.G_gbufIDOn = true
    	element.G_gbufID = i + 1
    	element.B_gbufIDOn = true
    	element.B_gbufID = i + 2
    	element.MatID = false
    	manager.AddRenderElement element
    )
    
    
    --sort out the remaining MMRE entry
    case remainder of
    (
    	1:
    	(
    		selection[count + 1].gbufferchannel = count + 1
    		
    		element = MultiMatteElement()
    		element.elementName = ("MMRE_" + mmreCount)
    		element.R_gbufIDOn = true
    		element.R_gbufID = count+1
    		element.MatID = false
    		manager.AddRenderElement element
    		
    	)
    	2:
    	(
    		selection[count + 1].gbufferchannel = count + 1
    		selection[count + 2].gbufferchannel = count + 2
    		
    		element = MultiMatteElement()
    		element.elementName = ("MMRE_" + mmreCount)
    		element.R_gbufIDOn = true
    		element.R_gbufID = count+1
    		element.G_gbufIDOn = true
    		element.G_gbufID = count+2
    		
    		element.MatID = false
    		manager.AddRenderElement element
    		
    	)
    
    )
    
  • javashrine
    You sir, are a mutha uckin' legend!!!

    The only thing that throws up an error is the name
    element.elementName = ("MMRE_" + mmreCount)
    

    But when I remove the + mmreCount it works perfectly!
  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    replace "+ mmreCount" with "+(mmreCount as string)"
    sometime somewhere you shall buy me a beer :)
  • javashrine
    Ha, but wait...

    I need the name to increment, otherwise the EXR only contains the last MME created...

    As for that beer, I'm flying home to Ireland on Wednesday to play at this

    http://www.bluesonthebay.co.uk/index.html

    so if you're about I'll get you a pint! But only if you can figure out the naming problem ;)
  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    thats what mmreCount does if you make that little change i mentioned above it should work

    unfortunately that gig on on the other side of country, thanks for the offer though :)
  • javashrine
    It's okay, I just stuck in as string after the + mmreCount and it works fine for the first duplicate, but not for the second...
  • r_fletch_r
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    post what the listener is saying please

    did you keep the bracketing?

    it should be +(mmreCount as string)

    other wise it will try and combined a string and an integer which it wont like
  • javashrine
    Sorry, yesterday was a bank holiday here, so here goes.

    Okay, the Listener is not giving me any errors and it says...

    2
    3
    1
    Ok
    True
    Ok

    I thought it might have been something else as I added a bit at the start to select VRay as the renderer and also added a bit at the end to add other elements, but even when I strip the script down it doesn't increment the last MME when there are not 3 objects in it.

    Now that I am this far with the script, I really want to develop it so that it's a complete one click VRay EXR render setup (hence already adding the rest of the elements) so I'll probably (actually, there's no probably about it, I will!!) need lots more help...
Sign In or Register to comment.