Circle example

Hi,

Thank you very much for your efforts in developing a great layout editor. I am an electrical engineer with little bit of programming experience. I need to generate a 2D array of circles for my research work. I can draw simple arrays from the interface but would like to use Ruby scripting to draw a complex array of circles. A major hurdle I am facing is the lack of simple examples. I am able to create TEXT and BOX easily following the examples. I am trying to find documentation which help me create a CIRCLE using the Basic library. I can't seem to figure out which datatypes and number of arguments to pass to the function. Hope someone can help!!

Thanks,
Naresh

Comments

  • edited January 2015
    You may want to look at the source code, there is a .cc file for this library, it is hardcoded I think.

    Best regards,
    Max
  • edited January 2015

    Hi Naresh,

    For generating circles I think that it's less effort to code a circular polygon generator than to instantiate a PCell by script.

    Here is some sample:

    n = 200    # number of points
    r = 10000  # radius
    da = 2 * Math::PI / n
    pts = n.times.collect { |i| RBA::Point.new(r * Math::cos(i * da), r * Math::sin(i * da)) }
    poly = RBA::Polygon::new(pts)
    

    Matthias

  • edited November -1
    Hi Matthias,

    Thank you very much for the quick response. I have tried it and your approach is much easier. Just a minor change - I had to prefix cos and sin functions with 'Math::'.

    Btw, is there a page where users can share their scripts so that it becomes easier for others in future?

    Naresh
  • edited November -1

    Of course you are right ... I have added to code above already. Thanks for the hint.

    And you're right about the exchange place too, but I don't have the resources to create an infrastructure for that right now. A lightweight solution would be to start a public kind of "KLayout script library" project on GitHub or SourceForge, but I'd be running out of resources if I'd try to manage that.

    Matthias

  • edited January 2015
    Matthias,

    A suggestion. I wonder if you could just create a new category on this Forum for "scripts to share" or something. Or, even better, duplicate this Forum's framework and have another, standalone, forum on this site. i.e. in the menu on the left would be "Forum" and then another entry for "Community Scripts" or something.

    People would then copy and paste their script into new posts in Markdown format. They could include a description of how to use it in text at the top. Others could reply to comment and ask questions, or make improvements. For a user to download the code, unfortunately there will be no .rb or .lym link to download but if you like the script then it is very easy to copy and paste the text into a new .rb or .lym. Indeed, select-copy-paste is what people are currently doing with this Forum, so it's no worse than the current solution, in fact better with hopefully not much effort on your part.

    I would prefer a separate forum rather than a new category on the existing Forum because then this Forum's "news feed" is preserved for questions, and so doesn't get clogged up with people posting scripts. And I believe most people use the main "news feed" and may not notice the "Categories" tab and know how to filter by category.

    The advantages of this over GitHub or SourceForge are that:
    * all KLayout resources remain in a central place (klayout.de) rather than on an external website,
    * it may not take much effort to set up,
    * people can offer questions and comments without needing to create a separate account on another website,
    * and it is easily searchable.
    The disadvantage is:
    * people are copying and pasting rather than downloading the full .rb or .lym.
    * There is no way to add a 1-5 star ranking, which would be nice in separating the wheat from the tares...

    But I still think this is best and easiest solution, sans a full-blown Matlab File Exchange - type website.

    David
  • edited November -1

    Hi David,

    you're right, but still I'd like to take a system from the shelf. Building web place myself is a lot of effort for a benefit difficult to measure. There may be better forum systems out there which I could pick.

    BTW: thanks for mentioning the FaceBook like button in your other post. Right now this feedback is not encouraging enough to spend a lot of time in improvement of this site.

    Matthias

  • edited November -1
    Hi Matthias,

    I dug around and found another off-the-shelf option as you mention. I'll create a new post, as I've hijacked this one..

    David
Sign In or Register to comment.