Home Coding, Scripting, Shaders

[Maxscript] How can I change the vertex color automatically?

Kyle_butler
polycounter lvl 11
Offline / Send Message
Kyle_butler polycounter lvl 11
Hi Guys!

I don't know how to script. Everything I've done so far is relying upon Maxscript listener.
I'm trying to automatically change vertex colors on the selected mesh ( any object which I've applied the Edit mesh modifier).

However, when i try to select the Vertex color on the Edit Vertex Colors tab, nothing shows up on the MaxScript Listener (no idea why...)






I tried to look up in the Maxscript online help (https://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_5702AD16_5D90_4B74_A7E7_F49A8B6903C0_htm) but I don't what to do with the line the give me ( setVertColor <mesh> <CPVvert_index_integer> <color>)


Here is my current "script" (I'm aware it is far from a proper script)

select $geometry in Scene
modPanel.addModToSelection (Edit_Mesh ()) ui:on
maxOps.CollapseNode $ off
subobjectLevel = 1
actionMan.executeAction 0 "40021"  -- Selection: Select All
setVertColor <mesh> <CPVvert_index_integer> <black>


Best Regards and Thanks in advance!


Replies

  • monster
    Options
    Offline / Send Message
    monster polycounter
    What version of 3ds Max are you using? It's super easy to make an MCG modifier to let you pick a vertex color for the whole mesh.


  • Kyle_butler
    Options
    Offline / Send Message
    Kyle_butler polycounter lvl 11
    Hi, @Monster! Thanks for your kind input! However I really need to automate this... 

    I'm using 2014 at home and 2016 at office. 
  • Klunk
    Options
    Offline / Send Message
    Klunk ngon master
    (&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; fn tint_mesh mobj col =<br>&nbsp;&nbsp;&nbsp; (<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; nverts = getNumVerts mobj;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setNumCPVVerts mobj nverts;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; buildVCFaces mobj;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for v = 1 to nverts do setVertColor mobj v col;<br>&nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; for obj in objects where obj.isSelected and classof obj == Editable_mesh&nbsp; do tint_mesh obj blue;<br>)<br>
    this will tint selected editable meshes blue
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Klunk beat me to a solution. :smile:

    I like to use modifiers, and since VC are just another mapping channel, you can use UV modifiers to edit them.

    (
        newColor = [1.0,0.0,0.0]
        uv =  uvwmap length:0.0 width:0.0 channel:1 utile:newColor.x vtile:newColor.y wtile:newColor.z
        addModifier selection uv
    )

  • Kyle_butler
    Options
    Offline / Send Message
    Kyle_butler polycounter lvl 11
    Hi, @Klunk and @Monster
    I'm sorry for the late response. I believe we are in different time zones.

    Both scripts work like a charm. Thank you very much for putting your time and effort into my question. They are also easy to edit to other colors as well, so, win win =)

    Hope I can do something like this eventually, Thank you again! 
Sign In or Register to comment.