Returns a simulation object by ID.
Syntax
outputObject = lumapi.getObjectById(id)
Parameters
Field |
Type |
Description |
---|---|---|
id |
str |
Object ID of the target simulation object. The object ID is the fully distinguished name of the object. For example, ::model::group::rectangle If a duplicate name exists, you should 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. ::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
Field |
Type |
Description |
---|---|---|
outputObject |
Object obtained by the function. |
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 the scope is not specified
fdtd = lumapi.FDTD() fdtd.addrect() rect = fdtd.getObjectById("rectangle") print(f"{type(rect)}")
Returns
<class 'lumapi.SimObject'>
If multiple rectangles are defined, numbers can used 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
See Also
Python API overview – Ansys Optics, Lumerical Python API Reference, lumapi.getObjectbySelection, lumapi.getAllSelectedObjects