14.4 Declaring Python variables

In the main code section of a Python script, we write the primary executable code that performs the core tasks and orchestrates the flow of the program. It’s the central part of the script that implements its purpose and functionality and ensures that the desired tasks are carried out in the desired sequence. We will begin writing this part of the code by initializing the variables necessary to start working in the active document and defining the geometry in the next stage:

 

#initialization of qwm_doc

qwm_doc = App.ActiveDocument

 

#variable initialization

add_variables(qwm_doc)

 

#assignment of QW-Parameters

ir = qwm_doc.QW_Vars.ir.Value

isl = qwm_doc.QW_Vars.isl.Value

dr0 = qwm_doc.QW_Vars.dr0.Value

l0 = qwm_doc.QW_Vars.l0.Value

twi = qwm_doc.QW_Vars.twi.Value

cwi = qwm_doc.QW_Vars.cwi.Value

cdl = qwm_doc.QW_Vars.cdl.Value

ncor = qwm_doc.QW_Vars.ncor.Value

anc = qwm_doc.QW_Vars.anc.Value*math.pi/180

 

#additional dependent variables

dr0c = dr0*(-1)

if(dr0>0):

dr0c=0

 

cdh=cdl+(twi+cwi)/math.tan(anc);

 

Initialization of qwm doc: we initialize the qwm doc variable to reference the active document in FreeCAD using qwm_doc = App.ActiveDocument. This step ensures that the subsequent code interacts with the correct document, enabling seamless access to project variables and geometry.

Variable Initialization: we call a function add_variables(qwm_doc) to add and initialize variables within active QW-Modeller document. After this part of the code is executed, these variables are available in QW-Parameters dock window, in QW-Modeller GUI.

Assignment of QW-Parameters: In this step, we assign Python variables to QW-Parameters that are essential for the corrugated horn design. Since QW-Parameters are combination of a floating point number and Unit (Quantity), we refer to their value assigning them to Python variables.

Declaration of Dependent Variables: After initializing Python variables that match the provided parameters, we proceed to declare additional dependent variables. These variables are calculated based on the initial parameters.