i guess you have something what you didn’t tell… make a picture. it will help for sure
I need to select objects next to selected object by same vertices position
Denis, thanks for the reply, you got the point right!
The issue is that I know the structure of the solution but I don’t know exact commands
btw, I just realized that I totaly forgot to mention a second part of the task: all other objects that somehow have vertices in same position as nearest objects should be selected too
so from previous example: I have selected on of the sphere but third sphere have any vertex in the same position of second (unselected) sphere but not the first one - so I want third sphere would be selected as well
It’s quite hard to exmplain. I hope you get it 
edit: so after selecting only object 1 I’d like 2 and 3 would be selected too
i don’t think your logic is correct. look at my picture.
you will see that following your logic red and green boxes are ‘far’ but red and yellow are ‘near’.
is it correct?
yes! and I think that having a way to set a threshold for the nearness is a good idea actually
edit: ofcourse if in your example red have a role of a base selected object
fn areMeshesNear source target threshold:1 =
(
s = snapshotasmesh source
t = snapshotasmesh target
result = undefined
for k=1 to s.numverts while result == undefined do
(
p = getvert s k
for i=1 to t.numverts while result == undefined do
(
if distance p (getvert t i) <= threshold do
(
result = [k,i]
)
)
)
free s
free t
return result
)
if areMeshesNear returns not undefined that means two geometry objects are close to each other by their verts locations
thanks a lot!
but what is target? I have thousands of objects in the scene and by selecting 1 I want all nearest by vertices would be selected too
c’mon…I’m not a coder…but it doesn’t take that long to fumble your way around…the Doc has done 95% of the work for you…can you put in a bit of elbow grease to push thru to the last 5% ?
Here, I’ve bastardised the code…as said I’m not a coder so coding integrity has gone out the window, I’m dealing with whatever errors come up on the screen…
so all your object should be ‘meshes’, ask the Doc to provide you an all purpose solution…NICELY.
It’s not that hard with a bit of determination…
fn areMeshesNear source target threshold:5 =
(
s = source
t = target
result = false
for k=1 to s.numverts while result == false do
(
p = getvert s k
for i=1 to t.numverts while result == false do
(
if distance p (getvert t i) <= threshold do
(
result = true
)
)
)
return result
)
s = $Teapot001 -- enter your source object name here !!!
clearSelection()
for t in (geometry) do
(
if areMeshesNear s t then (selectmore t)
)
as I’m not a coder, the source name is hardcoded…
thank you guys for putting an effort for me, I really appreciated.
But again I don’t understand how to use it — mean that I don’t know what parameters I should give to the function
All I want is to select one object of scene and then with some code select all other objects with “shared” vertices positions
as I understand the given FN could compare 2 objects by any vertex that share positions and return true/false.
now I want to use it for objects within a single scene. Do I need to have all objects as array or two arrays and then compare them? this is most hard part
it’s not that hard actually
for i=1 to geometry.count do
(
local obj1 = geometry[i]
for j=i+1 to geometry.count where areMeshesNear obj1 geometry[j] do ... anything you need
)
here’s an example of the scene:
https://drive.google.com/open?id=17DEGbh5wHWa5aQmnJ6KQYDCsA4i9d3zs
there’s two overlayed roads and other objects. I want to by selecting object “Mesh_3173” all of these objects to be selected:
"Mesh_2444"
"Mesh_2455"
"Mesh_2463"
"Mesh_2750"
"Mesh_2773"
"Mesh_2778"
"Mesh_2996"
"Mesh_3001"
"Mesh_3008"
"Mesh_3178"
"Mesh_3184"
"Mesh_2349"
"Mesh_2988"
"Mesh_3165"
"Mesh_2343"
"Mesh_2347"
"Mesh_2396"
"Mesh_2977"
"Mesh_3011"
"Mesh_3187"
"Mesh_2335"
"Mesh_2774"
"Mesh_2995"
"Mesh_3172"
"Mesh_2454"
"Mesh_2777"
"Mesh_2989"
"Mesh_3166"
"Mesh_2348"
EDIT: I add mentioned object list to the layer and reupload scene
well … i looked into the file and its setup and requirements.
as i expected the straightforward position comparison is very slow because of pretty big meshes and pure algorithm
anyway here is the code:
fn getOpenEdgeVerts mesh =
(
ee = meshop.getopenedges mesh
meshop.getvertsusingedge mesh ee
)
fn isMeshCloseEnough source target threshold:10 open:off =
(
near = off
sv = if open then getOpenEdgeVerts source else source.verts as bitarray
tv = if open then getOpenEdgeVerts target else target.verts as bitarray
for s in sv while not near do
(
p = getvert source s
for t in tv while not near do
(
near = distance p (getvert target t) <= threshold
)
)
near
)
fn findMeshesCloseEnough sources: targets: threshold:10 open:on =
(
if sources == unsupplied do sources = selection as array
sources = for source in sources where iskindof source Editable_mesh collect source
if targets == unsupplied do targets = for target in geometry where iskindof target Editable_mesh collect target
targets = for target in targets where (finditem sources target == 0) collect target
format ">> s:% t:%\n" sources.count targets.count
_sources = deepcopy (sources as array)
for source in _sources do
(
format "% >>" (finditem sources source)
for i = targets.count to 1 by -1 while not keyboard.escpressed do
(
target = targets[i]
if (isMeshCloseEnough source target threshold:threshold open:open) do
(
append sources target
deleteitem targets i
)
)
format " s:% t:%\n" sources.count targets.count
)
sources
)
fn findAllMeshesCloseEnough sources: targets: threshold:10 open:on =
(
if sources == unsupplied do sources = selection as array
sources = for source in sources where iskindof source Editable_mesh collect source
if targets == unsupplied do targets = for target in geometry where iskindof target Editable_mesh collect target
targets = for target in targets where (finditem sources target == 0) collect target
format ">> s:% t:%\n" sources.count targets.count
data = [0,0]
curr = [sources.count, targets.count]
for source in sources while not keyboard.escpressed do
(
data = copy curr
format "% >>" (finditem sources source)
for i = targets.count to 1 by -1 while not keyboard.escpressed do
(
target = targets[i]
if (isMeshCloseEnough source target threshold:threshold open:open) do
(
append sources target
deleteitem targets i
)
)
format " s:% t:%\n" sources.count targets.count
curr = [sources.count, targets.count]
)
sources
)
you can select the first mesh and run (with a specified threshold):
all = findAllMeshesCloseEnough threshold:10
select all
this function recursively adds close enough meshes to the list and grows the search. it stops when no new target was added.
the function shows the trace (where you can see timing and algorithm working)
i found that most meshes are ‘connected’ by open edges, so there is no reason to search all verts.
the function has an option <open: true/false>, which controls what set of verts to use (open or all). so, see the difference
the possible optimization could be:
#1 check meshes bounding box intersection before verts searching to ensure that the searching is needed at all
#2 of course it’s better to use Kd-tree search algorithm … but it’s a subject of another topic
(with a smart Kd-tree full search takes about 0.1 sec on my machine)
good luck!
… and of course any suggestions of possible optimization are welcome. i will be interested to see them too
thanks Denis, just launch it on my machine - still processing this example file.
I just thought if selection of all scene meshes and then searching for the meshes with shared vertices positions and then deviding those groups somehowe (by putting into different layers maybe?) would speed up the process
btw the process is finished: in around 5-7 minutes it does exactly what needs
edit: I’ve read the k-dimensional-tree wiki and this is quite interesting technology, how did you applied to my example file?
it’s still private at the moment … but I think I can open it for free. It all depends on my time and ongoing interest in MXS as a whole… which I doubt very much lately
could it be used out of the box or it’s need to be wraped in the code search algoritm for the topic task?

as soon as i have a time i will take a look