Tuesday, February 11, 2014

Maxscript stuff

One of my favorite tools to use while modeling in Max is bridge, it probably gets used more then any other tool with the exception of connect. So I thought I'd post the script I wrote for it.
What makes this script useful is that not only can it do standard bridges between edges, faces, and borders (in both Editable Poly and Edit_Poly modes), but it can also bridge two connected edges to form a triangle; something normal bridge can't do. Sure this could be done with the create tool but I find it much nicer to have as many functions on one hotkey as possible.

From quite a bit of use I can say the script is bug-free afaik, but if anyone ends up using it and has problems let me know.



macroScript BridgeReplace
category: "GregsScripts"
 (
 erStat = showEndResult
 showEndResult = false
 setCommandPanelTaskMode #modify    --Needed for the next command to work.
 curSelStack = modpanel.getCurrentObject()  --Gets the current modifier.
 
 if (superClassOf $ == GeometryClass) then
  modClass = classOf (modPanel.getCurrentObject())
  
  ------------------------------------------
  if (modClass == Editable_Poly) then
   (
   --NOTE: bridging border edges in edge mode tends to give more twisted results then in border mode.
   if ((subObjectLevel==2 or subObjectLevel==3) and ($.selectedEdges.count >= 2)) then
    (
    $.bridgeAdjacentAngle = 0
    Edgs= polyop.GetEdgeSelection $ as array

    EdgA=PolyOp.getEdgeVerts $ Edgs[1]
    EdgB=PolyOp.getEdgeVerts $ Edgs[2]

    tmperf=0
    if (EdgA[2]==EdgB[1] and Edgs.count==2) do ($.CreateFace #(EdgA[1], EdgA[2], EdgB[2]) ; tmperf=1)
    if (EdgB[2]==EdgA[1] and Edgs.count==2) do ($.CreateFace #(EdgB[1],EdgB[2],EdgA[2]) ; tmperf=1)
    
    if (tmperf==0) then ($.EditablePoly.Bridge ())
    )
   else if ((subObjectLevel == 4) and ($.selectedFaces.count >= 2)) then
    ($.EditablePoly.Bridge ())
   )
   
  ------------------------------------------
  if (modClass == Edit_Poly) then
   if ((subObjectLevel==2 or subObjectLevel==3) and ((((curSelStack.getSelection #Edge) as array).count) >= 2)) then
    (
    Edgs= ((curSelStack.getSelection #Edge) as array)

    EdgA=PolyOp.getEdgeVerts $ Edgs[1]
    EdgB=PolyOp.getEdgeVerts $ Edgs[2]

    tmperf=0
    --FlipFace is just to get around a weird selection bug with the EditPoly modifier.
    if ((EdgA[2]==EdgB[1]) and (Edgs.count==2)) then
     (
     curSelStack.CreateFace #(EdgA[1],EdgA[2],EdgB[2])
     curSelStack.ButtonOp #FlipFace
     curSelStack.ButtonOp #FlipFace
     tmperf=1
     )
    if ((EdgA[1]==EdgB[2]) and (Edgs.count==2)) then
     (
     curSelStack.CreateFace #(EdgB[1],EdgB[2],EdgA[2])
     curSelStack.ButtonOp #FlipFace
     curSelStack.ButtonOp #FlipFace
     tmperf=1
     )
    if ((EdgA[1]==EdgB[1]) and (Edgs.count==2)) then --This is an extra step for problem geometry just in the EditPoly modifier.
     (
     curSelStack.CreateFace #(EdgB[1],EdgB[2],EdgA[2])
     curSelStack.ButtonOp #FlipFace
     curSelStack.ButtonOp #FlipFace
     tmperf=1
     )
    
    if (tmperf==0) then (curSelStack.ButtonOp #BridgeEdge)
    )
   else if ((subObjectLevel==4) and (((($.Edit_Poly.getSelection #Face) as array).count) >= 2)) then
    (curSelStack.ButtonOp  #BridgePolygon)
  
 showEndResult = erStat;
 CompleteRedraw()
 )


No comments:

Post a Comment