Finding copies

(Pascal Golay) #1

Hi Brian -

Continuing the discussion from Turning duplicate objects into a single block:

Hmmm, I guess a script could start by locating stones of equal volume - that should be straightforward enough, but then refining the search, if the stones can be any which way, is a bit more of a head scratcher - it might be able to measure edges or something… not sure.


WISH: SelSame, A Better Version of SelDup
Compare two polysurfaces

I was going to start on something like that, but got sidetracked by the CompletePlanarSrf script which I just posted in “scripting”… :frowning:



Below is a link to a sample file…It’s only the polysurfaces on the layer “stone” that I have to do cut tickets on. Warning that file is over 50 megs.



OK, here is a Python script to try… Right now limited to closed volumes: meshes or surfaces/polysurfaces. After a reference object is selected, it checks in order:

Mesh or BRep object

  1. Volume
  2. Area
  3. Number of edges
  4. Total length of edges
  5. Number of faces
  6. Number of vertices

If an object does not match one of the criteria, it is excluded. The matching objects are selected at the end. The status bar shows the progress.

For a lot of objects, this can be somewhat time consuming and will vary with the different depths of checking before objects are included or excluded. I tried with 10,000 simple boxes with slightly varying volume, the time varied from about 30 seconds when only a couple of them met the volume criteria, to about 75 seconds when almost all of them did. With the same number of boxes, but half had one split edge (which will trigger a “not the same object”, despite the virtually identical criteria) it took about 60 sec.

All this stuff can be adjusted perhaps and the script could be extended to open objects etc at some point. I’ll throw it up here for testing. In your file it took about 20 seconds to find “identical” stones to a selected reference stone, usually about 7 others found besides the original.

Let me know how it works,


Edit: fixed one bug that could cause the status bar meter to stay on if no objects were found, and a couple of other cleanups. KB)


Of course, this is no guarantee against “false positives”. In the file attached you can see how easy it still is to fool the script, the two objects are obviously not identical, but they have the same volume, area, number of edges and total edge length. They even have the same minimal bounding box.

One workaround would be to get the individual polysurface faces or edges and check for identicality - however, this can be very time consuming if they have a lot of faces, as you would have to check each face against each other - even if the object has only 10 faces, that’s about 50 checks per object.


FindSimilarFail.3dm(124.4 KB)

Select Similar?

Nice Mitch, It would be good to make it work also for grouped objects if this is not hard to do?


Looking for similar objects within a group or similar groups of objects…? Right now the script checks all the “normal” (visible and unlocked) objects in the document like most of the other Rhino selection commands. I suppose it could be restricted to a group of user selected objects…

To check for similar groups of objects, it’s more complicated - there needs to be another level that first checks for same sized groups and then compares all the elements in each group… Somewhat long and complicated.



So, responding to my own post, attached is another version which has one further check - if it finds polysurface volume, area, edge numbers and lengths to be identical, it collects the distance from all the edge curve start points to the object centroid, puts them in an sorted list and compares that list to the same list from the reference object. This eliminates another class of false positives as per my previous file - although there still could be some. The time penalty for this additional check is low to moderate, as it’s mostly math operations… The more edges there are in the object, the worse it will get - but only if there are a lot of almost identical objects that have the same volume, surface area, and number/length of edges.

Have at it…

–Mitch KB)


Very good job Mitch, yes I thought about similar groups of objects because I use rarely single objects, mostly grouped.


Thank you Mitch…I’m going to work with this today and see what I can come up with.



Mitch…Should this script work in R6…? It still works fine in R5, maybe I don’t have something setup right in R6. Just asking, I can keep using it in R5 if it’s too much trouble to convert.

Thank You again…


I’ll have a look tomorrow…

Edit: It seems to be working in V6 here after a quick test - is it running at all on your end, erroring out somewhere or what?



This error box comes up…



Weird, it doesn’t error out here, and the last line in your error report seems to indicate that it’s failing trying to import rhinoscriptsyntax or something… Do your other python scripts run OK? Are you running this from an alias, toolbar or from the script editor?



I just load it from the drop down…Tools…PythonScript…Run. Unless they are build into Rhino I don’t think I have any other Python scripts to try.

I running Ironpython version 2.7.3 I thought about uninstalling it and installing 2.7.5 From what I have found on the forum it works with both R5 and R6.



OK, sounds like you have a version conflict. Rhino installs its own IronPython, you don’t need to install another one in order for it to work. I guess I would first completely uninstall the python you installed yourself, then try running the script in Rhino again.



I didn’t install ironpython on my own that I know of…


Edit…Once I uninstalled 2.7.3 it works just fine.

Thank you for all your help Mitch…


Mitch…Not that it really matters but the progress bar stops around 21%…It continues and finishes so it still works just fine.