RhinoScript - CompareGeometry

I don’t seem to be able to get the CompareGeometry to work in either Rhino 7 or the WIP. I’ve copied the example script from the help file and compared one shape with its exact copy and it’s always False. Has anyone had better luck with that? It seems like it should be quite simple.

1 Like

Hi @Steve_Crow,

Can you post a 3dm file with the geometry you are trying to compare?

Thanks,

– Dale

1 Like

Hi Dale,

Thanks for getting back. It’s not for a specific drawing. I simply copied a rectangle and then compared them using the script in the CompareGeometry help page. I then tried various other objects comparing them to their immediate copies. And, as I said before, they always comes up False.

Are you using the code from this page?

https://developer.rhino3d.com/api/RhinoScriptSyntax/#geometry-CompareGeometry

This code works as expected for me when I do as you’ve described. If this is the code you’re using and it is not working as expected:

  • post a 3dm file with the geometry you are using
  • post a python file with the code you are using

-Kevin

I’m working in RhinoScript and this is straight out of the help file.

Dim strObject1, strObject2, bCompare

strObject1 = Rhino.GetObject("Select first object to compare")
If Not IsNull(strObject1) Then
	strObject2 = Rhino.GetObject("Select second object to compare")

	If Not IsNull(strObject2) Then
		bCompare = Rhino.CompareGeometry(strObject1, strObject2)
		If bCompare = True Then
			Rhino.Print "Objects are geometrically identical."
		Else
			Rhino.Print "Objects are not geometrically identical."
		End If
	End If
End If

I’m not sure how to add a drawing file to this but my simplest test is just a rectangle and its copy. If that script above works for you then there must be something strange going on here.

Thanks for your attention.

I was using RhinoScriptSyntax (python) when I tried this earlier, but running the VB code you posted from the script editor in Rhino also works as expected for me.

While you are editing your post, click the upload button then select your 3dm file.

-Kevin

Upload button - got it.

I guess there’s just something weird about this computer or this particular Rhino installation. It’s certainly not essential to anything I’m doing but it would have been nice. Thanks very much for taking the time.

Hi @Steve_Crow,

The CompareGeometry function, which is also used by Rhino’s SelDup command is limited in that the geometry must match exactly. This can be difficult when dealing with float point issues, such as rounding errors.

If you create something within normal proximity of the world origin and then copy it in place (with the Copy command, then the function should work. But admittedly, it’s not the most robust as it does not us any tolerance to compare values.

– Dale

Okay… it seems the “in place” is a crucial factor here. I assumed the geometry was identical even separated. It’s more like “Compare Geometry and Location”. To me, two squares are identical in geometry if they have the same dimensions, even if one is in the Andromeda galaxy. It might be worth adding that clarification to the description in the help page. Otherwise, this is fabulous software and I’m enjoying the learning even after 20 years.

Thank you so much.