--********************************************************************************************************************* -- Author : Kostadin Kotev -- miau_u@yahoo.com -- Created: 23-03-2011 -- Last Updated: 09-07-2011 -- Version: 1.01 -- Required: 3ds max 9 and up -- Discription: -- In Vertex subobject level: -- if 0 vertex is selected will turn on the Cut tool -- if 1 vertex is selected will turn on the Targed Weld -- if 2 or more vertices are selected will connect them -- In Edge subobject level -- if 0 edge is selected will turn on Create edge tool (create edge from vert to vert) -- if 1 edge is selected will insert vertex in the middle of the edge and turn on the Vertex subobject level -- if 2 or more edges is selected: if bridge operation is possible will bridge edges, otherwise will start miauu's Edge Cutter script -- In Border subobject level -- will Cap border -- In Polygon subobject level -- if 0 polygons is selected will start the Create tool -- if 1 or more polygon are selected will extrude them -- Feel free to change the default commands with supplied ones(the comment lines), but remember that in any subobject level -- in any count of selected verts/edges/faces only one command can be valid(uncomment). Any others must be commented or deleted. -- Usage: Assign a hotkey and start use it. -- To Do: -- add an Edit_Poly modifier support -- This version of Magic_Hotkey is for 3djav. :) -- Spin Edge script by Borislav "Bobo" Petrov --********************************************************************************************************************* -- MODIFY THIS AT YOUR OWN RISK macroScript HotKey_Magic category:"miauu" internalCategory:"miauu" Tooltip:"Magic HotKey" ButtonText:"Magic HotKey" ( if (selection.count == 1 and classOf selection[1].baseobject == Editable_Poly) then ( local curObj = $.baseobject case subobjectlevel of ( 1: -- Vertex subobject level ( local vertSel = (polyop.getVertSelection curObj) as array case vertSel.count of ( 0: -- no selected vertices - Start Cut tool ( macros.run "Editable Polygon Object" "EPoly_Cut" ) 1: -- if only one vertex is selected - Start Targed Weld ( macros.run "Editable Polygon Object" "EPoly_TargetWeld" -- to change what the script do when one vertex is selected comment line above -- and uncomment the desired operation -- macros.run "Editable Polygon Object" "EPoly_Break" -- macros.run "Editable Polygon Object" "EPoly_Chamfer" -- macros.run "Editable Polygon Object" "EPoly_Extrude" -- macros.run "Editable Polygon Object" "EPoly_Remove" ) default: -- if two or more vertices are selected - Connect them ( -- start Weld to last selected vertex script macros.run "miauu" "miauu_WeldToLastSelVert_v1" -- $.EditablePoly.ConnectVertices () -- macros.run "Editable Polygon Object" "EPoly_Collapse" ) ) ) 2: -- Edge subobject level ( local edgeSel = (polyop.getEdgeSelection curObj)as array case edgeSel.count of ( 0: -- no edges selected - create Edge from vert to vert ( macros.run "Editable Polygon Object" "EPoly_Create" ) 1: -- one edge selected - spin edge ( -- spin edge -- script by Borislav "Bobo" Petrov theObject = modPanel.getCurrentObject() --get the object from the modifier stack if classof theObject == Edit_Poly then theMode = 1 else theMode = 0 --see what class it is to decide which code to use --get the selected edges using the corresponding syntax for Epoly or Edit_Poly: if theMode == 0 then theEdges = ((polyOp.getEdgeSelection theObject ) as array) else theEdges = (theObject.GetSelection #Edge node:selection[1]) as array if theEdges.count == 1 then --check to make sure only one edge is selected ( theEdge = theEdges[1] --if only one, get its index! if theMode == 0 then --if EditablePoly is selected in Modifier panel, then ( theFaces = (polyOp.getFacesUsingEdge theObject theEdge) as array --grab the faces sharing the selected edge as array if theFaces.count == 2 then ( theEdgeVerts = (polyOp.getVertsUsingEdge theObject theEdge) --grab the vertices on both sides of the edge as bitArray thePolyEdges1 = (polyOp.getEdgesUsingFace theObject theFaces[1]) - #{theEdge} --grab all edges of the first face except the selected one thePolyEdges2 = (polyOp.getEdgesUsingFace theObject theFaces[2]) - #{theEdge} --grab all edges of the second face except the selected one --get all edges using the first vertex of the selected edge except the selected edge itself. --then take the intersection with the edges of the first polygon, convert to array and grab the first edge theNeighbourEdge1 = ((( (polyOp.getEdgesUsingVert theObject (theEdgeVerts as array)[1]) - #{theEdge} ) * thePolyEdges1 ) as array)[1] --repeat for the second polygon. --This gives us knowledge which edges are part of the one or the other polygon AND share a vertex with the selected edge --(which is the only one that belongs to both polygons) theNeighbourEdge2 = ((( (polyOp.getEdgesUsingVert theObject (theEdgeVerts as array)[2]) - #{theEdge} ) * thePolyEdges2 ) as array)[1] --Create an array of the first vertex of both edges collected above. --Then sort the array to keep the vertices in ascending order. newVerts = sort #( (((polyOp.getVertsUsingEdge theObject theNeighbourEdge1) - theEdgeVerts) as array)[1], (((polyOp.getVertsUsingEdge theObject theNeighbourEdge2) - theEdgeVerts) as array)[1] ) theObject.remove selLevel:#edge --remove the currently selected edge, turning both polygons into one. if keyboard.shiftPressed then --depending on the state of the SHIFT key when pressing the script's button, create edge in the one or the other direction theObject.createEdge newVerts[2] newVerts[1] select:true else theObject.createEdge newVerts[1] newVerts[2] select:true ) else --if the edge does not have two polygons, let the user know! pushPrompt "Cannot Spin an OPEN Edge!" ) else --if the object in Modifier Stack is Edit_Poly, work here instead... ( theFaces = #() --init. an array to collect the faces of the selected edge theFace1 = theObject.getEdgeFace theEdge 1 --grab the first one theFace2 = theObject.getEdgeFace theEdge 2 --and the second one if theFace1 > 0 do append theFaces theFace1 --if it is valid, add it to the array if theFace2 > 0 do append theFaces theFace2 --same with the second one if theFaces.count == 2 then --if two faces collected, continue... ( theEdgeVerts = #{ (theObject.getEdgeVertex theEdge 1), (theObject.getEdgeVertex theEdge 2) } --collect the two vertices of the selected edge --collect the edges of the first polygon except the selected one thePolyEdges1 = ((for i = 1 to (theObject.GetFaceDegree theFaces[1]) collect (theObject.getFaceEdge theFaces[1] i) ) as bitArray) - #{theEdge} --collect the edges of the second polygon except the selected one thePolyEdges2 = ((for i = 1 to (theObject.GetFaceDegree theFaces[2]) collect (theObject.getFaceEdge theFaces[2] i) ) as bitArray) - #{theEdge} --collect the edges that share the first vertex of the selected edge and are used by the first polygon, take the first one theNeighbourEdge1 = ((((( for i = 1 to (theObject.GetVertexEdgeCount (theEdgeVerts as array)[1]) collect theObject.getVertexEdge (theEdgeVerts as array)[1] i) as bitArray) - #{theEdge} ) * thePolyEdges1 ) as array)[1] --collect the edges that share the second vertex of the selected edge and are used by the second polygon, take the first one theNeighbourEdge2 = ((((( for i = 1 to (theObject.GetVertexEdgeCount (theEdgeVerts as array)[2]) collect theObject.getVertexEdge (theEdgeVerts as array)[2] i) as bitArray) - #{theEdge} ) * thePolyEdges2 ) as array)[1] --grab the vertices of the neighbour edge determined above, remove the vertices of the selected edge and take the remaining one newVert1 = ((#{theObject.getEdgeVertex theNeighbourEdge1 1, theObject.getEdgeVertex theNeighbourEdge1 2} - theEdgeVerts ) as array)[1] newVert2 = ((#{theObject.getEdgeVertex theNeighbourEdge2 1, theObject.getEdgeVertex theNeighbourEdge2 2} - theEdgeVerts ) as array)[1] --sort the two vertices in ascending order newVerts = sort #( newVert1, newVert2) --remove the selected edge to turn the two polys into one... theObject.ButtonOp #RemoveEdge --depending on the state of the SHIFT key, connect the vertices in descending or ascending order if keyboard.shiftPressed then theObject.CreateEdge newVerts[2] newVerts[1] node:selection[1] else theObject.CreateEdge newVerts[1] newVerts[2] node:selection[1] theObject.Commit() --commit the change to create two polys again. ) else --open edge is a no-no pushPrompt "Cannot Spin an OPEN Edge!" )--end Edit_Poly code )--end if one edge else --let the user know he did not select a single edge! pushPrompt "Select EXACTLY Only Edge to Spin!" -- divide edges -- $.EditablePoly.divideEdge edgeSel[1] 0.5 select:on -- subobjectLevel = 1 ) default: -- if two or more edges are selected - bridge or connect edges ( $.bridgeSelected = 1 -- will bridge only selected edges $.bridgeSegments = 1 -- change the value will change the number of Bridge Segments if ($.EditablePoly.Bridge () == false) do ( -- start miauu's Edge Cutter script createdialog miauuEdgeCutter width:402 height:104 style:#(#style_sysmenu, #style_titlebar) -- if Bridge operation can not be done - connect edges -- $.connectEdgeSegments = 1 -- change the value will chagne the default Connect Edge Segments value -- $.EditablePoly.ConnectEdges () ) -- to change what the script do when 2 or more edges are selected comment all 7 lines above -- (from $.bridgeSelected = 1 to ")" ) and uncomment the desired operation -- macros.run "Editable Polygon Object" "EPoly_Remove" -- remove selected edge/edges(and shared verts) -- macros.run "Editable Polygon Object" "EPoly_InsertVertex" -- macros.run "Editable Polygon Object" "EPoly_Extrude" -- macros.run "Editable Polygon Object" "EPoly_Chamfer" -- macros.run "Editable Polygon Object" "EPoly_Split" -- macros.run "Editable Polygon Object" "EPoly_ShapeFromEdges" -- macros.run "Editable Polygon Object" "EPoly_Collapse" ) ) ) 3: -- Border subobject level ( -- Cap macros.run "Editable Polygon Object" "EPoly_Cap" -- macros.run "Editable Polygon Object" "EPoly_Collapse" ) 4: -- Polygon subobject level ( local faceSel = (polyop.getFaceSelection $) as array case faceSel.count of ( 0: -- no face selected - start creating polygons ( macros.run "Editable Polygon Object" "EPoly_Create" ) default: -- one or more faces selected - extrude them ( -- macros.run "Editable Polygon Object" "EPoly_Extrude" -- to change Extrude command with Bevel, Outline, Inset or Flip -- uncomment desired command and comment "Extrude" command macros.run "Editable Polygon Object" "EPoly_Bevel" -- macros.run "Editable Polygon Object" "EPoly_Outline" -- macros.run "Editable Polygon Object" "EPoly_Inset" -- macros.run "Editable Polygon Object" "EPoly_Flip" -- macros.run "Editable Polygon Object" "EPoly_Detach" -- macros.run "Editable Polygon Object" "EPoly_Collapse" ) ) ) ) ) else messagebox "Select an Editable Poly object!" title:"Magic HotKey Error!" )