<?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: Script to create new vertices on shared coordinate edges? in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761023#M6341</link>
    <description>&lt;P&gt;Actually there's not much to add to senorpablo's answer.&lt;BR /&gt;In worst case scenario OpenVertsCount * OpenEdgesCount operations have to be made to find all 'missing' vertex positions. It's not optimal and is slow on high poly meshes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pseudocode of what's under the hood:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;obj               = $
radius            = 1.0
open_edge_indexes = polyop.getOpenEdges obj
open_vert_indexes = polyop.getVertsUsingEdge obj open_edge_indexes
edges_to_divide = #()
edges_to_divide_indexes = #{}

for v in open_vert_indexes do
(
	pt  = polyop.getVert obj v	
		
	for index in open_edge_indexes where PointSegmentDistance pt obj index &amp;lt;= radius do
	(
		ev = polyop.getEdgeVerts obj
		v1 = polyop.getVert obj ev[1]
		v2 = polyop.getVert obj ev[2]
		
		proj_pt = ProjectPointOnSegment pt v1 v2
		
		if PointsBelongsToSegment proj_pt v1 v2 do
		(
			fraction = distance v1 proj_pt / distance v1 v2			
			append edges_to_divide #( index, fraction )
			
			edges_to_divide_indexes[ index ] = true 
		)
	)
	
)


edges_with_fractions = for i in edges_to_divide_indexes collect
(
	all_fractions_of_edge = for item in edges_to_divide where item[1] == i collect item[2]
	sort all_fractions_of_edge
	
	DataPair edge_index:i fractions:all_fractions_of_edge
)

qsort edges_with_fractions SortByEdgeIndexHighToLow

for item in edges_with_fractions do
(
	DividePolyEdge obj item.edge_index item.fractions
)

&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Sep 2020 12:19:15 GMT</pubDate>
    <dc:creator>Serejah</dc:creator>
    <dc:date>2020-09-22T12:19:15Z</dc:date>
    <item>
      <title>Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9752235#M6331</link>
      <description>&lt;P&gt;We are processing loads of CAD geometry from ArchiCAD, but are struggling with the same errors from ArchiCAD all the time, which we need to address to be able to use other tools. The real solution would be to weld vertices that shares coordinates automatically, as there is open geometry all over the place. However, it isn't that easy, because there are also edges sharing coordinates where one has a vertex while the other doesn't have. (see image for visual explanation)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this image, I have moved one of the vertices down a bit just to show that the shared edge doesn't have a vertex, which means I won't be able to complete/weld this geometry easily without creating a new vertex on the edge that is missing a vertex, and then target weld it to that existing vertex. Welding is of course not a problem to do, but how can I create those new vertices with maxscript? Hopefully some guru out there knows the answer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vertices1.JPG" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/820263i559F8DE659CD6E1E/image-size/large?v=v2&amp;amp;px=999" role="button" title="vertices1.JPG" alt="vertices1.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 09:07:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9752235#M6331</guid>
      <dc:creator>chroma123</dc:creator>
      <dc:date>2020-09-17T09:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756508#M6332</link>
      <description>&lt;P&gt;I've done something similar in one of my tools, it's&amp;nbsp;not a trivial task. There is no built in method to do it so it requires&amp;nbsp; &amp;nbsp;custom math functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Every edge edge must be tested against every vertex to see if they lie along and within an edge, and then use the built in function to add vertices along that edge based on the distances.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 01:02:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756508#M6332</guid>
      <dc:creator>senorpablo</dc:creator>
      <dc:date>2020-09-19T01:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756651#M6333</link>
      <description>&lt;P&gt;is the vert at the other end always shared/welded ? and are there mapping channels to deal with ?&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 06:42:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756651#M6333</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2020-09-19T06:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756658#M6334</link>
      <description>&lt;P&gt;I am not sure about mapping coords, actually, but I wonder if there are some options in the export from archicad. No mapping channels applied in max at this point. Specifically we use this type of geometry to create cladding with a custom script, but the base mesh from archicad sucks so much. I came to the conclusion that closing the geometry fixes the problem, but cannot do that without adding vertices on the edges that is missing one. Do you think mapping could fix it somehow?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other vertex in such cases seems to be shared but not welded.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 07:03:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756658#M6334</guid>
      <dc:creator>chroma123</dc:creator>
      <dc:date>2020-09-19T07:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756671#M6335</link>
      <description>&lt;P&gt;Makes sense. But distance. Wouldn't the problem be that these edges has different lengths? Hm. What if just save one vertex coordinate, and check all edges if they have eighter x, y or z placed on along this coordinate, and if yes then add vertex. And then off to the next vertex and same procedure, and then at the end, welding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say that it is the "&lt;SPAN style="font-family: inherit;"&gt;check all edges if they have eighter x, y or z placed on along this coordinate" part that gets me stuck with this option, because how do you check if an exact vertex position exist on a whole edge?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 07:15:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756671#M6335</guid>
      <dc:creator>chroma123</dc:creator>
      <dc:date>2020-09-19T07:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756695#M6336</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;The other vertex in such cases seems to be shared but not welded.&lt;BR /&gt;&lt;BR /&gt;so you don't have this going on ?&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tjunct.jpg" style="width: 336px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/821265iDA4C1B5F65B86A34/image-size/large?v=v2&amp;amp;px=999" role="button" title="tjunct.jpg" alt="tjunct.jpg" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;don't think mapping helps it was just something that could have to be dealt with&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 07:58:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756695#M6336</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2020-09-19T07:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756708#M6337</link>
      <description>&lt;P&gt;perhaps something like this can find the them (assuming theres always a shared welded vert)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;fn get_tjunction poly epsilon =
(
	polyop.setVertSelection poly #{}; -- illustration 
	polyop.setEdgeSelection poly #{};
	
	open_edgs = polyop.getopenEdges poly;
	open_verts = polyop.getvertsUsingEdge poly open_edgs;	
	
	for v in open_verts do
	(
		vedges = polyop.getEdgesUsingVert poly v;	
		openvedges = for ve in vedges where open_edgs[ve] == true collect ve;	
		
		if openvedges.count == 2 then -- does an open "used" vert always have 2 edges ?
		(	
			edgeverts = polyop.getEdgeVerts poly openvedges[1];
			end_v1 = if edgeverts[1] == v then  edgeverts[2] else edgeverts[1];
			
			edgeverts = polyop.getEdgeVerts poly openvedges[2];
			end_v2 = if edgeverts[1] == v then  edgeverts[2] else edgeverts[1];
				
			a = polyop.getvert poly v;
			ab = (polyop.getvert poly end_v1) - a;
			ac = (polyop.getvert poly end_v2) - a;
			
			d = dot (normalize ab) (normalize ac);

			if	d &amp;gt; 1.0 - epsilon then
			(	
				tvert = end_v1;
				insert_edge = openvedges[1];
				if length ab &amp;gt; length ac then
				(
					tvert = end_v2;
					insert_egde = openvedges[2];
				)
				
				vsel = polyop.getVertSelection poly;
				vsel[tvert] = true;
				polyop.setVertSelection poly vsel;
					
				esel = polyop.getEdgeSelection poly;
				esel[insert_edge] = true;
				polyop.setEdgeSelection poly esel;	
			)
		)	
	)
)

get_tjunction $ 0.0001;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 08:20:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9756708#M6337</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2020-09-19T08:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9758833#M6338</link>
      <description>&lt;P&gt;There's always a hope!&lt;/P&gt;&lt;P&gt;But can't say if I'm able to release it anytime soon...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="cIpVGoyM7m.gif" style="width: 662px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/821734iB853524D5C93E5F9/image-size/large?v=v2&amp;amp;px=999" role="button" title="cIpVGoyM7m.gif" alt="cIpVGoyM7m.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 12:11:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9758833#M6338</guid>
      <dc:creator>Serejah</dc:creator>
      <dc:date>2020-09-21T12:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9759832#M6339</link>
      <description>&lt;P&gt;YES! Exactly like that, only in an automatic under-the-hood operation. Looks like you've done quite a bit work to achieve this though, since you put the effort to create a new modifier. Am I right? If you are thinking about commercializing it, I won't ask you for how you did it, but otherwise; can you share some insight on how you did it?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 20:54:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9759832#M6339</guid>
      <dc:creator>chroma123</dc:creator>
      <dc:date>2020-09-21T20:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9759839#M6340</link>
      <description>&lt;P&gt;Thanks for the script snippet&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1794911"&gt;@klvnk&lt;/a&gt;,&amp;nbsp;but it didn't do anything, at least to my edges and vertices.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 20:55:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9759839#M6340</guid>
      <dc:creator>chroma123</dc:creator>
      <dc:date>2020-09-21T20:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761023#M6341</link>
      <description>&lt;P&gt;Actually there's not much to add to senorpablo's answer.&lt;BR /&gt;In worst case scenario OpenVertsCount * OpenEdgesCount operations have to be made to find all 'missing' vertex positions. It's not optimal and is slow on high poly meshes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pseudocode of what's under the hood:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;obj               = $
radius            = 1.0
open_edge_indexes = polyop.getOpenEdges obj
open_vert_indexes = polyop.getVertsUsingEdge obj open_edge_indexes
edges_to_divide = #()
edges_to_divide_indexes = #{}

for v in open_vert_indexes do
(
	pt  = polyop.getVert obj v	
		
	for index in open_edge_indexes where PointSegmentDistance pt obj index &amp;lt;= radius do
	(
		ev = polyop.getEdgeVerts obj
		v1 = polyop.getVert obj ev[1]
		v2 = polyop.getVert obj ev[2]
		
		proj_pt = ProjectPointOnSegment pt v1 v2
		
		if PointsBelongsToSegment proj_pt v1 v2 do
		(
			fraction = distance v1 proj_pt / distance v1 v2			
			append edges_to_divide #( index, fraction )
			
			edges_to_divide_indexes[ index ] = true 
		)
	)
	
)


edges_with_fractions = for i in edges_to_divide_indexes collect
(
	all_fractions_of_edge = for item in edges_to_divide where item[1] == i collect item[2]
	sort all_fractions_of_edge
	
	DataPair edge_index:i fractions:all_fractions_of_edge
)

qsort edges_with_fractions SortByEdgeIndexHighToLow

for item in edges_with_fractions do
(
	DividePolyEdge obj item.edge_index item.fractions
)

&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 12:19:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761023#M6341</guid>
      <dc:creator>Serejah</dc:creator>
      <dc:date>2020-09-22T12:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761447#M6342</link>
      <description>&lt;P&gt;Wow. I am impressed by the level of this forum, and grateful for the detail of sharing. Thank you so much. The script does kinda make sense to me, but when tested straight out on a mesh, I get an error, allegedly Call needs function or class, got undefined, somewhere in "for index in open_edge_indexes where PointSegmentDistance pt obj index &amp;lt;= radius do".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am eager to dive deeper into this, but first I need to understand what's undefined. Perhaps the&amp;nbsp;pt = polyop.getVert obj v&amp;nbsp; failed. My geometry is editable poly, and it is selected, so no need to be undefined, me thinks. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; Probably the answer is &lt;SPAN&gt;embarrassingly&amp;nbsp;&lt;/SPAN&gt;easy.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 15:12:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761447#M6342</guid>
      <dc:creator>chroma123</dc:creator>
      <dc:date>2020-09-22T15:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761585#M6343</link>
      <description>&lt;P&gt;Pseudocode is just a description of how the thing works. It's not a real script so it won't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 16:04:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761585#M6343</guid>
      <dc:creator>Serejah</dc:creator>
      <dc:date>2020-09-22T16:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761609#M6344</link>
      <description>&lt;P&gt;... Like I said. Embarrasingly simple. &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 16:15:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9761609#M6344</guid>
      <dc:creator>chroma123</dc:creator>
      <dc:date>2020-09-22T16:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9762239#M6345</link>
      <description>&lt;P&gt;my algorithm is almost identical to the Serejah's:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fn distanceToSegment p A B &amp;amp;param: &amp;amp;dist: =
(
	v = B - A
	param = dot v (p - A) / dot v v
	proj = A + v * param
	
	dist = distance p proj
	
	if (param &amp;lt; 0) then distance p A else if (param &amp;gt; 1) then distance p B else dist
)
fn getPolyEdgeParamPoint poly edge param = 
(
	vv = polyop.getEdgeVerts poly edge
	v1 = polyop.getVert poly vv[1]
	v2 = polyop.getVert poly vv[2]
	
	v1 * (1 - param) + v2 * param
)	

fn dividePolyEdgeAt poly edge point = 
(
	vv = polyop.getEdgeVerts poly edge
	v1 = polyop.getVert poly vv[1]
	v2 = polyop.getVert poly vv[2]
	
	param = distance v1 point / distance v1 v2
	polyop.divideEdge poly edge param
)	

fn multiDividePolyEdge poly edge params = 
(
	sort params

	points = for param in params collect (getPolyEdgeParamPoint poly edge param)
	new_verts = #()
	nume = poly.edges.count
	for point in points do 
	(
		v = dividePolyEdgeAt poly edge point
		if (v &amp;gt; 0) do
		(
			nume += 1
			edge = nume
			
			append new_verts v
		)
	)
	new_verts
)

fn weldClosePolyEdges poly threshold:0.5 weld:on select:on =
(
	if threshold != unsupplied then poly.weldThreshold = threshold else threshold = poly.weldThreshold

	open_ee = polyop.getOpenEdges poly
	open_vv = polyop.getVertsUsingEdge poly open_ee

	ee_table = #()
	weld_vv = #{}

	getvertpos = polyop.getVert
	getvertedges = polyop.getEdgesUsingVert 
	getedgeverts = polyop.getEdgeVerts 
	
	for v in open_vv do
	(
		pt = getvertpos poly v	
		ee = getvertedges poly v  
		
		found = off
		
		for e in open_ee while not found where not ee[e] do
		(
			vv = getedgeverts poly e
			v1 = getvertpos poly vv[1]
			v2 = getvertpos poly vv[2]

			distanceToSegment pt v1 v2 param:&amp;amp;p dist:&amp;amp;d
			if (found = (p &amp;gt; 0 and p &amp;lt; 1 and d &amp;lt; threshold)) do
			(
				if ee_table[e] == undefined do ee_table[e] = #()
				append ee_table[e] p

				append weld_vv v
			)
		)
	)

	for e=1 to ee_table.count where (params = ee_table[e]) != undefined do
	(
		vv = multiDividePolyEdge poly e params
		if vv.count &amp;gt; 0 do join weld_vv (tobits vv)
	)
	
	if select do poly.selectedverts = weld_vv
	
	if weld do polyop.weldVertsByThreshold poly weld_vv
		
	ok
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a test scene:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;delete objects
(
	p0 = plane width:30 length:10 pos:[-4,0,10.1] dir:y_axis wirecolor:yellow
	p1 = plane width:20 length:10 pos:[0,0,0] dir:y_axis wirecolor:orange
	p2 = plane width:40 length:10 pos:[3.5,0,-10.1] dir:y_axis wirecolor:brown

	converttopoly p0
	polyop.attach p0 p1
	polyop.attach p0 p2

	polyop.deletefaces p0 #{17, 20, 30..31}
	update p0
	p0.vertexticks = on
	select p0
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;weldClosePolyEdges $ threshold:0.2 weld:off select:on -- or use weld ON&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 21:40:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9762239#M6345</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-09-22T21:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9762267#M6346</link>
      <description>&lt;P&gt;hmm... it looks like&amp;nbsp;&lt;STRONG&gt;multiDividePolyEdge&lt;/STRONG&gt; method needs to be reviewed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 22:12:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9762267#M6346</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-09-22T22:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9762442#M6347</link>
      <description>&lt;P&gt;line:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;if vv.count &amp;gt; 0 do join weld_vv (tobits vv)&lt;/LI-CODE&gt;&lt;P&gt;must be changed to:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;if vv.count &amp;gt; 0 do join weld_vv (vv as bitarray)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tobits is my function. we should use the built-in one (as bitarray)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 00:35:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9762442#M6347</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-09-23T00:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9762870#M6348</link>
      <description>&lt;P&gt;Holy how. It works. Thank you so much. The concept is kind of simple, but in the reality it seems not quite so. I am taking a closer look at this script to understand all of it's nature. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks again! This should be implemented as a base functionality in 3ds max. Hopefully it's already covered in one of the remesh functions that was mentioned in the beta/roadmap, but if not...&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4316068"&gt;@brentscannell&lt;/a&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 07:41:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9762870#M6348</guid>
      <dc:creator>chroma123</dc:creator>
      <dc:date>2020-09-23T07:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9764700#M6349</link>
      <description>&lt;P&gt;The biggest problem with the above algorithm is its performance. For high poly objects with a lot of open edges, this will be slow. The only algorithmic solution I see is using an R-Tree ... but that's not for this topic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another small improvement we can make is to change the line:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;ee = getvertedges poly v&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and exclude all edges of surrounded faces for a processing vertex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 23:04:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9764700#M6349</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-09-23T23:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Script to create new vertices on shared coordinate edges?</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9801658#M6350</link>
      <description>&lt;P&gt;whoa, super interested in this!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 07:39:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/script-to-create-new-vertices-on-shared-coordinate-edges/m-p/9801658#M6350</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-14T07:39:03Z</dc:date>
    </item>
  </channel>
</rss>

