-
Notifications
You must be signed in to change notification settings - Fork 22
Description
In HFSSdrawpy.core.modeler.Modeler.set_variable, the "hack" to auto-name variables assumes the python code lives inside a file, so when the code is tested inside a shell, an error occcures.
The error message is
File "........\modeler.py", line 79, in set_variable
code_line = open(filename).readlines()[f.f_lineno - 1]
Which isn't very usefull
I suggest the following changes for the function Modeler.set_variable
def set_variable(self, value, name=None):
"""
name (str): name of the variable in HFSS e.g. 'chip_length', only optionnal if used inside a .py script
value (str, VarStr, float): value of the variable
if str will try to analyse the unit
"""
if name is None:
# this auto-parsing is clearly a hack and not robust
# but I find it convenient
f = currentframe().f_back # .f_back
filename = getfile(f)
if filename != '<stdin>':
code_line = open(filename).readlines()[f.f_lineno - 1]
name = code_line.split("=")[0].strip()
else:
raise ValueError("Please provide a name for the variable, automatic naming only works in .py scripts")
if self.mode == "hfss":
self.design.set_variable(name, value) # for HFSS
symbol = sympy.symbols(name)
store_variable(symbol, value)
return symbolAdding just an if statement and corecting the documentation
I didn't made tests for .ipynb, I'll leave it to whoever has the time to do it (I dont have a setup for this)
Thanks to whoever take the time to correct this minor issue
Acknowledgement : this is more a Pull Request than an open issue, but I don't have the permission to create a branch and I'm not very fluent with Giuhub (for yet ?)