matching a cq shape with same shape after exporting and importing from STEP/Brep file

41 views
Skip to first unread message

drshi...@gmail.com

unread,
Jan 7, 2023, 5:24:11 PM1/7/23
to CadQuery
Hi all

I'm just trying to find a shape in a file by using the hashCode or isEqual or isSame or any other method

I have made a shape in Cq then export it to a STEP or Brep file then I load the file and get the shape back again.

I compare the hashCode of the two shapes and their faces and they are different.
I used the shape.isSame and shape.isEqual methods to compare the original shape and the same shape loaded from the STP file and they both return false.

I'm looking for a way of keeping track of these shapes while exporting and importing them. Perhaps I have misunderstood the scope of these methods. Here is a minimal example that I hope would print out the same hash code twice and then True , True but it does the opposite.

In my real use case my Brep file (with merged faces) ends up containing many shapes and I'm trying to keep track of the through out a process.

Many thanks

Jon

```
import cadquery as cq
from cadquery import exporters

result = cq.Workplane().box(10, 10, 10)
original_shape = result.val().Solids()[0]

exporters.export(result, 'test.step')

result_round_trip = cq.importers.importStep('test.step')
shape_from_round_trip = result_round_trip.val().Solids()[0]

print(shape_from_round_trip.hashCode())
print(original_shape.hashCode())
print(original_shape.isEqual(shape_from_round_trip))
print(original_shape.isSame(shape_from_round_trip))
```

Adam Urbanczyk

unread,
Jan 13, 2023, 2:59:59 AM1/13/23
to CadQuery
Hey,

you could store custom metadata (say hash or a custom ID) using OCAF when exporting. It is currently not implemented and it will require extending CQ, but it is doable. I'm not sure if the hash is preserved on an export-import round-trip. You might need to invent your own hashing function.

HTH
Reply all
Reply to author
Forward
0 new messages