It looks like you're new here. If you want to get involved, click one of these buttons!
Hi Matthias,
I'm trying to extract the coordinate of cell instace via RBA code but stucked, could you please help to figure out the problem ?
For example:
A db hierarchy is Top_Cell=>CellA=>CellB and CellC ,
I hope to extract the coordinates of CellB and CellC.
The code:
cell = layout.cell(layout.cell_by_name("CellA"))
cell.each_inst do |inst|
p = inst.trans.disp
x = p.x
y = p.y
name = inst.cell.name
puts "#{name} at #{'%.3f'%(x*dbu)}, #{'%.3f'%(y*dbu)}"
end
It would only output the coordinate related to CellA, however I hope it could output the coordinate related to Top_Cell
chhung
Comments
Hi chhung,
First of all, I'd like so suggest a new solution - not based on Ruby but on the "Layout Queries" of "Search & Replace": open "Search & Replace" from the "Edit" menu. Chose the "Custom" tab and enter this expression:
hit Execute and the left table ("Results") will fill with a list of x, y coordinates. Using the "Export" button above you can write that table to a CSV file for example.
If you want the see the results in Mikrometer units, you can modify the query:
A pure Ruby scripted solution involves recursively traversing the cell tree like this:
Matthias
Hi Matthias,
Really thanks for your sample code, I modified it to fit our requirement.
It would output all the instance coordinates start with P character, just like "P_cell ( 4107.618 , 2048.636 )
"
Tried to run the code with 1850 cells database, and it needs about 134s to complete the job.
Best Regards,
chhung
Hi,
134s may be good or bad depending on the hierarchical complexity of your layout. If the cell tree expands to a lot of effective instances, the cells traversed may become pretty big. In general, Ruby is quite efficient, but far from an optimized C++ solution. Caching may be one way to optimize it.
BTW: I noticed that the code above does not account for cell arrays. So if you are interested in the expanded instances of cell arrays, you'll need to iterate over the array locations additionally:
I wonder about the performance of the first solution based on Search & Replace. Did you try that one too?
Matthias
Hi Matthias,
Sorry to reply so late because Taiwan is in Mid-Autumn Festival.
I tried the following command in search/replace function
The run time is around 15s, must faster than search with RBA code,
however it outputs a strange result as following data(incorrect coordinates):
Correct coordinates:
And I notice that the Export => To CSV file function would try to do the query again then save to CSV file, not save the quired results to CSV file directly, is that correct ?
Best Regards,
chhung
Hi chhung,
is it mid-autumn already? I thought it's kind of late-summer to early-autumn transition ...
Sorry, just kidding :-)
Thanks for the data. The strange value like "x.ye-319" is a typical close-to-zero rounding issue. But I don't understand the differences in the coordinates. I tried in a test case of mine and found that the coordinates of the search function and the script are the same. But they come out in a different order. Maybe you are just looking at the first entries of your list? Or maybe you use an older version?
And yes: the query is run again on CSV export ... that's not necessary always, but the query will stop after having rendered more than a configurable maximum number of results (default 1000) while the CSV is rendered completely. Hence a new pass. But I agree it could be done more efficiently by reusing the existing list if it's not shortened.
Kind regards,
Matthias
Hi Matthias,
Mid-autumn Festival is one of the feasts in Taiwan, and temperature is in summer. XD
I tested two cells' name, one(cell1) is a subcell of topcell, another(cell2) is second level hierarchy of topcell.
For cell1, the y data is correct, however x is a random number. @_@a?
For cell2, the y data is incorrect, but I found it's related to cell2's parent cell, x is still a random number.
I'm trying this function with klayout v0.24.7
If I switch the klayout version to v0.23.7:
No matter cell1 or cell2 output incorrect data, x is still a random number,
and y is always 0.
Did I miss something or have a wrong command?
Best Regards,
chhung
Very weired ... you're on Windows, are you? Maybe a problem with that build. It works perfectly for me on Linux.
I'll take a look into that.
Thanks for testing,
Matthias
Hi Matthias,
I'm running klayout v0.24.7 on CentOS6(RHEL6), then I switch to klayout v0.24.5 on MDK9.2, the same problem.
CentOS6: gcc 4.4.6-3 + ruby 1.8.7-p352
MDK9.2: gcc 4.2.2-0 + ruby 1.8.7-p371
FYI.
Best Regards,
chhung