It looks like you're new here. If you want to get involved, click one of these buttons!
Trying to make a tool that will merge polygons horizontally or vertically, so the first step I wanted to take is to get the currently selected polygons, and their information (coordinates of points/corners, layername/data/type).
I've tried reading, but since I don't know Ruby, and most of the documentation is written for Ruby with no Python substitute... I'm left relatively confused.
Here's as far as I've got... able to print the list of layers available... but don't know how to discriminate which are selected and which are not (even though this doesn't matter, it seems like a simple API feature that /should/ exist... but I just couldn't figure it out.
Later I try to print the current layer list
, but it shows empty... as does the selected_cells_paths
.
import pya
import pprint
import inspect
print('\n\nStarting KLayout Script')
c=pya.CellView.active().layout()
lv = pya.LayoutView.current()
sl = lv.selected_layers()
cll = lv.current_layer_list
if sl:
sll = []
while not sl[0].at_end():
sll.append(sl[0].current())
sl[0].next()
print(f'selected layer(s): {[(s.name, s.visible, s.marked) for s in sll]}')
else:
print('Nothing in "Layers" list is currently selected')
print(f'current layer list: {cll}')
print(f'selected_cells_paths: {lv.selected_cells_paths(0)}')
print(f'selection bounding-box: {lv.selection_bbox()}')
Comments
I made some progress, I can print the coordinates of each rectangular polygon:
Have you tried this: https://www.klayout.de/doc-qt5/programming/python.html ?
Traversing the selected layers is complicated by the potential presence of multiple layouts. So this is a way to traverse the layers in the layer list in the general case:
If you're looking for selected objects on selected layers you need to check if
o.cv_index
is one of the selected layer'scellview
values ando.layer
is one of the selected layer'slayer_index
values.So as you're basically able to retrieve the polygons, what are you trying to implement next?
Matthias