Move RBA command into Macro

edited October 2012 in KLayout Support
For a long time now, I've used the RBA Console to capture images from KLayout to support documentation. I'd run the command:

RBA::Application.instance.main_window.current_view.save_image("E:/image.png",1000,1000)

The great part about this is that I could change the location, filename and image size however I wanted.

Now, to move this into a macro, I started with the Qt dialog sample included in the Macro Templates in the IDE. I simply edited as shown ... all I really did was insert the line:

view.save_image("E:/klay_image.png",1000,1000)

I don't yet have a strong working knowledge of Ruby, so I'd like to ask if anyone can illustrate how I can edit this to have options to set the location, filename, x size and y size of the image.

Thanks,
Jim.

module MyMacro

include RBA

# This class implements a dialog with a screenshot display area and a
# screenshot button
class ScreenshotDialog < QDialog

include RBA

def initialize(parent = nil)

super

setWindowTitle("Image Saver")

resize(400, 120)

layout = QVBoxLayout.new(self)
setLayout(layout)

@image = QLabel.new("Press the button to save an image", self)
layout.addWidget(@image)

button = QPushButton.new('Save Image', self)
button.setFont(QFont.new('Times', 18, QFont::Bold))
layout.addWidget(button)

button.clicked do
view = Application.instance.main_window.current_view
if view
view.save_image("E:/klay_image.png",1000,1000)
@image.setPixmap(QPixmap::fromImage(view.get_image(100, 100)))
else
@image.setText("No layout opened to save image from")
end
end

end

end

# Instantiate the dialog and make it visible initially.
# Passing the $main_window will make it stay on top of the main window.
$dialog && $dialog.destroy
$dialog = ScreenshotDialog.new(Application::instance.main_window)
$dialog.show

end

Comments

  • edited November 2012

    Hallo,

    I have put a macro file here: screenshot.lym.

    Please copy that file to the local macro folder (for example "~/.klayout/macros" on Linux).

    When you have installed it, you should find it under "local" macros in the macro editor.

    This macro demonstrates how to install a macro in the menu (found in "File" above the original Screenshot entry). You can edit these settings in the macro editor on the properties page after opening the macro.

    Maybe this script serves as a good example for creating own dialogs. I admit that this requires some Ruby and Qt knowledge, but not too much :-).

    Hope that helps further. Best regards,

    Matthias

  • edited November -1
    Perfect, nice example of putting all the dialogue input in one window ... it will serve me well as a working example.

    As you have grown the script/macro capability of KLayout so much over time, it might be time to start another category in the forum just for sharing and discussing macros.

    Thanks,
    Jim.
  • edited October 2012

    Hi Jim,

    done - see category "Ruby Scripting" :-)

    Matthias

  • edited November -1
    Getting images with fixed pixel width/height from a layout, independent from its content, is a useful feature.
    Many thanks for the script!

    Another task would be creating images with fixed resolution (pixel per µm), e.g. for component documentation, where the size of each component might be an important property and should be visualized by the size of the image.

    Could somebody improve the script in that direction, please?

    Peter R.
  • edited November 2012

    Hi Peter,

    I have adjusted the macro given in the link above to contain an option which computes the size based on the resolution. Here is the link once again: screenshot.lym.

    Installation instructions are given here: Useful Ruby Modules.

    Please feel free to modify the script as you like.

    Best Regards,

    Matthias

  • edited November -1
    Hello Matthias,

    many thanks for your fast response. The enhanced script works fine.

    Kind regards,
    Peter R.
Sign In or Register to comment.