Ruby shape operations

edited June 2013 in Ruby Scripting
Thanks Matthias for a very useful piece of software! I was looking to do an equivalent operation to the 'Selection'->'Flip..' or 'Selection'->'Rotation...' with Ruby script commands. Specifically I would like to flip or rotate a select number of geometrical primitives in a cell, but not necessarily all of them. Is this possible using a Ruby script?


  • edited June 2013

    Hi ronm,

    Yes, that is possible. The key to that functionality is the method "Shapes#transform(shape, transformation)". The "transformation" is an affine transformation of class "Trans" which can represent a flipping or rotation operation. "shape" is a "Shape" object representing the database object that you want to transform and "Shapes" is the container where that object is contained in (inside the database a single layer of a single cell).

    Give you have obtained a Shape object, you can use code like this to transform a shape:

    shape = ... # a Shape object
    trans = RBA::Trans::new(RBA::Trans::R0)  # mirror at X axis, no displacement
    shape.shapes.transform(shape, trans)

    You can obtain the shape objects for the current selection from the layout view by using a code like this:

    view = RBA::Application::instance.main_window.current_view # Current layout view 
    view.each_object_selected do |inst|
      shape = inst.shape

    There are a couple of pitfalls. You'll have to check whether the object selected is a cell instance rather than a shape. Shapes may be selected inside child cells which implies the possibility of multiple instances being selected at the same time etc.

    Please also note that the above code works in Editor mode only.

    Unless you have some experience already I'd strongly suggest to have a look at the introduction docs, i.e. for more details about the database API.



  • edited November -1
    Thanks for the quick help! As you can tell I'm still figuring out the ins and outs of the Ruby interface but it has been very useful so far. Regards,

Sign In or Register to comment.