<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: MaxScript Editable Poly - Collapse vertices in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290796#M17139</link>
    <description>Yes you are right, because in this way we are taking an object at an index which is out of length so a Not Existing Object,&lt;BR /&gt;I think that this can be resolved updating vertexCount every time we collapse two vertex&lt;BR /&gt;for v = 1 to vertexCount-1 do (&lt;BR /&gt;    for v1 = v+1 to vertexCount do (&lt;BR /&gt;        if vertex&lt;V&gt;.position = vertex do (&lt;BR /&gt;            Collapse (v, v1)&lt;BR /&gt;            vertexCount = polyOp.getNumVerts obj&lt;BR /&gt;        )&lt;BR /&gt;    )&lt;BR /&gt;)&lt;BR /&gt;What do you thing? Thanks.&lt;/V&gt;</description>
    <pubDate>Thu, 09 May 2013 11:21:55 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-05-09T11:21:55Z</dc:date>
    <item>
      <title>MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290794#M17137</link>
      <description>Good morning everybody.&lt;BR /&gt;I am starting with MaxScript, but I already know develop codes (I come from c#)&lt;BR /&gt;I want to create a script which collapse all vertices which has the same position or their distance is close then a value. I thought this logic:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;SelectedMesh = $&lt;BR /&gt;ConvertTo SelectedMesh Editable_Poly&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;BR /&gt;for (v in "Vertices of this editable poly") do&lt;BR /&gt;    for (v1 in "Other vertices of this poly but not this") do&lt;BR /&gt;//        if (v.position = v1.position) Collapse These two&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;How can I do this? Thanks Good Bye.</description>
      <pubDate>Wed, 08 May 2013 18:44:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290794#M17137</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-08T18:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290795#M17138</link>
      <description>Avoid "$" in scripts. $ is the entire current selection whereas you need a single object.&lt;BR /&gt;&lt;PRE&gt;selectedMesh = selection&lt;/PRE&gt;&lt;BR /&gt;Or if you need to iterate over all the selected objects:-&lt;BR /&gt;&lt;PRE&gt; for selectedMesh in selection do&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;for (v in “Vertices of this editable poly") do&lt;BR /&gt;No. for (v in "all but the last vertex of this editable poly") do&lt;BR /&gt;Reason being you correctly identified the need to omit the current v vertex in the v1 loop (but it needs to omit all vertices up to and including the current v) therefore you must omit the last vertex in the first line otherwise you'll end up comparing the last vertex with itself.&lt;BR /&gt;And as you're converting it, it will no longer be a mesh. Probably better to simply call it  "obj" or "thisObj".&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;obj = selection&lt;BR /&gt;convertToPoly obj&lt;BR /&gt;&lt;BR /&gt;vertexCount = polyOp.getNumVerts obj&lt;BR /&gt;&lt;BR /&gt;for v = 1 to vertexCount - 1 do&lt;BR /&gt;   (&lt;BR /&gt;   for v1 = v + 1 to vertexCount do&lt;BR /&gt;      (&lt;BR /&gt;      ...&lt;BR /&gt;      )&lt;BR /&gt;   )&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;The above, as it stands, will not work. If you collapse 2 vertices of a single quad poly (4 vertices) you end up with a triangle (3 vertices). The conditions of a for loop, as in most languages, are set in the initial for statement &lt;I&gt;and cannot be changed within the loop&lt;/I&gt; therefore you'll be trying to test vertex 3(last iteration of the outer v loop) with vertex 4 (last iteration of the inner v1 loop) which no longer exists. This will cause an exception and the script will fail.&lt;BR /&gt;&lt;BR /&gt;Note. This isn't specifically a Maxscript issue - it can occur in almost any language where you attempt to compare, for example, 2 arrays of values and remove values from those arrays when a match is found. The count (number of elements in the arrays) decreases causing either an exception, an "index out of range" or some similar error, depending on the language. For arrays it can sometimes be overcome by working DOWN the arrays rather than UP them. This may not work in this specific case because you may remove more than 1 vertex per pass. It will need more than just iterating over the vertices which exist at the beginning in order to overcome this.</description>
      <pubDate>Wed, 08 May 2013 21:38:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290795#M17138</guid>
      <dc:creator>Steve_Curley</dc:creator>
      <dc:date>2013-05-08T21:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290796#M17139</link>
      <description>Yes you are right, because in this way we are taking an object at an index which is out of length so a Not Existing Object,&lt;BR /&gt;I think that this can be resolved updating vertexCount every time we collapse two vertex&lt;BR /&gt;for v = 1 to vertexCount-1 do (&lt;BR /&gt;    for v1 = v+1 to vertexCount do (&lt;BR /&gt;        if vertex&lt;V&gt;.position = vertex do (&lt;BR /&gt;            Collapse (v, v1)&lt;BR /&gt;            vertexCount = polyOp.getNumVerts obj&lt;BR /&gt;        )&lt;BR /&gt;    )&lt;BR /&gt;)&lt;BR /&gt;What do you thing? Thanks.&lt;/V&gt;</description>
      <pubDate>Thu, 09 May 2013 11:21:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290796#M17139</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-09T11:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290797#M17140</link>
      <description>Unfortunately not - as I mentioned, the conditions for a for loop are set once when the actual for loop is executed. That actual statement is never executed again (at least the outer one isn't) so changing the value of vertexCount within the loop will not affect the number of times the looped code is executed.&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;(&lt;BR /&gt;V = 5&lt;BR /&gt;for t = 1 to V do&lt;BR /&gt;   (&lt;BR /&gt;   format "t=%, V=%\n" t V&lt;BR /&gt;   V -= 1&lt;BR /&gt;   )&lt;BR /&gt;)&lt;/PRE&gt;&lt;BR /&gt;results in&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;t=1, V=5&lt;BR /&gt;t=2, V=4&lt;BR /&gt;t=3, V=3&lt;BR /&gt;t=4, V=2&lt;BR /&gt;t=5, V=1&lt;BR /&gt;OK&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;Next up - the actual collapsing of the vertices. There are 2 methods for collapsing vertices in an Editable Poly:-&lt;BR /&gt;polyOp.collapseVerts editable_poly_object vertexlist&lt;BR /&gt;and&lt;BR /&gt;editable_poly_object.collapse #vertex&lt;BR /&gt;&lt;BR /&gt;The first requires a list of vertex numbers (actually a bitArray) to be collapsed, the second requires that the vertices to be collapsed are selected. In both cases the vertices must be directly connected to each other - merely determining that their positions are the same will not be sufficient to guarantee that they will be collapsed. That will require a fair bit of work - that which you can easily identify by simply looking at the object can be quite difficult (or at least long-winded) to determine programatically.</description>
      <pubDate>Thu, 09 May 2013 12:47:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290797#M17140</guid>
      <dc:creator>Steve_Curley</dc:creator>
      <dc:date>2013-05-09T12:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290798#M17141</link>
      <description>I am having trouble manipulating with vertexes.&lt;BR /&gt;&lt;BR /&gt;This works great&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;for selectedMesh in selection do (&lt;BR /&gt; print (selectedMesh.name as String)&lt;BR /&gt; vertexCount = polyOp.getNumVerts selectedMesh&lt;BR /&gt; collapsableVertex = 0&lt;BR /&gt; print (vertexCount as String)&lt;BR /&gt; for v = 1 to vertexCount-1 do (&lt;BR /&gt; for v1 = v+1 to vertexCount do (&lt;BR /&gt; vertexA = polyOp.getVert selectedMesh v&lt;BR /&gt; vertexB = polyOp.getVert selectedMesh v1&lt;BR /&gt; )&lt;BR /&gt; )&lt;BR /&gt; print (collapsableVertex)&lt;BR /&gt;)&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;But when I check if they has the same position I get error.&lt;BR /&gt;This is the code I have used to check the position&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;if vertexA.pos = vertexB.pos do (&lt;BR /&gt; collapsableVertex = collapsableVertex+1&lt;BR /&gt;)&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;This is the error&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;BR /&gt;"Box001"&lt;BR /&gt;"6146"&lt;BR /&gt;-- Error occurred in v1 loop; filename: C:\Users\Gurpreet Singh\Documents\3dsMax\scenes\CollapseVertexWithSamePosition.ms; position: 886; line: 26&lt;BR /&gt;--  Frame:&lt;BR /&gt;--   v1: 2&lt;BR /&gt;--   vertexA: &lt;BR /&gt;--   vertexB: &lt;BR /&gt;--   called in V loop; filename: C:\Users\Gurpreet Singh\Documents\3dsMax\scenes\CollapseVertexWithSamePosition.ms; position: 945; line: 29&lt;BR /&gt;--  Frame:&lt;BR /&gt;--   V: 1&lt;BR /&gt;--   called in selectedMesh loop; filename: C:\Users\Gurpreet Singh\Documents\3dsMax\scenes\CollapseVertexWithSamePosition.ms; position: 949; line: 30&lt;BR /&gt;--  Frame:&lt;BR /&gt;--   selectedMesh: $Box001&lt;BR /&gt;--   collapsableVertex: 0&lt;BR /&gt;--   vertexCount: 6146&lt;BR /&gt;-- No ""="" function for (Global:distance Local:vertexA Local:vertexB)&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 09 May 2013 12:55:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290798#M17141</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-09T12:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290799#M17142</link>
      <description>You need to read the help a little more carefully. &lt;BR /&gt;&lt;BR /&gt;if vertexA.pos = vertexB.pos&lt;BR /&gt;Is wrong on 2 counts.&lt;BR /&gt;&lt;BR /&gt;1) polyOp.getVert returns a position (a Point3 value) - it IS a position. It does not have a pos property.&lt;BR /&gt;2) A test for Equals is == not = (= is for assignment only).&lt;BR /&gt;&lt;BR /&gt;I would suggest you put this project on hold temporarily. Load the Maxscript help &amp;gt; contents &amp;gt; Maxscript Introduction. Read all the sections down to (and including) "Maxscript for new and casual users". That should help you avoid making what are quite basic mistakes. Every language has its own distinct syntax and is rarely applicable, without modification, to another language. Knowing C# will help with the general principles of programming, but not with the specifics.</description>
      <pubDate>Thu, 09 May 2013 14:20:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290799#M17142</guid>
      <dc:creator>Steve_Curley</dc:creator>
      <dc:date>2013-05-09T14:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290800#M17143</link>
      <description>I've done a similar script by request quite a while ago, the barebones version would be:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;try destroyDialog ::vertexFuse catch()&lt;BR /&gt;rollout vertexFuse "Vertex Fuse" width:150 height:65&lt;BR /&gt;(&lt;BR /&gt;    spinner spnDist "Distance: " range: fieldWidth:50 type:#worldunits&lt;BR /&gt;    button btnFuse "Fuse Vertices" width:135 height:25 offset:&lt;BR /&gt;&lt;BR /&gt;    local setMeshVert = meshOp.setVert&lt;BR /&gt;&lt;BR /&gt;    fn getNearbyVertices index list dist verts queue =&lt;BR /&gt;        for v in queue&lt;BR /&gt;            where distance verts.pos verts&lt;V&gt;.pos &amp;lt;= dist do&lt;BR /&gt;            (&lt;BR /&gt;                append list v&lt;BR /&gt;                queue&lt;V&gt; = false&lt;BR /&gt;                getNearbyVertices v list dist verts queue&lt;BR /&gt;            )&lt;BR /&gt;&lt;BR /&gt;    on btnFuse pressed do with undo off, redraw off&lt;BR /&gt;    (&lt;BR /&gt;        if selection.count != 1 do&lt;BR /&gt;            return messageBox "Select one object."&lt;BR /&gt;&lt;BR /&gt;        local obj = selection&lt;BR /&gt;        local objTM = obj.transform&lt;BR /&gt;        if NOT isKindOf obj Editable_mesh do convertToMesh obj&lt;BR /&gt;&lt;BR /&gt;        setCommandPanelTaskMode mode:#create&lt;BR /&gt;&lt;BR /&gt;        local verts = obj.verts as bitArray&lt;BR /&gt;        local vertCount = verts.count&lt;BR /&gt;        local vertList = join #() obj.verts&lt;BR /&gt;        local vertDist = spnDist.value&lt;BR /&gt;        local vertQueue = #{}&lt;BR /&gt;&lt;BR /&gt;        local matchedVerts = #{}&lt;BR /&gt;        local fuseList = #()&lt;BR /&gt;&lt;BR /&gt;        for i = 1 to vertCount do&lt;BR /&gt;        (&lt;BR /&gt;            local v = vertList&lt;I&gt;&lt;BR /&gt;&lt;BR /&gt;            for j = i + 1 to vertCount&lt;BR /&gt;                where NOT matchedVerts&lt;J&gt; AND&lt;BR /&gt;                distance v.pos vertList&lt;J&gt;.pos &amp;lt;= vertDist do&lt;BR /&gt;                (&lt;BR /&gt;                    append vertQueue i&lt;BR /&gt;                    append vertQueue j&lt;BR /&gt;                    append matchedVerts j&lt;BR /&gt;                )&lt;BR /&gt;        )&lt;BR /&gt;&lt;BR /&gt;        local vertToSelect = copy vertQueue&lt;BR /&gt;&lt;BR /&gt;        for v in vertQueue do&lt;BR /&gt;        (&lt;BR /&gt;            local vertGroup = #{}&lt;BR /&gt;            getNearbyVertices v vertGroup vertDist vertList vertQueue&lt;BR /&gt;            append fuseList vertGroup&lt;BR /&gt;        )&lt;BR /&gt;&lt;BR /&gt;        for each in fuseList do&lt;BR /&gt;        (&lt;BR /&gt;            obj.selectedVerts = each&lt;BR /&gt;            setMeshVert obj each ((averageSelVertCenter obj) * objTM)&lt;BR /&gt;        )&lt;BR /&gt;&lt;BR /&gt;        obj.selectedVerts = vertToSelect&lt;BR /&gt;&lt;BR /&gt;        setCommandPanelTaskMode mode:#modify&lt;BR /&gt;        subObjectLevel = 1&lt;BR /&gt;    )&lt;BR /&gt;)&lt;BR /&gt;createDialog vertexFuse&lt;/J&gt;&lt;/J&gt;&lt;/I&gt;&lt;/V&gt;&lt;/V&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Hopefully it's short enough for you to comprehend while still applicable (with a few changes here and there - you might want to use 3d grid for lookup for complex meshes, for example). Instead of collapsing the verts, it positions them at the same place - one loop to find all close verts, another to merge them in groups. It uses a threshold (btw. note that equality comparison on two Point3 values, effectively vectors consisting of single precision floats, will often return false even when the two points are by design on the same position - look up float comparison for further info).&lt;BR /&gt;&lt;BR /&gt;Using mesh instead of poly methods is just my personal preference, if you'd like to use polyop methods, only averageSelVertCenter would need to be replaced by a simple function - sum of all positions divided by their count.</description>
      <pubDate>Thu, 09 May 2013 16:06:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290800#M17143</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2013-05-09T16:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290801#M17144</link>
      <description>It's oke, got it. I have just now studied Values at: &lt;A href="http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-B59088DE-AC0B-4926-8522-FC0A98BF8577.htm,topicNumber=d30e154967" target="_blank"&gt;http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-B59088DE-AC0B-4926-8522-FC0A98BF8577.htm,topicNumber=d30e154967&lt;/A&gt;&lt;BR /&gt;So only now I am able to understand what is Point3 and how to compare these two.&lt;BR /&gt;Now I am studying "Maxscript for new and casual users" at &lt;A href="http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-35CB7918-A86D-465E-AC63-3AAE310A113B.htm,topicNumber=d30e33578" target="_blank"&gt;http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=files/GUID-35CB7918-A86D-465E-AC63-3AAE310A113B.htm,topicNumber=d30e33578&lt;/A&gt; as you said. &lt;BR /&gt;The problem is that this script would help me in a game development project, so I without this I will lost a lot of time.</description>
      <pubDate>Sat, 11 May 2013 09:01:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290801#M17144</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-11T09:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290802#M17145</link>
      <description>Does Editable_Mesh to this better then Editable_Poly?&lt;BR /&gt;I was using Editable_Poly because this has also the possibility to remove a vertex without losing a face and the UV.&lt;BR /&gt;You are suggesting me to use one loop to position all vertex with less then a distance at the same position, and use a second loop to collapse them. Yes this looks good, now I have another idea passing through my mind. With this I can implement in this way:&lt;BR /&gt;Detect which  is the vertex a the border.&lt;BR /&gt;Position all closest vertex to it's position.&lt;BR /&gt;How can I detect if a vertex is at border?&lt;BR /&gt;What is averageSelVertCenter? Is it the mid point between vertexes or a method like polyOp?&lt;BR /&gt;I see at line 10 you used " where distance verts.pos verts&lt;V&gt;.pos &amp;lt;= dist do". Does this loop automatically and check the if statement?&lt;BR /&gt;Thanks&lt;/V&gt;</description>
      <pubDate>Sat, 11 May 2013 09:14:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290802#M17145</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-11T09:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290803#M17146</link>
      <description>It looks I am getting near to the target but not sure.&lt;BR /&gt;I am using this Logic&lt;BR /&gt;Loop from 1 to vertexCount to check how many vertex are collapsable&lt;BR /&gt;Loop from 1 to vertexCount-collapsableVertex to collapse this vertex.&lt;BR /&gt;I have created a box with Length = 0, Width = 10, Height = 10, I have converted it to Editable_Poly and then Tesselate a lot of time. So now this Box has at 17 vertex per each vertex at the border, and 2 vertex on per each vertex on the front face.&lt;BR /&gt;In total I have 1538 Vertex, this script detects 1248 Vertex Collapsable&lt;BR /&gt;Looping in this way to second loop (the loop which has the function to collapse) finishes at 1538-1248 = 290. This should be correct, but the problem is that all collapse returns false, I don't know why?.&lt;BR /&gt;I have tried to do it from Editable_Poly Options, and is possible to collapse this 17 vertex to 1 vertex.&lt;BR /&gt;This is the script:&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;distanceToCollapse = 0.1&lt;BR /&gt;for selectedMesh in selection do (&lt;BR /&gt; vertexCount = polyOp.getNumVerts selectedMesh&lt;BR /&gt; print (selectedMesh.name as String + "; Vertex: " + vertexCount as String + ";")&lt;BR /&gt; print ("Detection started ...")&lt;BR /&gt; collapsableVertex = 0&lt;BR /&gt; disabledVertex = #()&lt;BR /&gt; for a = 1 to vertexCount-1 do (&lt;BR /&gt; for b = a+1 to vertexCount-1 do (&lt;BR /&gt; vertexA = polyOp.getVert selectedMesh a&lt;BR /&gt; vertexB = polyOp.getVert selectedMesh b&lt;BR /&gt; if (distance vertexA vertexB) &amp;lt; distanceToCollapse do (&lt;BR /&gt; availableVertex = true&lt;BR /&gt; for c = 1 to disabledVertex.count do (&lt;BR /&gt; if disabledVertex&lt;C&gt; as Integer == b as Integer then (&lt;BR /&gt; availableVertex = false&lt;BR /&gt; print ("STATE " + a as String + "; DETECTED " + b as String + "; AT INDEX " + c as String + "; TARGET " + vertexCount as String + "; RETURN " + availableVertex as String + ";")&lt;BR /&gt; )&lt;BR /&gt; )&lt;BR /&gt; if availableVertex then (&lt;BR /&gt; collapsableVertex = collapsableVertex+1&lt;BR /&gt; disabledVertex = disabledVertex + #(b)&lt;BR /&gt; ) else (&lt;BR /&gt; print ("AVAILABLE RETURNED FALSE")&lt;BR /&gt; )&lt;BR /&gt; )&lt;BR /&gt; )&lt;BR /&gt; )&lt;BR /&gt; print (disabledVertex.count)&lt;BR /&gt; print ("Detection finished. Detected " + collapsableVertex as String + " collapsable vertex over " + vertexCount as String + " vertex")&lt;BR /&gt; if collapsableVertex &amp;gt; vertexCount do (&lt;BR /&gt; print ("Failed")&lt;BR /&gt; continue&lt;BR /&gt; )&lt;BR /&gt; for d = 1 to vertexCount-collapsableVertex-1 do (&lt;BR /&gt; for g = d+1 to vertexCount-collapsableVertex do (&lt;BR /&gt; vertexD = polyOp.getVert selectedMesh d&lt;BR /&gt; vertexG = polyOp.getVert selectedMesh g&lt;BR /&gt; if (distance vertexD vertexG) &amp;lt; distanceToCollapse do (&lt;BR /&gt; polyOp.SetVertSelection selectedMesh #{d, g}&lt;BR /&gt; if (selectedMesh.EditablePoly.collapse #Vertex) then (&lt;BR /&gt; print ("Collapsed Vertex " + d as String + " and " + g as String)&lt;BR /&gt; ) else (&lt;BR /&gt; print ("Failed collapsing " + d as String + " and " + g as String)&lt;BR /&gt; )&lt;BR /&gt; )&lt;BR /&gt; )&lt;BR /&gt; )&lt;BR /&gt; vertexCount = polyOp.getNumVerts selectedMesh&lt;BR /&gt; print (vertexCount as String)&lt;BR /&gt;)&lt;BR /&gt;&lt;/C&gt;&lt;/PRE&gt;&lt;BR /&gt;How can I fix this?&lt;BR /&gt;Thanks, good bye!</description>
      <pubDate>Sat, 11 May 2013 09:27:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290803#M17146</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-05-11T09:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290804#M17147</link>
      <description>You are free to use whatever suits your purpose best, meshop methods are in some cases faster but sometimes the conversion from poly to mesh beats the purpose.&lt;BR /&gt;I'm not sure what you mean by the border here. In a subobject sense, finding out if a vertex lies on a border means that the vertex is one of the border verts - you'd get the border verts before entering the loop - borderVerts = polyOp.getVertsUsingEdge obj (polyOp.getOpenEdges obj) - and then in the loop test for it - borderVerts.&lt;BR /&gt;As for averageSelVertCenter, just look it up in the reference. Same applies for where condition - look up for loop syntax in the reference.</description>
      <pubDate>Sat, 11 May 2013 11:24:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290804#M17147</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2013-05-11T11:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: MaxScript Editable Poly - Collapse vertices</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290805#M17148</link>
      <description>No, it won't work like this, look at the code I posted before - the second loop is not just iterating over all the candidates, it's recursively searching for the neighbor candidates to collapse. To see what would happen in you case compare it with for example max teapot, 4 segments, 120-unit radius - run my code on it converted to editable mesh, run this code on it converted to editable poly:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;(&lt;BR /&gt;    local distanceToCollapse = 10.0&lt;BR /&gt;    local objs = for obj in selection where isKindOf obj Editable_Poly collect obj&lt;BR /&gt;    local getVertPos = polyOp.getVert&lt;BR /&gt;&lt;BR /&gt;    for obj in objs do&lt;BR /&gt;    (&lt;BR /&gt;        local disabledVerts = #{}&lt;BR /&gt;        local vertexCount = polyOp.getNumVerts obj&lt;BR /&gt;        format "Object: %, Vertex count: %\n" obj.name vertexCount&lt;BR /&gt;        print ("Detection started ...")&lt;BR /&gt;&lt;BR /&gt;        for a = 1 to vertexCount-1 do&lt;BR /&gt;            for b = a + 1 to vertexCount&lt;BR /&gt;                where distance (getVertPos obj a) (getVertPos obj b) &amp;lt; distanceToCollapse do&lt;BR /&gt;                (&lt;BR /&gt;                    append disabledVerts a&lt;BR /&gt;                    append disabledVerts b&lt;BR /&gt;                )&lt;BR /&gt;&lt;BR /&gt;        format "Detection finished. Detected % collapsible vertices of %.\n" disabledVerts.numberSet vertexCount&lt;BR /&gt;&lt;BR /&gt;        polyOp.collapseVerts obj disabledVerts&lt;BR /&gt;&lt;BR /&gt;        format "Vertex count after collapse: %\n" (polyOp.getNumVerts obj)&lt;BR /&gt;    )&lt;BR /&gt;)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;That's basically your code cleaned up a bit with some erroneous parts removed.&lt;BR /&gt;&lt;BR /&gt;Have a look at bitarrays and how they work, and study polyOp structure for a while to see what you can use. Don't write new code until you are familiar with them, otherwise you end up reinventing the whell which makes your code both slower and harder to read (and introduces some bugs here and there as well). Take for example this part:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;for c = 1 to disabledVertex.count do&lt;BR /&gt;(&lt;BR /&gt; if disabledVertex&lt;C&gt; as Integer == b as Integer then&lt;BR /&gt; (&lt;BR /&gt; availableVertex = false&lt;BR /&gt;  print (...)&lt;BR /&gt;  )&lt;BR /&gt;)&lt;/C&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Using bitarray for disabledVerts, it can be rewritten as &lt;PRE&gt;if disabledVerts&lt;B&gt; do print (...)&lt;/B&gt;&lt;/PRE&gt; or rather using this line together with the original condition ((...) AND (...)). Apart from the debug print, it's not needed here as bitarrays don't have duplicate entries anyway so I left it out in the end. &lt;BR /&gt;&lt;BR /&gt;Note that in another line, &lt;PRE&gt;disabledVertex = disabledVertex + #(b)&lt;/PRE&gt; is actually &lt;PRE&gt;append disabledVerts b&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;And a minor nitpick would be changing &lt;PRE&gt;collapsableVertex = collapsableVertex + 1&lt;/PRE&gt; to &lt;PRE&gt;collapsableVertex += 1&lt;/PRE&gt; although you don't actually need it at all.&lt;BR /&gt;&lt;BR /&gt;Also don't use EditablePoly methods, many of them require modify mode and redraw the UI, which slows things down. Another problem with them is that you often have to select verts and "push the buttons" instead of passing some arbitrary vertex bitarray directly to a function.</description>
      <pubDate>Sat, 11 May 2013 11:29:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/maxscript-editable-poly-collapse-vertices/m-p/4290805#M17148</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2013-05-11T11:29:07Z</dc:date>
    </item>
  </channel>
</rss>

