14.3 Adding User Variables (QW Vars Object)

Here, all the variables such as dimensions of the structure, that we suspect we would like to change during the design process should be defined. The dimensions of the corrugated horn, which will be implemented as parameters, have been presented in the drawings below.

Figure 2: Half of long section

Figure 3: Obtained solid

Figure 4: Obtained solid

 

In the function definition section of a Python script, we define custom functions that encapsulate specific pieces of code or logic. These functions serve as reusable blocks of code that can be called from the main code section. We create custom functions using the def keyword followed by a function name, a parameter list (if any), and a colon.

The addition of User Variables to the project will be carried out through the Python function add variables(qwm doc), which takes the active document as its argument.

def add_variables(qwm_doc):

PropertiesList = qwm_doc.QW_Vars.PropertiesList

if not ("anc" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’anc’, 45, ’Angle of the cone’,App.Units.Unit(’’))

if not ("cdl" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’cdl’, 5, ’Corrugation depth’,App.Units.Unit(’’))

if not ("cwi" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’cwi’, 5, ’Corrugation width’,App.Units.Unit(’’))

if not ("dr0" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’dr0’, 0, ’Matching sec. radius step’,App.Units.Unit(’’))

if not ("ir" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’ir’, 12, ’Input radius’,App.Units.Unit(’’))

if not ("isl" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’isl’, 20, ’Input segment length’,App.Units.Unit(’’))

if not ("l0" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’l0’, 10, ’Matching sec. length’,App.Units.Unit(’’))

if not ("ncor" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’ncor’, 9, ’Number of corrugations’,App.Units.Unit(’’))

if not ("twi" in PropertiesList):

qwm_doc.QW_Vars.addVariable(’twi’, 1, ’Tooth width’,App.Units.Unit(’’))

 

Each of the parameters has its name, default value, description, and unit. If a given variable does not already exist in the project, it will be added to a project with defined above default value. In opposite case, the value of an existing variable will not be changed.