Home Technical Talk

3D max script help; global delete

polycounter lvl 11
Offline / Send Message
Yozora polycounter lvl 11
Hi can anyone help me with a script that can delete anything based on the selection level? Currently I've binded ctrl+backspace to one of my extra mouse buttons (because I cant bind it to another hotkey apparently without the use of a seperate hotkey program) and use the delete key for deleting everything else. But I'd like to combine both of these all into 1 button.

So in vertex/face/element level, it removes vertex/face/element
Edge level it removes edge AND vertices if the vertices are not supported by another edge (ctrl+backspace)
Object = delete object


I've found a script for doing the edge thing, but the problem is it only deletes edges and cant even be used to delete vertices like ctrl+backspace can


macroScript cleanRemoveEdge
category:"Yozora"
buttonText:"cleanRemoveEdge"
toolTip:"cleanRemoveEdge"
(
on isEnabled return selection.count == 1 and subObjectLevel == 2 and classof selection[1] == Editable_Poly
on execute do (
local obj=selection[1]
local theEdges=polyOp.getEdgeSelection obj
if theEdges.numberset!=0 do (
local theVerts=#()
for e in theEdges do ( join theVerts ((polyop.getVertsUsingEdge obj e) as array) )
local theVertsToRemove=theVerts as bitarray
for v in theVertsToRemove do ( deleteItem theVerts (findItem theVerts v) )
undo "cleanRemoveEdge" on (
obj.EditablePoly.Remove selLevel:#Edge
polyop.setVertSelection obj (theVerts as bitarray)
obj.EditablePoly.Remove selLevel:#Vertex
)
)
)
)

Replies

  • Yozora
    Offline / Send Message
    Yozora polycounter lvl 11
    alright using my extremely limited scripting knowledge (copy and pasting stuff from existing scripts and using the listener) I've created this;



    macroscript GlobalDelete
    category:"Yozora"
    buttonText:"Global Delete"
    toolTip:"Global Delete"
    (
    On Execute Do
    (
    if (classof($.baseobject) == editable_poly)
    then
    (

    if (subobjectLevel == 1) then
    (
    $.EditablePoly.Remove ()
    )
    if (subobjectlevel == 2) then
    (
    macros.run "Yozora" "cleanRemoveEdge"
    )

    else
    (
    max delete
    )
    )
    else
    (
    max delete
    )
    )
    )


    And it works, I feel all happy and stuff :p - "cleanRemoveEdge" is just the first script I pasted in the first post.

    The 2nd "else max delete" is there to delete non editable poly objects, its probably redundant and theres an easier way to do this without the
    "if (classof($.baseobject) == editable_poly)" bit at the start, but I dont know how.

    So far the only "problem" is that I cant delete a border edge because "cleanremoveedge" is like ctrl+backspace and doesnt delete edges on a border. How can I modify my script to allow deletion of these edges? Something like "if edge = on the border of the object then ( max delete)" but how do you type that properly?

    (when i say border I dont mean the border sub object level, I can delete them fine with my script - I'm talking about one of the edges in the border. Its unlikely I'd want to delete an edge like that anyway but still, might as well make my "global delete" really globally delete anything)




    Edit - After some further testing I found that the "cleanRemoveEdge" script doesnt cleanly remove the edges if one of the edges in a edge loop is already deleted. For example, make a box with 2 subdivisions on 1 axis, select ONE of the edges in the inside loop, delete it using cleanremoveedges and then select the remaining edge loop (3 edges) and delete that using the script, you'll find 2 left over vertices from where the "gap" in the loop was.
  • Yozora
    Offline / Send Message
    Yozora polycounter lvl 11
    thanks per, actually I decided not to include the function to delete a border edge because that really has never happened to me and cant see it ever being useful anyway so gonna keep the script shorter and cleaner by not including it :p
    If I ever wanted to delete the end of a polygonal plane strip I'd delete the face in face mode instead of the edge anyway.

    Edit; this is a perfect working version that has no problems:

    macroscript GlobalDelete
    category:"TP"
    buttonText:"Global Delete"
    toolTip:"Global Delete"
    (
    if (classOf (modpanel.getcurrentobject()) == Editable_Poly) then
    (
    if (subobjectLevel == 1) then
    (
    $.EditablePoly.Remove ()
    )
    if (subobjectlevel == 2) then
    (
    case (getSelectionLevel $) of
    (
    #Vertex: $.EditablePoly.Remove selLevel:#Vertex
    #Edge:
    (
    sel = #{}
    edgesel = polyOp.getEdgeSelection $
    vertsel = polyOp.getVertsUsingEdge $ edgesel
    $.EditablePoly.Remove selLevel:#Edge
    for i = 1 to vertsel.numberset do
    if ($.GetVertexEdgeCount (vertsel as array)) == 2 then sel = sel + #{(vertsel as array)}
    polyop.setVertSelection $ sel
    $.EditablePoly.Remove selLevel:#Vertex
    )
    #Face:
    (
    sel = #{}
    facesel = polyOp.getFaceSelection $
    edgesel = polyOp.getEdgesUsingFace $ facesel
    for i = 1 to edgesel.numberset do
    if (((polyOp.getEdgeFaces $ (edgesel as array)) as bitarray)*(facesel as bitarray)).numberset == 2 then sel= sel + #{(edgesel as array)}
    polyop.setEdgeSelection $ sel
    $.EditablePoly.Remove selLevel:#Edge
    )
    )

    )
    else
    (
    max delete
    )
    )
    else
    (
    max delete
    )
    )
Sign In or Register to comment.