Array selected objects

edited July 2013 in Ruby Scripting
Hi Matthias,
I get stuck with arraying selected objects (mostly polygons) in scripting. It should work like the "Make Array" function in /Edit/Selection/. Could you please help on giving a scripting example? Thank you so much.

Best regards,
Tsann-Bim

Comments

  • edited November -1

    Hi,

    what exactly are you stuck at?

    Matthias

  • edited November -1
    Hi Matthias,
    Sorry, let me explain little bit clearly. Before doing arraying, I made a new cell (I call it "unitcell") that contains certain polygons selected by using a clip function. Now, I wanna array all the polygons in unitcell and make a new cell for the arrayed polygons. I feel the "Make Array" function in /Edit/Selection/ menu pretty fit my requirement. But I don't know how to make it in scripting. So here I have 2 fundemantal problems-
    1. how to select the polygons (like the mouse does)?
    2. how to array the selected polygons?
    Or, you might have another way to do it?

    Thank you so much.
    Tsann-Bim
  • edited July 2013

    Hallo,

    The "make array" function is not readily available for scripting. To be more precise: the scripting feature does not map the capabilities of the user interface but that of the layout database. In the user interface, the code behind the "make array" function is basically creating multiple copies of the selection with a increasing displacement.

    To implement that function in Ruby, you don't necessarily need to have a selection. Since you already have the shapes inside the unitcell you can easily create an array of those shapes by creating a cell atop of your unitcell, i.e.

    ly = ... # the layout
    unitcell_index = ... # cell index of the unitcell
    
    arraycell_index = ly.add_cell("ARRAY")
    arraycell = ly.cell(arraycell_index)
    
    nx = ... # number of columns
    dx = ... # column pitch
    ny = ... # number of rows
    dy = ... # row pitch
    arraycell.insert(RBA::CellInstArray::new(unitcell_index, RBA::Trans::new, 
                     RBA::Point::new(dx, 0), RBA::Point::new(0, dy), nx, ny)
    

    That will create a two-level hierarchy in a new cell "ARRAY" and employ a cell instance array (aka "AREF") to effectively produce the regular array.

    If you want to get rid of the hierarchy you can flatten the new arraycell in order to have all shapes inside that cell:

    ly.flatten(arraycell_index, -1, false)
    

    (if you want to remove the unitcell in that step, use "true" for the last argument)

    That is different from the implementation inside the "make array" function but it is very efficient.

    Regards,

    Matthias

  • edited November -1
    Hi Matthias,
    It works well. Thank a lot for guiding me the array scripting. Your comments are always helpful...

    Regards,
    Tsann-Bim
Sign In or Register to comment.