Home Technical Talk

New Editable Poly Modeling Script for Max

FatAssasin
polycounter lvl 18
Offline / Send Message
FatAssasin polycounter lvl 18
This script acts just like the edge Connect button on an editable poly object, but it will also raise of lower the new vert to keep the overall curvature of the object. So if you connected the edges down the length of a cylinder with the normal connect button, you end up with a new edge loop but the cylinder now has a flat side where the new edges and verts were added. This will keep the cylinder round when connecting edge rings. I hope that makes sense.

I wrote this recently and have been using it in my own modeling. It seems to work pretty good and saves a bunch of time, so I though I'd share. It only works on the base Editable Poly rollout, not the Edit Poly modifier. But you can have other modifiers on top, it doesn't need to be collapsed. I've only tested it with Max 7 and 8, but might possibly work with older versions.

If you don't know how to install and use a macroScript, let me know and I post some instructions.

<font class="small">Code:</font><hr /><pre>/*

Haywood Tools
Connect Edges Rounded
v0.01
Created: 06/05
By: James Haywood

Description:
Same as using the Connect tool on an edge Ring, but will also move the newly added verts
out along their local Z axis in order to keep the overall curvature of the object.

How to use:
Select a ring of edges and run the script. You can also select only one edge and it will
be expanded to a ring automatically.

History:
v1.00 - Ready for prime time.

*/

macroScript connectEdgesRounded
category:"HaywoodTools"
toolTip:"Connect Edges Rounded"
buttonText:"connectEdgesRounded"
(
-- get the vertex normal by averaging the surrounding face normals
fn getVertexNormal obj theVert = (
faceArr = polyop.getFacesUsingVert obj theVert as array
vertNormal = polyop.getFaceNormal obj faceArr[1]
for i = 2 to faceArr.count do (
vertNormal += polyop.getFaceNormal obj faceArr
)
return (normalize vertNormal)
)

local polyMod = modPanel.getCurrentObject()

if classOf polyMod == editable_poly and subObjectLevel == 2 then (
theEdge = polyop.getEdgeSelection polyMod
if theEdge.numberset == 1 then (
polyMod.editablePoly.selectEdgeRing()
)
-- store the edge ring as an array
edgeArr = polyop.getEdgeSelection polyMod as array
-- get the verts connected to each edge and store in an array
-- the array goes like this:
-- edgeVertArr[x][1]: the edge
-- edgeVertArr[x][2]: the two verts at the ends of the edge
edgeVertArr = for i in edgeArr collect (
vertArr = polyOp.getVertsUsingEdge polyMod i as array
#(i,vertArr)
)

newVertArr = #()
for i = 1 to edgeVertArr.count do (
-- add a new vert in the middle of the edge
newVert = polyMod.insertVertexInEdge edgeVertArr[1] .5
append newVertArr newVert
-- define the two end verts of the edge
v1 = edgeVertArr[2][1]
v2 = edgeVertArr[2][2]
-- get the position of the two end verts
vPos1 = polyop.getVert polymod v1
vPos2 = polyop.getVert polymod v2
-- get the normal vector for each vert (the new one and the two ends)
vDir1 = getVertexNormal polyMod v1
vDir2 = getVertexNormal polyMod v2
vDir3 = getVertexNormal polyMod newVert
-- get the angle between the two end verts
vAngle = acos(dot vDir1 vDir2)
-- get the distance between the new vert and one of the end verts
d1 = distance (polyop.getVert polyMod newVert) (polyop.getVert polyMod v1)
-- move the new vert out along it's Z axis
-- the amount is defined by the angle between the end verts, the distance between the new vert and one of the end verts,
-- and a number that seems to work good for what I want
angleCheck = (dot vdir1 (vPos1 - vPos2))
-- if angleCheck is negative, move the vert down along it's local Z axis
-- if angleCheck is positive, move the vert up along it's local Z axis
if angleCheck < 0 then polyop.moveVert polyMod newVert -(vdir3 * vAngle * d1 * .005)
if angleCheck > 0 then polyop.moveVert polyMod newVert (vdir3 * vAngle * d1 * .005)
)
-- connect the new verts to create a new edge loop
subObjectLevel = 1
polyOp.setVertSelection polyMod newVertArr
polyMod.buttonOp #connectVertices
subObjectLevel = 2
)
)
</pre><hr />

Replies

  • MoP
    Options
    Offline / Send Message
    MoP polycounter lvl 18
    Damn, it's like you read my mind or something.
    That's really awesome. I'm gonna try it out as soon as I get the chance, there's been quite a few times I've wanted something like this!

    Good work!
  • pior
    Options
    Offline / Send Message
    pior grand marshal polycounter
  • Silva_Spoon
    Options
    Offline / Send Message
    Silva_Spoon polycounter lvl 18
    Definatley useful! Thanx dude.
  • ScoobyDoofus
    Options
    Offline / Send Message
    ScoobyDoofus polycounter lvl 19
    Awesome! As others have said, this is something I've been thinking about for awhile!
  • Rakile
    Options
    Offline / Send Message
    Rakile polycounter lvl 18
    I'm fairly new to using scripts, so I'm not positive that I put it in correctly. I copied your code into a new Maxscript dialiouge window and saved it as Buldgeconnectscript.ms. I tried making a quick box, pulled out the edges to make it look round in the middle, but when I tried to run the script, it didn't seem to do anything. Maybe I need to quit Max and boot it up again?
  • FatAssasin
    Options
    Offline / Send Message
    FatAssasin polycounter lvl 18
    I'm glad you guys are finding this useful.

    Rakile: Macroscripts are run a bit differently than regular scripts. They're saved in the UI/Macroscripts folder and can be assigned to buttons and hotkeys instead of having to manually run it every time.

    How to save and run a macroscript

    1. In Max, click on the MAXScript menu and select "New Script".
    2. Copy and paste the above code into the window. Make sure to get everything between the lines.
    3. Save the file in the UI/Macroscripts folder under the Max root folder. The actual name of the file doesn't matter, but it needs to end with the .mcr extension. Usually, the author of the script will give you the .mcr file instead of just the code, but I was being lazy. smile.gif Although, you still need to put it in the right folder.
    4. Restart Max.
    5. Click on the Customize menu and select Customize UI Interface...
    6. To assign a hotkey to the script, search for the script in the list of commands. Either look for the name of the script in the list of All Commands (in this case, "Connect Edges Rounded"), or change the Category dropdown list to the category listed in the script itself (in this case, "HaywoodTools"), and find the script there. Then select it in the list and assign a hotkey to it.
    Follow the same basic procedures to create a button for the script or add it to your quad menu.

    If you get a macroscript and don't know what category it's in, open it up in Notepad and look for the "category:" parameter at the beginning of the file.

    To download other really useful scripts, go to scriptspot.com. There are a lot of handy tools out there that can make your life much easier, so they're worth checking out and getting the hang of installing them.
  • fritz
    Options
    Offline / Send Message
    fritz polycounter lvl 18
    what if you ran the script...but have no "haywood" tools in your keyboard tab? i can select a row of edges....the go to run script and it works. but i have no "haywood" tools in my keyboard tab. i'm kinda new to scripts as well
  • FatAssasin
    Options
    Offline / Send Message
    FatAssasin polycounter lvl 18
    Fritz: Check out the edited post above with more detailed installation instructions. It really shouldn't do anything (or appear to do anything, because it actually does do something) if you just run the script. If you run it without following the above instructions about saving the file manually, Max will save the file in the Macroscript folder anyway and add the script to the list of commands in the Customize UI window. Look for "HaywoodTools" in the Category drop down list, not in the Group list or list of actions.
  • Rakile
    Options
    Offline / Send Message
    Rakile polycounter lvl 18
    That is a nice script. That will help quite a bit with characters. Thanks for posting up, FA.
  • fritz
    Options
    Offline / Send Message
    fritz polycounter lvl 18
    OK FA. I'll give that a try. thanks so much for this...just like others have said: you've been reading minds on this one.

    cheers!!!!!!
  • Fuse
    Options
    Offline / Send Message
    Fuse polycounter lvl 18
    that is very helpful, i was looking around for something like that
Sign In or Register to comment.