Set the layer a shape is on

edited August 2013 in Ruby Scripting

Hi,

I'm trying to select a shape (polygon, box,...) on any GDS layer and then run a .lym script. The desired result is that the shape changes GDS layer to be on (e.g.) GDS Layer 1.

However I can't find any methods to set the GDS layer.

I looked in the docs in Shape, Polygon, Box, etc - and can't find any methods to set the GDS layer number.

How is this done?

Thanks!

Comments

  • edited August 2013

    Never mind, figured out how to do it. I duplicated the box and added it to the same cell. Then can erase the original box if desired.

    I was surprised - it seems a good feature to have would be a "layer=" method within Box, Polygon, etc, whereby you could set the layer. But this works too.

    module ConvertSelectionToSpecifiedLayer
    
      app = RBA::Application.instance
      mw = app.main_window
    
      lv = mw.current_view
      if lv == nil
        raise "No view selected"
      end
    
      lv.transaction("Convert selection to specified layer")
      begin
    
        result_cell=[]
        output_layer=[]
    
        desiredGDSOutputLayer = 1 # default
        desiredGDSOutputLayer = RBA::InputDialog.get_int("Convert to layer", "Convert to which GDS output layer?",desiredGDSOutputLayer )
        desiredLayer = Float(desiredGDSOutputLayer.to_i)
    
        lv.each_object_selected do |obj|
    
          shape = obj.shape
          layout = lv.cellview(obj.cv_index).layout
    
          result_cell = layout.cell(obj.cell_index)
    
          lnum = desiredLayer # GDS Layer number
          dtnum = 0
          output_layer = layout.layer_indices.find do |li|
            info = layout.get_info(li)
            info.layer == lnum && info.datatype == dtnum
          end
    
          new_shape = obj.shape.dup
          result_cell.shapes(output_layer).insert(new_shape)
    
        end
    
        ensure 
        lv.commit
      end
    end
    
  • edited November -1

    Hi David,

    thanks .. I would like to comment, but it will take a few days.

    Regards,

    Matthias

  • edited November -1

    Hi David,

    I got some time now ...

    Having a layer= method actually is a good suggestion. It's the OO style of thinking - but behind the scenes that method has to be mapped to code very similar to the one you presented above.

    But your code does not delete the original shapes, does it? That is actually creating some interference, because a shape can (through the hierarchy) be selected many times in different ways of instantiation. And moving away one shape will then render the other selections of that shape invalid. "shape.shapes.is_valid?(shape)" is a solution for that. It will return true if the shape has been modified already and the modification has to be skipped in that case.

    Frankly, I don't quite understand why you wrote a script for that functionality. "Edit/Selection/Change Layer" should be available already. You'll just have to select the shapes and the target layer in the layer list.

    Regards,

    Matthias

  • edited November -1

    Thanks for the very helpful reply.

    • Since this has turned from a question to a feature request :) -- then I suppose I would mention that it would be helpful to have methods to set and to get the layer index (.layer and .layer=), methods to set and get the GDS layer number, which may or may not correspond to the layer index, (.gds_layer and .gds_layer=, or something), and similar for GDS datatype (.dt_layer and .dt_layer= or something). So I think each of these six is useful. And perhaps one for CIF layer name get/set. Though I agree it is relatively easy for the user to code it themselves too.

    • No it doesn't delete the shapes and yes this does result in interference under certain conditions - thanks for the tip on checking if the shape is invalid.

    • I agree, this functionality is available in Edit/Selection/Change Layer -- but the reason for a script is, this is part of a larger script so I needed to "Ruby-ize" it...

    Thanks,
    David

  • edited November -1

    Hi David,

    there is a good reason for separating GDS layer/datatype and layer index - there is not necessarily a correspondence between both. Layers can be temporary (no GDS layer), there are file formats without layer numbers, just names (CIF, DXF) and it's even possible to assign identical GDS layer/datatype numbers to different layers. The layer index is a unique identifier while the GDS layer/datatype is an annotation. So it's something different.

    And thanks for the explanation about the script. I just wanted to make sure the built-in feature was not too deeply hidden :-)

    Matthias

  • edited November -1

    Regarding layer index being a unique identifier and GDS layer/datatype being an annotation -- Understood and agreed. This is a smart way and the only way to do it I think.

    But I still think the get/set methods are still just as useful even with that understanding. They could just return nil if no GDS layer/datatype is set, for instance, and it's up to the coder to handle that case.

Sign In or Register to comment.