WasteOptimiser icon indicating copy to clipboard operation
WasteOptimiser copied to clipboard

AttributeError: 'Polygon' object has no attribute 'shape_nfps' in addShapeAsHole()

Open supersuperfranz opened this issue 6 months ago • 1 comments

I am encountering an AttributeError when using optimiser.addShapeAsHole(). The error indicates that the Polygon object being processed does not have the shape_nfps attribute, suggesting it's a standard shapely.geometry.Polygon object rather than the extended WasteOptimiser Polygon class.

Full Traceback:

File "c:\Users\francesco.tripaldi\Desktop\dxf2gcode\nest_dialog.py", line 169, in run_nesting placements = self.run_nesting_from_contours(self.contours) File "c:\Users\francesco.tripaldi\Desktop\dxf2gcode\nest_dialog.py", line 130, in run_nesting_from_contours self.api.placeAllSelectedShapes() File "c:\Users\francesco.tripaldi\Desktop\dxf2gcode\WasteOptimiser\wasteoptimiser\api\api.py", line 114, in placeAllSelectedShapes if not self.placeSelectedShape(): File "c:\Users\francesco.tripaldi\Desktop\dxf2gcode\WasteOptimiser\wasteoptimiser\api\api.py", line 98, in placeSelectedShape self.optimiser.addShapeAsHole(self.selected_shape_name) File "c:\Users\francesco.tripaldi\Desktop\dxf2gcode\WasteOptimiser\wasteoptimiser\optimiser\spaceoptimiser.py", line 262, in addShapeAsHole
newhole.shape_nfps = defaultdict() AttributeError: 'Polygon' object has no attribute 'shape_nfps' (Note: Line number 262 is where the attribute assignment is attempted.)

Steps to Reproduce:

Initialize the WasteOptimiser API.

Attempt to place shapes using self.api.placeAllSelectedShapes() or directly call self.optimiser.addShapeAsHole() with any valid shape.

Expected Behavior:

The addShapeAsHole method should successfully process the shape, and the newhole object should be an instance of the custom WasteOptimiser Polygon class, possessing the shape_nfps attribute.

Actual Behavior:

An AttributeError occurs because the newhole object is a standard shapely.geometry.Polygon, which lacks the shape_nfps attribute. This happens even when self.optimiser.convex_hull is set to False, indicating a more fundamental issue with the Polygon object instantiation within WasteOptimiser.

Environment:

Operating System: Windows11

Python Version: 3.8.7, 3.9.13, 3.11.9, 3.13.8

Thank you for your time.

supersuperfranz avatar Jul 07 '25 20:07 supersuperfranz

@supersuperfranz please see this answere here: https://github.com/Papooch/WasteOptimiser/issues/26#issuecomment-2712979466

Papooch avatar Jul 22 '25 14:07 Papooch