selective inherit


#1

Hi,

When inherit a variable “a” of component to another variable “b” in the upper hierarchy, can we check if the “b” exist before doing inherit?

I remember Lumerical has a “exist” function, but it is not obvious how to use it in this case.

thank you,
Zeqin


#2

Hi @zqlu

Thank you for your post. Are you talking about inherit by setting expression in script? If you are doing this manually, you won’t be able to see a variable in the Inherit list if it is not exist. If you are using script, then you can use the “exist” script command to check whether this variable exists or not. Basically it returns “0” if the variable is not exist (it returns “1” if the checking object is a variable, “2” if the checking object is a build-in function and “3” if the checking object is a script file in the current script working directory). So you can setup a flag equals to the return value of “exist” and pop out a warning/error if it is “0”. But the “exist” command does not check for pre-defined properties, so if you want to inherit a property which is not exist, there will be a system error message says that “the property … was not found”.

I hope this could help :slightly_smiling:


#3

Hi Guanhui,

Thank you for your reply.

If using setup script of component, it seems that “exist” function only checks the properties of component itself. Can we check upper upper hierarchy properties?

thank you,
Zeqin


#4

Hi @zqlu

The setup script of a component/compound can only access its own property (can access but cannot modify) and its children’s property (can access and can modify). So there is no way to check the existence of its upper upper level component’s properties. However in order to set the hierarchy structure, you have to pass the property to the current level anyway. And you will get an error message anyway if you set an expression based on a non-existence variable.

I am not so sure about your application, but I think you can check the existence in the upper level and set the setup script in the upper level using the scope sign. That will give you access to all the variables.

I hope this could help, let me know if you have other concerns :slightly_smiling: