Home Technical Talk

Specify Dimensions In 3DSmax

polycounter lvl 11
Offline / Send Message
jocose polycounter lvl 11
Hey everyone I am looking for a quick way to take an existing object and specify its dimensions. For example if I have a box of a random size, I would like to select it, open some sort of menu, and type of 5x5x5 to make it a 5 unit by 5 unit x 5 unit box.

What's the best way to go about doing somthing like that?

Replies

  • felipefrango
    Options
    Offline / Send Message
    felipefrango polycounter lvl 9
    I have nothing to contribute so I'm gonna follow this cause it's a problem Ive faced many times before.
  • glynnsmith
    Options
    Offline / Send Message
    glynnsmith polycounter lvl 17
    I use an FFD modifier for this kind of thing.

    Apply it to your mesh and think of it like the Photoshop transform box :)
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    that should be pretty straight forward to script. Im taking a look at it now. Like Glynn says FFD works well. you could snap it to the grid aswell.
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Ok, Try this out. It should let you dynamically change the size of your selections bounding box by entering values into the spinners. Give it a whirl and report back with bugs/suggestions :)

    Save script in startup folder to make it start with max. (not essential)
    Customize UI
    Toolbars
    rt Tools
    Drag onto UI.
    http://www.robertfletcher.org/public_files/Scripts/rt_redim.ms

    updated: Added Preserve Proportions checkbox, made Undoable
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    I APPROVE! Thanks so much r_fletch_r. Works great. Would it be possible to add a feature to snap the dimension to the the closet grid point so that the bounds of the object are on grid?



    Would also be neat if it allowed you to enter dimensions other than the current unit scale (so I could enter in inches and it would automatically convert it).

    Right now it just works on the last item in your selection, might be nice if it worked on all selected objects and treated them as a group.

    Another nice feature would be to transfer the dimension of one object to another some how, or save the dimensions so you could use them later.
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    jocose wrote: »
    I APPROVE! Thanks so much r_fletch_r. Works great. Would it be possible to add a feature to snap the dimension to the the closet grid point so that the bounds of the object are on grid?
    Shouldnt be a problem. it may squish the mesh a little though.
    Would also be neat if it allowed you to enter dimensions other than the current unit scale (so I could enter in inches and it would automatically convert it).
    Shouldnt be difficult. Max handles all this internally. I dont know why it doesnt work allready actually, its probably because im using spinners. Most input fields in max support unit conversion. Eg. your working in CM and type in 6' (6 foot) into a field it will convert it on the fly to 182.88cm
    Right now it just works on the last item in your selection, might be nice if it worked on all selected objects and treated them as a group.
    Be specific on the exact behavior your looking for. Working on a group of objects isnt a problem. Scaling as a group may be trickier. It should be doable to apply a scale factor to the whole selection and snap to grid dimensions

    Another nice feature would be to transfer the dimension of one object to another some how, or save the dimensions so you could use them later.
    not a problem.

    Now i just need to get time to do it all :)
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    jocose
    I really would like to encourage you and other that are interested to have a look at the script(s) that are posted in this thread. Read them at least once and you will notice its not a impossible thing to understand.
    Once you get dirty yourself its all about googling for reference snippets or asking around here but it will give you such a different picture of what is possible workflow wise. Whenever something bugs me in Max or a work flow I usually end up writing a small script that enables me to do tedious tasks in just matter of clicks.
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Never a wiser word. the math behind this is extremely simple.
    Plus it gets more creative folks writing tools and understanding what makes things tick.

    Update wise, I've added a function to resize an object to the nearest whole grid units. and also to position it at the nearest grid position. basically you can take any object and conform it to the grid in 2 clicks. I haven't effected the objects Pivot. Could you guys give it a go and make a suggestion on how you would like the pivot to be placed.

    The conform and position buttons work across your entire selection.

    http://www.robertfletcher.org/public_files/Scripts/rt_redim.ms
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    It's not that I don't understand the math, I can write this stuff up in MEL pretty easily. I just don't know the syntax, and that takes time to learn.

    I wrote a script this morning that snaps an object to the nearest grid point and it took me quite awhile to do because I kept getting a syntax error that turned out to be a single character.

    Right now i'm trying to just learn how to use 3dsmax, but I assure you I'm also dabbling in script along side working on my project. It just takes time.

    So I wont turn down an offer if someone awesome like r_fletch_r drops by :)

    Belive me I'll be looking at the script and using it as an example for others. I'm already modifying little bits of it to suit my needs and learning a ton in the process.

    That said, I completely agree with you, its best to use these generosity scripts as a foundation to kick start your own scripting education and not as a crutch.

    @r_fletch_r

    I used really poor wording when talking about modifying the selection as a group.

    Features:

    Specifically, I would just like it to loop through each object in the array and make each one the specified dimensions.


    It would also be really useful if this tool could get the distance between two selected polygons and then align a pre-specified object to the center of those polygons and scale it (either uniformly or along a single axis) so that the top and bottom, left and right, front or back, of the bounds of that object are flush with the two polygons.

    An example of using this feature would be making a pillar and then specifying it as as the source mesh. Then selecting the "floor" and "roof" of a room. If the tool is run with this input it would then move the pillar to the center of the floor and roof polygons and re-size it so it fit perfectly in between them.

    It might also be useful if there was an option to have it make instances of the objects instead of just moving them. So it would leave the original pillar in place and instead create an instance of the pillar and move/re-size it.

    Just a thought, might be a way to implement that in a more open ended/useful way.


    Bugs:


    Conform to grid will make the object dimension 0 if its size is half a grid unit smaller than the current grid size. So if I have a box that 254 244 254 and my grid size is 512 that box will be resized to zero. When the box is esactly have the current gridsize I get odd results where one dimension sometimes goes up and another sometimes goes to 0.


    Hitting the "position on grid" button on an object that is off grid results in some odd behavior. If I hit the button multiple times the object will keeping going back and forth between one position and another (neither of which are actually on grid).
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    So if i add a copy and paste button for absolute dimensions that worked on the whole selection on a node by node basis this would work?

    If you make a change that works well post it! :) Might aswell make this a usefull tool
  • MattLichy
    Options
    Offline / Send Message
    Cool script :D

    I broke it though, hehe. But it might not matter for what most ppl would use it for.

    I rotated the object while resizing it, with the xform on, and it got all jacked. Then I rotated it back flat, and it was somewhat working as far as conforming to the grid in x,y, but z was broke. Then all of a sudden it reformed again, but the spinner values went to 9999.999.

    I know from experience that doing local to world space Rotation math / vice versa can be a pain in the ass though.... : \ I can't seem to wrap my head around it yet. Some people said it took them years.
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    gs = getGridSpacing()
        for obj in selection  do
    (
    pivBackup = $.pivot
    for o in selection do o.pivot = o.center
    pPos = obj.pivot
    
    for i = 1 to 3 do
    pPos[i] = floor(pPos[i] / gs + 0.5) * gs
    obj.position = pPos
    for o in selection do o.pivot = pivBackup
    
    )
    
    I modified a bit of code I found on scriptspot so that it takes any object, moves its pivot to its center, centers the object to a grid point, and then restores the pivot. I don't know if its any more or less useful than what you had written.

    Lol, that's just the only customization I have made so far, just playing around. I am looking into writing a few more things. Just playing around. Kudos to MattLichy for helping me with that.
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Mattlichy: I think i can fix that without getting into too much math. As it is rotation is mucking up my super simple dimension calculations. using the distance formula should correct the issue... I hope :D

    Update.
    *You can type any measurement into the fields now and it will convert them to generic units. so typing 1m, 20cm, 6'12" and so on will all work.
    *Setting the size,conforming and positioning work across the entire selection
    *Zero scale bug fixed, if the closest grid point is 0 then the grid width is used instead.
    *Copy and paste added. copy takes dimensions from 1st object in selection. paste applies to entire selection on a per node basis
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    I tried adding a print out that displays the current grid size but right now its updating every tick. It would be nice if it only updated when the grid sized changed but I don't know how to detect that:

    The changes I made start on line 117 (of the version you posted prior to you update)
    label lbl_nodeName "select a node"    
        label lbl_cGridSize 
        spinner spn_width "width" range:[0,10000,1] enabled:false
        spinner spn_depth "depth" range:[0,10000,1] enabled:false
        spinner spn_height "height" range:[0,10000,1] enabled:false
        checkbox chk_preserve "preserve proportions" checked:true
        
        button btn_gridConform "Conform to Grid" enabled:false
        button btn_moveToGrid "Position on Grid" enabled:false
            
        timer  tmr_check_sel interval:.01 active:true
        
        on tmr_check_sel tick do
        (
                    local gridSize = getGridSpacing() as string
                    lbl_cGridSize.text = "GridSize: "+gridSize
            
    
    By the way, where is your update? I tried re-downloading the file and its the same?
  • r_fletch_r
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    Okay great, I had a chance to test it out.

    FEATURE: I REALLY liked having the spinners and being able to drag the values around. If there were some way to have those back it would be really nice.

    BUG: If I enter "12ft" it gives me a runtime error and the entire thing stops working.

    BUG: If I enter 12cm, it works, but the if I try to conform it to the grid its off by a decimal amount and then I have to hit "conform to grid" again to get whole number values.


    If you have any idea about a good way to to have the current grid size displayed and updated in real time let me know. Even if you don't want to include it in the final script I would really like to have it on my end so I can see what grid i'm working on.

    Thanks so much for all your help so far, this thing is really shaping up nicely :)
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    12ft = 12' in max. ill sort it out so invalid numbers dont mess it up.
    I removed the spinners so generic input could happen. Might be able to do both.

    Updating the the Grid display per tick isnt going to add any major overhead.
  • MattLichy
    Options
    Offline / Send Message
    I broke it again... hehe..

    I typed in 00 into the width. Maybe don't allow for ppl to type that in.

    Also, if I sit and click conform to grid and position back and forth, AFTER the object has been rotated, the object hops around the grid, and starts moving further and further away. I think partially because the pivot gets separated from the mesh?

    Spinners next to the width/depth/height editText boxes would be helpful :)
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    Updating the the Grid display per tick isnt going to add any major overhead.

    Ah, okay, it just seamed like it might be bad. The UI flickers a little, but its not big deal. I will just leave it as is then. Thanks :)
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Cheers for the bug reports guys. Be aware: Not all functions are undo-able yet, the spinners are an example of this, Obviously you dont want a new undo event for each increment you move the spinner so they need a special case. If you want to undo just delete the xform modifier in the objects stack. I have a pretty solid idea of how i can get the undo to work with the spinners. its not perfect yet though.

    Changes:
    *Rewrote Entire UI/ resizing function, much cleaner/modular now, more error checking, no UI flicker.

    *Local rotation should no longer cause problems neither should scale.
    *Everything works on entire selection.
    about_rt_dim.png
  • MattLichy
    Options
    Offline / Send Message
    For the spinner undo, couldn't u just do onEntered? Or would that only work when you type into the box? I forget..
  • MattLichy
    Options
    Offline / Send Message
    sweet. I modified it quick for him, so that now , on tick, it gets the current grid size in a float and displays it. He was wanting to see the changes update when he used keyboard shortcuts to increase/decrease the grid spacing.

    thanks
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    If you do the scaling on buttonUp you dont get the interaction.
  • MattLichy
    Options
    Offline / Send Message
    I'm not sure how he had his shortcuts setup. But he did have an issue with viewport flickering, so I made an if statement that checks to see if the current value in the spinner is != the current grid spacing, and if not, it updates it.
  • kdm3d
    Options
    Offline / Send Message
    Matt.. quit breakin sh*t;)
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    Right now I have a script that I use to set the grid size to 32 64 128 ect...

    I could modify it to update your value in the window in addition to setting the grid size, but that's a less robust solution if I ever use another tool or anything else that modifies the grid size in the future. So I just figured it would be good to watch for a change an then update if one occurs.

    If you think its a bad idea though I could just have my gridsize script update your spinner value instead.
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Way ahead of you :)
    Updated
    *All undos should work, Im not too happy with the work around but it works. it could get slow if your working with hundreds of objects(at once).
    *Added Realtime update of gridsize as suggested by mattLichy also changed Gridsize spinner use floats rather than integers.

    Download

    So the big question, hows it working for you? I hope its looking usefull, i have no idea if ill ever use it myself :poly142:
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    Since you asked for contributions I added a button that snaps to the nearest grid point rather than the center of the grid unit and change the existing snap button name to make sense.

    http://dl.dropbox.com/u/2997790/rt_redim_3_jocoseMod.ms

    You can search for --jocose to see all my changes

    gridtoolupdate.jpg

    Oh, just saw your post. Its working great! I have been using it constantly while building my environment. Really good for blocking everything out, been helping to keep me organized with all the different sized assets I'm making.

    Thanks so much for all your help. Sorry I can't directly contribute more, trying to balance learning macscript with getting some art done :)
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    Thanks man :)
    Actually the snap i wrote snaps the lower corner of the object to the nearest grid point. Yours uses the pivot yeah?
    I figured a corner would make it easier to fit meshes together :)

    I was planning to expand upon this and let the user pick a corner to snap or the pivot point. so basically a 5 button grid 1 for each corner and the pivot
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    Yeah what you just described sounds very useful. I don't work any one particular way so the more options I have the better. Your method of using the corner is indeed very useful, but sometimes I prefer to use the center.

    If you do end up implementing the grid of buttons that would be better :)
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    Oh BTW, the other reason that I used the pivot is because your method of getting the corner seamed to have some sort of problem.

    I have noticed several times that the position values given for an object are not perfectly on grid when I use your button, and if I use the button several times on some assets they jump around each time I use the tool.

    You should be able to re-create this by making a box and then trying to run the tool on it, and press it over and over again.

    Basically when I put something on grid I expect that it will be using whole numbers for its position provided its pivot is at its center.
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    I'm curious, what would be the best way to go about getting this to work on selections in edit poly mode? I've been merging a lot of my objects lately and it gets rather tedious separating them to use this tool.
  • MattLichy
    Options
    Offline / Send Message
    Seperating the elements into new Objects? I have two tools in my toolbar, one will take your selection and make them all into 1 EditablePoly Mesh, and another Element to Object, will break the elements into their own named objects with their pivots centered.
  • jocose
    Options
    Offline / Send Message
    jocose polycounter lvl 11
    I was talking about effecting the geometry directly without having to make it a separate mesh.
  • r_fletch_r
    Options
    Offline / Send Message
    r_fletch_r polycounter lvl 9
    It should be possible, If a check was added when getting the bounding box to look at subobject selections and put xform mods on them. it'd be messy though once you start doing it to multiple objects. it may also be possible to do it with a tranformation matrix so you dont have to use a xform modifier at all.

    Doing it with a TM and a lot of verts would be pretty slow though.

    Im getting kind of addicted to transformation Matrixs. They seem to make so many things easier
Sign In or Register to comment.