It looks like you're new here. If you want to get involved, click one of these buttons!

Hello everyone,

I am new to Klayout and I am currently learning draw Layout using python script. I have one problem that cannot fix and cannot find solution in forum. I want to rotate some polygons with respect to certain point. I want to use a region BOX to define those polygons and apply the transformation, below is my code:

def Rotation(layout,sp,box,degree,mirror=0):

r=pya.Region(box)

cp=r.bbox().center()

x=(cp.x-sp.x)-(cp.y-sp.y)

if degree==1:

y=cp.y+(cp.x-sp.x)

elif degree == 3:

y=cp.y-(cp.x-sp.x)

else:

y=cp.y

#t=pya.ICplxTrans(mag,degree,mirror,x,y)

t=pya.Trans(degree,mirror,x,y)

for polygons in r.each():

polygons.transform(t)

The code did not do anything? Appreciate if anyone could take a look and point out what wrong with the codes or is there any better way to do it?

## Comments

I could achieve the transform, but i cannot delete the original object.

the code i am using is:

Hi,

as you discovered, the angle representation is not in degree for "Trans". "Trans" is limited to rotations which are multiples of 90 degree and accepts the angle as an integer which gives multiples of 90 degree. "ICplxTrans" is the version capable of doing all-angle transformations and the angle parameter is degree.

To transform the shapes, simple use the transformation directly on the Shape object (which is a reference into the database) rather than the working objects (Polygon etc.):

This can be simplified by precomputing the transformation:

Matthias