fix(layers): use KiCad 9 API for add_layer
board.GetLayerStack() was removed in KiCad 9. Call SetLayerName and SetLayerType directly on the board instead, and grow the copper layer count via SetCopperLayerCount when adding inner layers. Without this, add_layer raises AttributeError on any KiCad 9 installation.
This commit is contained in:
@@ -39,9 +39,6 @@ class BoardLayerCommands:
|
|||||||
"errorDetails": "name, type, and position are required",
|
"errorDetails": "name, type, and position are required",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get layer stack
|
|
||||||
layer_stack = self.board.GetLayerStack()
|
|
||||||
|
|
||||||
# Determine layer ID based on position and number
|
# Determine layer ID based on position and number
|
||||||
layer_id = None
|
layer_id = None
|
||||||
if position == "inner":
|
if position == "inner":
|
||||||
@@ -64,12 +61,16 @@ class BoardLayerCommands:
|
|||||||
"errorDetails": "position must be 'top', 'bottom', or 'inner'",
|
"errorDetails": "position must be 'top', 'bottom', or 'inner'",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set layer properties
|
# Enable inner copper layers by increasing copper layer count (KiCAD 9.0 API)
|
||||||
layer_stack.SetLayerName(layer_id, name)
|
if position == "inner":
|
||||||
layer_stack.SetLayerType(layer_id, self._get_layer_type(layer_type))
|
current_count = self.board.GetCopperLayerCount()
|
||||||
|
needed_count = 2 + number # F.Cu + B.Cu + inner layers
|
||||||
|
if needed_count > current_count:
|
||||||
|
self.board.SetCopperLayerCount(needed_count)
|
||||||
|
|
||||||
# Enable the layer
|
# Set layer properties directly on board (GetLayerStack removed in KiCAD 9.0)
|
||||||
self.board.SetLayerEnabled(layer_id, True)
|
self.board.SetLayerName(layer_id, name)
|
||||||
|
self.board.SetLayerType(layer_id, self._get_layer_type(layer_type))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|||||||
Reference in New Issue
Block a user