KLayout 0.30.7 (2026-03-06 f8646851e) [master]

API reference - Class LayoutHandle

Notation used in Ruby API documentation

Module: lay

Description: A handle to a global layout object

Layout objects shown in layout views are stored in a global repository. The layout handle is a pointer into that repository. Handles are reference counted - when no handle points to a layout, the layout is discarded. A handle stores some more information about the layout, i.e. whether it is 'dirty' (needs saving) and the options used for loading or saving the layout.

The layout handle object is useful to hold a separate reference to a layout. This way it is possible to close a layout view, but still have a reference to the layout:

You can use layout handles to move a layout to a different view for example:

cellview = ...   # the source cellview
new_view = ...   # the new target view

h = cellview.handle
cellview.close
new_view.show_layout(h, true)

Handles are named. You can use LayoutHandle#find the find a handle by name or to obtain the handle for a given layout object. You can use LayoutHandle#names to get the names of all handles registered in the system.

This class has been introduced in version 0.30.7.

Public constructors

new LayoutHandle ptrnew(string filename,
const LoadLayoutOptions options,
string technology = )
Creates a handle from a file.
new LayoutHandle ptrnew(Layout ptr layout)Creates a handle from an existing layout object.

Public methods

[const]LayoutHandle ptr_const_castReturns a non-const reference to self.
void_createEnsures the C++ object is created
void_destroyExplicitly destroys the object
[const]bool_destroyed?Returns a value indicating whether the object was already destroyed
[const]bool_is_const_object?Returns a value indicating whether the reference is a const reference
void_manageMarks the object as managed by the script side.
void_unmanageMarks the object as no longer owned by the script side.
voidassign(const LayoutHandle other)Assigns another object to self
[const]new LayoutHandle ptrdupCreates a copy of self
[const]stringfilenameGets the file name the layout was loaded from.
[const]boolis_dirty?Gets a value indicating whether the layout needs saving.
[const]boolis_valid?Gets a value indicating whether the layout handle is valid.
[const]Layout ptrlayoutGets the layout object kept by the handle.
[const]LoadLayoutOptionsload_optionsGets the load options used when the layout was read.
[const]stringnameGets the name of the layout handle.
voidname=(string arg1)Sets the name of the layout handle.
[const]intref_countGets the reference count.
voidsave_as?(string filename,
const SaveLayoutOptions options,
int keep_backups = 0)
Saves the layout to a file.
[const]variantsave_optionsGets the save options used most recently when saving the file or 'nil' if no save options are available.

Public static methods and constants

new LayoutHandle ptrfind(string name)Finds a layout handle by name.
new LayoutHandle ptrfind(const Layout ptr layout)Finds a layout handle for the given layout object.
string[]namesGets the names of all layout handles registered currently.

Deprecated methods (protected, public, static, non-static and constructors)

voidcreateUse of this method is deprecated. Use _create instead
voiddestroyUse of this method is deprecated. Use _destroy instead
[const]booldestroyed?Use of this method is deprecated. Use _destroyed? instead
[const]boolis_const_object?Use of this method is deprecated. Use _is_const_object? instead

Detailed description

_const_cast

Signature: [const] LayoutHandle ptr _const_cast

Description: Returns a non-const reference to self.

Basically, this method allows turning a const object reference to a non-const one. This method is provided as last resort to remove the constness from an object. Usually there is a good reason for a const object reference, so using this method may have undesired side effects.

This method has been introduced in version 0.29.6.

_create

Signature: void _create

Description: Ensures the C++ object is created

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

_destroy

Signature: void _destroy

Description: Explicitly destroys the object

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

_destroyed?

Signature: [const] bool _destroyed?

Description: Returns a value indicating whether the object was already destroyed

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

_is_const_object?

Signature: [const] bool _is_const_object?

Description: Returns a value indicating whether the reference is a const reference

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

_manage

Signature: void _manage

Description: Marks the object as managed by the script side.

After calling this method on an object, the script side will be responsible for the management of the object. This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. If necessary, the script side may delete the object if the script's reference is no longer required.

Usually it's not required to call this method. It has been introduced in version 0.24.

_unmanage

Signature: void _unmanage

Description: Marks the object as no longer owned by the script side.

Calling this method will make this object no longer owned by the script's memory management. Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. Technically speaking, this method will turn the script's reference into a weak reference. After the script engine decides to delete the reference, the object itself will still exist. If the object is not managed otherwise, memory leaks will occur.

Usually it's not required to call this method. It has been introduced in version 0.24.

assign

Signature: void assign (const LayoutHandle other)

Description: Assigns another object to self

create

Signature: void create

Description: Ensures the C++ object is created

Use of this method is deprecated. Use _create instead

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

destroy

Signature: void destroy

Description: Explicitly destroys the object

Use of this method is deprecated. Use _destroy instead

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

destroyed?

Signature: [const] bool destroyed?

Description: Returns a value indicating whether the object was already destroyed

Use of this method is deprecated. Use _destroyed? instead

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

dup

Signature: [const] new LayoutHandle ptr dup

Description: Creates a copy of self

Python specific notes:
This method also implements '__copy__' and '__deepcopy__'.

filename

Signature: [const] string filename

Description: Gets the file name the layout was loaded from.

If the handle was not constructed from a file, this attribute is an empty string.

find

(1) Signature: [static] new LayoutHandle ptr find (string name)

Description: Finds a layout handle by name.

If no handle with that name exists, nil is returned.

(2) Signature: [static] new LayoutHandle ptr find (const Layout ptr layout)

Description: Finds a layout handle for the given layout object.

If no handle for that layout exists, nil is returned.

is_const_object?

Signature: [const] bool is_const_object?

Description: Returns a value indicating whether the reference is a const reference

Use of this method is deprecated. Use _is_const_object? instead

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

is_dirty?

Signature: [const] bool is_dirty?

Description: Gets a value indicating whether the layout needs saving.

is_valid?

Signature: [const] bool is_valid?

Description: Gets a value indicating whether the layout handle is valid.

Invalid layout handles cannot be used. Default-created layout handles are invalid for example.

layout

Signature: [const] Layout ptr layout

Description: Gets the layout object kept by the handle.

load_options

Signature: [const] LoadLayoutOptions load_options

Description: Gets the load options used when the layout was read.

Default options will be returned when the layout was not created from a file.

name

Signature: [const] string name

Description: Gets the name of the layout handle.

The name identifies a layout handle in the global context. Names should be unique. Handles can be retrieved by name using find.

Python specific notes:
The object exposes a readable attribute 'name'. This is the getter.

name=

Signature: void name= (string arg1)

Description: Sets the name of the layout handle.

The caller is responsible for selecting a unique name for the handle. Only uniquely named handles can be retrieved by find.

Python specific notes:
The object exposes a writable attribute 'name'. This is the setter.

names

Signature: [static] string[] names

Description: Gets the names of all layout handles registered currently.

new

(1) Signature: [static] new LayoutHandle ptr new (string filename, const LoadLayoutOptions options, string technology = )

Description: Creates a handle from a file.

Loads the layout and creates a handle from that layout. The name is derived from the file name initially. You can pass load options and assign a technology using 'options' and 'technology' respectively.

Python specific notes:
This method is the default initializer of the object.

(2) Signature: [static] new LayoutHandle ptr new (Layout ptr layout)

Description: Creates a handle from an existing layout object.

Creates a layout handle for an existing layout object. The ownership over the layout object is transferred to the handle.

Python specific notes:
This method is the default initializer of the object.

ref_count

Signature: [const] int ref_count

Description: Gets the reference count.

The reference count indicates how many references are present for the handle. If the reference count reaches zero, the layout object is destroyed. References are kept by layout views showing the layout, but can also be kept by separate handles.

save_as?

Signature: void save_as? (string filename, const SaveLayoutOptions options, int keep_backups = 0)

Description: Saves the layout to a file.

filename:The path where to save the layout to
options:The options used for saving the file
keep_backups:The number of backup files to keep (0 for 'no backups')

This method will save the layout kept by the handle to the given file. Calling this method will change the file name and reset the is_dirty? flag and set save_options to the options passed.

save_options

Signature: [const] variant save_options

Description: Gets the save options used most recently when saving the file or 'nil' if no save options are available.