getObjectById#

INTERCONNECT.getObjectById(id)#

Returns a simulation object by ID.

Parameters:
idstr

Object ID of the target simulation object.

The object ID is the fully distinguished name of the object.

For example,

>>> ::model::group::rectangle

If duplicate names exist, append #N to the name to unambiguously identify a single object. N is an integer identifying the Nth object in the tree with the given name.

For example,

>>> ::model::group::rectangle#3

The behavior is undefined if duplicate object names exist, and no specifier is used.

If an unqualified name is given, the group scope will be prepended to the name.

Returns:
ansys.lumerical.core.SimObject

Object obtained by the function.

See also

getObjectBySelection()

Returns the currently selected simulation object.

getAllSelectedObjects()

Returns a list of all currently selected simulation objects.

Examples

Add a rectangle and obtain it by ID.

>>> fdtd = lumapi.FDTD()
>>> fdtd.addrect()
>>> rect = fdtd.getObjectById("::model::rectangle")
>>> print(f"{type(rect)}")

Returns

>>> <class 'lumapi.SimObject'>

The same command still works even if you don’t specify the scope.

>>> fdtd = lumapi.FDTD()
>>> fdtd.addrect()
>>> rect = fdtd.getObjectById("rectangle")
>>> print(f"{type(rect)}")

Returns

>>> <class 'lumapi.SimObject'>

If multiple rectangles are defined, use numbers to specify the correct one

>>> fdtd = lumapi.FDTD()
>>> fdtd.addrect(z = 0e-6)
>>> fdtd.addrect(z = 1e-6)
>>> rect = fdtd.getObjectById("rectangle#1")
>>> rect2 = fdtd.getObjectById("rectangle#2")
>>> print(f"Rectangle 1 z position: {rect['z']}, Rectangle 2 z position: {rect2['z']}")

Returns

>>> Rectangle 1 z position: 0.0, Rectangle 2 z position: 1e-06