# BIM-Based Optimization of Drilling Angle and Hole Position of Outside Corner Anchor Rods
## 4 Case Study
### Program Scripts
#### 4.4.3 Borehole Location Optimization  
The process of optimizing borehole locations is similar to that of optimizing borehole dip angles. The core script modules are different, and the four script modules--data input and extraction, borehole location optimization, collision detection, and data output--need to be comprehensively used. In the execution of program script three under Dynamo's automatic mode, the first-side anchor rod model, the second-side anchor rod model, the path of the collision report optimization form, the hole adjustment value, and the number of rows for data entry in the Excel table are selected. The Select Model Element node is employed to select the anchor rod models, while the File Path node reads the path of the \"Outside Corner Anchor Collision Report Optimization Form\". The Number Slider node is used to set the hole adjustment value, with a national standard allowing a maximum of 100 mm, a minimum of 0 mm, and a slider step size of 1 mm. The integer for the number of rows in the \"Outside Corner Anchor Collision Report Optimization Form\" is defined. The Element.GetParameterValueByName node retrieves the initial hole offset value, and the Code Block node is used to set a formula that calculates the new hole offset value based on the angle adjustment value. The Element.SetParameterByName node assigns the new hole offset value to the family instance. The Revit model is converted to Dynamo software using the Element.Geometry node. Since the anchor rods are generated using multiple modeling commands, the Solid.ByUnion node is used to combine each anchor rod model. The Geometry.Does Intersect node is employed to assess the occurrence of lateral anchor rod collisions, resulting in a Boolean value. This value is then converted into a collision string using the If node. The Watch node enables real-time visualization of the anchor rod collision results in automatic mode. The Code Block node sets a formula to calculate the range for angle adjustment optimization. The following program is written using the Python Script node:  
if IN[0] == 0:  
OUT = str(\"\")  
elif IN[0] > 0:  
OUT = str(\"[\"+str(int(IN[0]))+\",\"+str(100)+\"]\")  
else:  
OUT = str(\"[\"+str(-100)+\",\"+str(int(IN[0]))+\"]\")  
The program utilizes conditional statements to convert the result into the correct string format for the optimized angle adjustment range. The summarized data are imported into the \"Outside Corner Anchor Collision Report Optimization Form\" using the Data.ExportExcel node. As is the case with the borehole dip optimization process, the range allowed for adjusting the borehole location according to the national standard is not limited by the program. It can be adjusted according to actual needs and the instruments used to ensure the accuracy and authenticity of the results. The collision results of anchor bolts can still be viewed in real time in Dynamo's automatic mode. Figure 13 shows a comparison of anchor bolt collisions before and after optimization. Before optimization, there were collisions between the two side anchors, as shown with the red circles indicating the locations of the collision points. After optimization, all collision points within the red circles disappeared, and there were no longer any collisions present. The optimized results can also be viewed in the table, as shown in Table 3.  
The obtained results of the \"Specific Range of Allowed Inclination Angle of the Optimized First-Side Anchor Rod Outside Corner (\({}^{\circ}\))\" include specific numerical intervals, such as [17; 18], [18; 18], [26; 28], and textual output denoting \"Not calculated\". These numerical intervals demonstrate the adjustable permissible range of drilling angles achieved after optimization. The angles of the first-side anchors are adjusted downward, resulting in larger specific numerical intervals compared to the original angles. The textual output for the fifth-row anchor is due to the absence of collision, rendering optimization unnecessary for the drilling angle.