Home Technical Talk

Baby's first maxscript

Okay, so when I worked in maya I would make myself little macro type mel scripts all the time for operations I found I needed to repeat often (ie. scale -1 on one axis, freeze transforms, invert normals).

I would do this by turning on the 'echo all commands' option and watching what was output, then changing this until it did what I needed (and often wrapping it in a "for i in `ls -sl`"). Max's version of echo all doesn't seem to echo much at all.

I want to take my selection (at object level), assign a certain material id, uvw map with a box at 100,100,100 dimensions, then collapse the stack.


Teach a man to fish, please.

Replies

  • swytch
    Options
    Offline / Send Message
    swytch polycounter lvl 8
    glib,

    I learned how to do this from the CGSociety "Share your Max Secrets" thread http://forums.cgsociety.org/showthread.php?f=6&t=160223 But I forget which of the 40 some pages it is on.[FONT=&quot]

    [/FONT]
    With the maxscript listener open (F11) and making sure macrorecorder > enable is on. Highlight the text and drag it into a toolbar e.g., Extras. Then you can create at the touch of a button, anything that has been recorded. For example:
    Open the maxscript listener (F11), the bits we want are in the pink area up top.
    Create a sphere and change some of the settings: hemisphere, slice, to-from.
    You'll then get the following :

    Sphere radius:150 smooth:on segs:44 chop:0 slice:off sliceFrom:0 sliceTo:0 mapCoords:on recenter:off pos:[0.578125,183.586,0] isSelected:on
    $.hemisphere = 0.25
    $.slice = on
    $.sliceFrom = 50
    $.sliceTo = -50

    Highlight that and drag it into a toolbar when you click the button, what you have recorded will be generated, always in the same spot though. If you right click the button > edit buttons appearance, you can give it a unique name. I saw this used with bones and adding multiple spring position controllers to them. Dragging text to make a button from the listener is good, dragging text from the Maxscript window is nice. Dragging text from your internet browser is awesome…
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    yup all you need is the maxscript listener and enable the macro recorder to listen to your commands (well most of them)

    noticed this little thing at the lower left corner of max?
    image003.jpg
    it is the maxscript listener but in a compact mode, for the real deal

    press [F11] or alternativly find it here:
    image004.jpg
    and this big version appears:
    image006.jpg

    the red part shows the recordings (if enabled in the MacroRecorder menu) and the lower white part traces results or lets you input code and evaluate it.

    my own usual workflow is that after pressing F11 for the listener record some possible use-able commands in the red part, select them and copy them to the clipboard.
    Then hit [Ctrl]+[N] (with the maxscript listener window active) to create a new script and paste the clipboard code into it.
    Within that window I then remove the script parts I don't need and perhaps change or research some things. Each time I want to test the code I then hit [ctrl]+[e] (which is the shortcut for evaluate code) to run the whole code. Alternatively you can select parts of your code and hit the [Enter] key that is on your numblock which will then only evaluate your selection.


    have any more questions drop them here
  • glib
    Options
    Offline / Send Message
    Got it figured out after much head-bashing:
    sel = getCurrentSelection()
    for obj in sel do (
    	convertTo obj Editable_Poly
    	addModifier obj (Uvwmap ())
    	obj.modifiers[#UVW_Mapping].maptype = 4
    	obj.modifiers[#UVW_Mapping].length = 100
    	obj.modifiers[#UVW_Mapping].width = 100
    	obj.modifiers[#UVW_Mapping].height = 100
    	maxOps.CollapseNode obj off
    	polyOp.setFaceSelection obj #all
    	obj.EditablePoly.setMaterialIndex 12 1
    )
    
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    I am not saying that its needed but you can a little bit simply or change your script like the following. Oh and i noticed that you script does not work well with multiple objects selected because it processes the UVW mapping with all objects selected whereas it should be only applied to the loop element, so I added "select o;" which will select the loop sub element.
    sel = getCurrentSelection();
    for o in sel do (
    	select o;--select only this object
    	convertTo o Editable_Poly;
    	addModifier o (Uvwmap ());
    
    	local uv = o.modifiers[#UVW_Mapping];
    	uv.maptype = 4;
    	uv.length = uv.width = uv.height = 100;
    	
    	maxOps.CollapseNode o true;--no warning
    	polyOp.setFaceSelection o #all;
    	o.EditablePoly.setMaterialIndex 12 1;
    )
    
  • Mark Dygert
    Options
    Offline / Send Message
    Glad you got it figured out, feels good doesn't it =)

    Also hitting F1 in the MaxScript Editor brings up the MaxScript help which is really useful and very different then the regular 3dsmax help.
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    yup and..

    [ctrl] + [d] clears the maxscript listener (you need focus on it)

    [ctrl] + rightclick on a rollout item gives you this:
    maxscriptctrlrightclick.gif

    as for rollouts (super easy to prototype GUI's)
    tr3d_30_maxscript7.gif
    go here and create 1st a new rollout then select the name of the rollout and go again in the menu to edit it.
    tr3d_30_maxscript8.gif
    In the visual maxscript editor (for editing rollouts) you can then let the tool generate the maxscript that is needed for displaying buttons, sliders and lots of other GUI stuff
Sign In or Register to comment.