Design and Development of Sheet-Metal Elbows Using Programming with Visual Basic for Applications in CATIA

: This article introduces an innovative application of Visual Basic for Applications (VBA) (Visual Basic macro language) developed in CATIA (Computer-Aided Three-Dimensional Interactive Application), computer-aided manufacturing and engineering design software. Said application enables the three-dimensional (3D) representation and development to be obtained on a plane of the surfaces of cylindrical and conical elbows utilised to join two conduits, since CATIA lacks tools for the design of elements of metal fabrication. The application permits the geometric and dimensional parameters necessary for the creation and development of the analysed elbows to be introduced via a keyboard. Once these values have been entered and it has been veriﬁed that the design of the elbow is possible, then the application is programmed within the CATIA “Wireframe and Surface Design” module to obtain the 3D representation of said elbows, and the development of their surface is projected in the CATIA “Drafting” module. Consequently, the incorporation of this tool into CATIA software could increase technical-design productivity by eliminating certain intermediate operations, such as symmetry, and through improving the geometry training of less skilled users.


Introduction
Advances in engineering graphics, as a fundamental part of the computer-aided design process, are ongoing [1], as are the advances in the use of computer-aided design (CAD) techniques in the geometric modelling process [2][3][4].
One of its main applications involves obtaining the development stamped onto metal sheet (metal fabrication) to form surfaces that can be used in industry; subsequently and by means of computer-aided manufacturing (CAM) software, this stamped development can be adapted to cutting machines using computer numerical control (CNC).
Metal fabrication is the branch of the industry in which the most diverse constructions are made in metal or in metallic alloys, from sheets of various shapes and thicknesses. It is subdivided into three large sectors depending on the thickness of the sheet or plate used and the dimensions of the profiles: light, medium, and heavy metal fabrication, and consists of the manufacture and assembly of conduits and containers used in the storage and conduction of aggregates and fluids [5].
The most common elements are cylindrical and polygonal conduits, concentric and eccentric reductions, adapter surfaces, hoppers, and elbows. These can be classified into two groups: developable and warped surfaces (parts). The first are those that can be extended on a single plane to obtain the form of the material before shaping; the latter are those that cannot be extended on a plane and, therefore, are obtained by approximate drawing methods, and require special shaping operations such as embossing, stamping, and pumping.

•
Galileo [13] This is a vertical application designed to trace the developments of the most commonly used elements (hoppers, elbows, bifurcations, and various cuts by planes, among others) in the metal fabrication industry. This application works entirely within the AutoCAD and MicroStation environment, with an AutoCAD drawing file (.dwg) output format and can be exported by means of an interchange file (neutral file) (.dxf).
In this way, by means of a plotter output, either an optical copier is employed to automatically generate the cutting path, or this file can be sent to a numerical control machine for greater automation.

•
Lantek Expert [14] This is a powerful module for the automatic tracing of sheet-metal elements. It includes an extensive library of parameterised figures that follow DIN and SMACNA standards (hoppers, cones, cylinders, elbows, etc.), where practically all the elements used can be found.
This tool integrates a two-dimensional (2D) CAD module for the design of any part, as well as for the geometric modification of the drawings. Lantek Expert also enables cutting or punching the development of the figure based on flanges, notches, and fold lines for marking.
This module connects with many CAD systems through a variety of formats (such as .dwg), or via neutral files (such as .dxf and .iges).
• LITIO 2.0 [16] This is a design software that obtains the development in sheet metal (with metals such as iron, stainless steel, brass, copper, and aluminium) of multiple metal fabrication elements. It is a program for AutoCAD/GStarCAD and is used to design hoppers, cyclones, conduits, silos, tubes, air conditioning, ventilation and heating installations, dust-extraction installations, and transport systems. This is manufacturing software for metal fabrication designs. The result can be exported in neutral format (.dxf) to the machining software of a numerical control machine. The design can also be printed on a 1:1 scale to create a template or to obtain a table of points to mark directly onto a metal plate to be cut with a manual machine. It has an extensive library with almost 200 elements.
First, the user selects the element to trace and enters its dimensions. Likewise, parameters are established such as sheet thickness, separation for cutting, type of joint, and the construction parameters: type of development and number of bending lines.
The software then analyses the coherence of the values entered and reports on any inconsistencies. The outputs it provides include the 3D view, the design to optimise the material, the design to align joins, templates, measurements, and design dimensioning.
Having carried out the review, it was revealed that none of said software applications has been programmed in the CATIA (Computer-Aided Three-Dimensional Interactive Application) environment, which is one of the most widely used commercial computeraided design, manufacturing and engineering software. Hence, the convenience and originality of this research lies in including this environment for the manufacture of sheetmetal elbows.
This research makes it possible to underline the importance of the application developed both from a commercial and educational point of view, since it could be used for CAD teaching purposes in design-related schools and institutions worldwide. Consequently, the incorporation of this tool into CATIA could increase technical-design productivity by eliminating certain intermediate operations, such as symmetry, and by improving the geometry training of less skilled users.
The remainder of the paper is structured as follows: Section 2 presents the sheet-metal elbows. Section 3 shows the materials and methods used in this investigation. Section 4 includes the main results and discussion, while Section 5 states the main conclusions.

Sheet-Metal Elbows
Undoubtedly, one of the numerous and most important examples that can be shown in metal fabrication involves the elbows or union of two conduits. For example, when their axes cross and a change of direction is produced, this can be carried out directly by extending the conduits until they intersect.
However, if the angle between the axes of the conduits is not very large, then this construction is not feasible since blockages, load losses, and hydraulic shock could occur when aggregates or fluids circulate. Therefore, in the majority of cases, it is decided to place one or more intermediate parts (ferrules) that aid circulation. The set of these intermediate parts is called an elbow, and for economic reasons, said elbow is made with the least number of ferrules possible.
The elbows can be cylindrical or conical, depending on whether the conduits to be joined are cylinders of the same diameter or of different diameters, respectively and, whenever possible, they will be resolved by cylinders and cones of revolution [18].

Cylindrical Elbow
The theoretical foundation for the resolution of this type of elbow is based on the possibility of obtaining the number of parts necessary for the construction of the elbow from the same cylinder ( Figure 1). Although cylindrical elbows can be solved by means of revolution cylinders or by oblique cylinders with a circular base, it is more advisable to use revolution cylinders due to their easy construction, despite the drawback that none of the parts of the elbow are the same size. The oblique cylinder with a circular base, however, has the drawback of its constructional difficulty, despite the fact that all the parts of the elbow are of the same size [18]. the parts of the elbow are the same size. The oblique cylinder with a circular base, however, has the drawback of its constructional difficulty, despite the fact that all the parts of the elbow are of the same size [18]. If said cylinder is cut by a vertical projecting plane ( ′) that passes through half its height, then the cylinder will be divided into two parts (I and II). If the upper part (IIg) is rotated so that both parts are symmetrical with respect to the projecting plane, then it can be observed that the angle formed by the axes of both parts is: Likewise, it can be observed that between the part (II) and its rotated part (II ) there is an axial symmetry with respect to an axis perpendicular to the cutting plane that passes through the intersection point of the axes (O′). Therefore, the angle (θ) formed by the planes of the circular openings is supplementary to the angle formed by the axes: Either of expressions (1) or (2) enable the calculation of the angle of inclination of the cutting plane ′ in order to obtain a two-part elbow whose axes form angle or whose circular openings form angle θ.
Furthermore, it is verified that the development of a cylindrical elbow can be obtained from a single cylinder of revolution of height ℎ, by cutting it across a vertical projecting plane ( ′) that passes through the midpoint of its axis, thereby forming angle with said axis.
To this end, starting from a rectangular metal sheet of dimensions (2 ) × (ℎ), it is cut by the transform of the section of the plane ′ (a sine curve), and the sheet is then rolled to the diameter of the cylinder (Figure 2). If said cylinder is cut by a vertical projecting plane (α ) that passes through half its height, then the cylinder will be divided into two parts (I and II). If the upper part (II g ) is rotated so that both parts are symmetrical with respect to the projecting plane, then it can be observed that the angle ω formed by the axes of both parts is: Likewise, it can be observed that between the part (II) and its rotated part (II g ) there is an axial symmetry with respect to an axis perpendicular to the cutting plane that passes through the intersection point of the axes (O ). Therefore, the angle (θ) formed by the planes of the circular openings is supplementary to the angle ω formed by the axes: Either of expressions (1) or (2) enable the calculation of the angle of inclination β of the cutting plane α in order to obtain a two-part elbow whose axes form angle ω or whose circular openings form angle θ.
Furthermore, it is verified that the development of a cylindrical elbow can be obtained from a single cylinder of revolution of height h, by cutting it across a vertical projecting plane (α ) that passes through the midpoint of its axis, thereby forming angle β with said axis.
To this end, starting from a rectangular metal sheet of dimensions (2πR) × (h), it is cut by the transform of the section of the plane α (a sine curve), and the sheet is then rolled to the diameter of the cylinder (Figure 2).

Conical Elbow
This type of elbow is used to join two cylindrical conduits that present different diameters. Conical elbows are always solved by cones of revolution of the same conicity, either by the procedure of circumscribed traverse elbows (the elbow elements are different sizes) or inscribed traverse elbows (the elbow elements are of the same height).
The procedure for drawing circumscribed polygonal elbows ( Figure 3) consists, as in the case of a circumscribed cylindrical elbow, of dividing the angle formed by the planes of the circular openings (δ) by twice the number of ferrules (n) minus two: Finally, the tangents to these spheres are drawn, thereby obtaining the apparent contour of the elbow, and in this way, through the intersections of the generatrices of the cone trunks, the ferrules are obtained [18].

Conical Elbow
This type of elbow is used to join two cylindrical conduits that present different diameters. Conical elbows are always solved by cones of revolution of the same conicity, either by the procedure of circumscribed traverse elbows (the elbow elements are different sizes) or inscribed traverse elbows (the elbow elements are of the same height).
The procedure for drawing circumscribed polygonal elbows ( Figure 3) consists, as in the case of a circumscribed cylindrical elbow, of dividing the angle formed by the planes of the circular openings (δ) by twice the number of ferrules (n) minus two: Subsequently, a truncated cone is built whose height is the perimeter of the polygon and the diameter of the conduits as the bases. Through the points (O' 1 , O' 2 , O' 3 ), spheres are drawn inscribed onto the truncated cone of radii (R 1 , R 2 , R 3 ).
Finally, the tangents to these spheres are drawn, thereby obtaining the apparent contour of the elbow, and in this way, through the intersections of the generatrices of the cone trunks, the ferrules are obtained [18].
It is observed that the development of the conical elbow can be obtained from the surface of the single truncated cone (Figure 4).  It is observed that the development of the conical elbow can be obtained from the surface of the single truncated cone (Figure 4).

Cylindrical Elbows
In order to explain the steps necessary to draw and develop a cylindrical elbow, an elbow of 90° formed of 4 ferrules has been chosen as an example [19]. Figure 5 shows the various steps to follow. In order to create the design, it is necessary to first draw the inlet and outlet of the conduits to be connected.

Design
In Figure 5a, it can be observed that the horizontal and vertical distances between the centres of the two conduits are not equal, and therefore the elbow is extruded through the opening of conduit 2 until an arc can be traced that is tangent at the midpoint of both conduits.
In accordance with Equation (3), the angle between the two conduits (90°) is divided into twice the number of ferrules (4) minus two, resulting in an angle of 15°.
In Figure 5b, the six divisions needed to draw the elbow can be observed. Note that auxiliary lines perpendicular to the equal divisions of the 90° angle have also been drawn, which represent the axes of the ferrules; these will be used later.
Finally, in Figure 5c, the last step, which consists of extending the conduits to the divisions, is observed, thereby forming the 4 ferrules, and obtaining the final result of the elbow. The inlet and outlet conduits are extended to their first division and form simple ferrules. However, the two intermediate ferrules are drawn parallel to the axes described above and are considered to be double ferrules due to the fact that they each contain two divisions.  In order to explain the steps necessary to draw and develop a cylindrical elbow, an elbow of 90 • formed of 4 ferrules has been chosen as an example [19]. Figure 5 shows the various steps to follow. In order to create the design, it is necessary to first draw the inlet and outlet of the conduits to be connected.

Design
In Figure 5a, it can be observed that the horizontal and vertical distances between the centres of the two conduits are not equal, and therefore the elbow is extruded through the opening of conduit 2 until an arc can be traced that is tangent at the midpoint of both conduits.
In accordance with Equation (3), the angle between the two conduits (90 • ) is divided into twice the number of ferrules (4) minus two, resulting in an angle of 15 • .
In Figure 5b, the six divisions needed to draw the elbow can be observed. Note that auxiliary lines perpendicular to the equal divisions of the 90 • angle have also been drawn, which represent the axes of the ferrules; these will be used later.
Finally, in Figure 5c, the last step, which consists of extending the conduits to the divisions, is observed, thereby forming the 4 ferrules, and obtaining the final result of the elbow. The inlet and outlet conduits are extended to their first division and form simple ferrules. However, the two intermediate ferrules are drawn parallel to the axes described above and are considered to be double ferrules due to the fact that they each contain two divisions.

Development
At this stage, we proceed to explain how to develop said cylindrical elbow on the plane, by using the necessary metal sheet for its construction ( Figure 6).
First, the conduit inlet is drawn, and the semicircle is divided into eight equal parts, that is, it is divided into eight angles of 22.5° each (Figure 6a). On the other hand, a rectangle is drawn, which represents the sheet necessary for the manufacture of the elbow, whose base is the length of the circumference and whose height is the same as that of the complete cylinder. This sheet is divided with vertical lines into 16 equal parts; only the first 8 divisions are shown, however, since the right-hand side will be symmetrical to the left-hand side. For clarification, the height of the cylinder (H) is obtained as the sum of all the segments of the axes of the ferrules.
Subsequently, vertical lines are drawn from the divisions of the semicircle to the cut between the first and second ferrules, and these points are projected horizontally onto the divisions made on the sheet (Figure 6b).
These last intersection points are then joined, thereby forming the design of the joint between the first two ferrules. It should be borne in mind that by increasing the number of divisions of the circumference, a greater number of points would be obtained and, therefore, greater precision in the design.

Development
At this stage, we proceed to explain how to develop said cylindrical elbow on the plane, by using the necessary metal sheet for its construction ( Figure 6).
First, the conduit inlet is drawn, and the semicircle is divided into eight equal parts, that is, it is divided into eight angles of 22.5 • each ( Figure 6a). On the other hand, a rectangle is drawn, which represents the sheet necessary for the manufacture of the elbow, whose base is the length of the circumference and whose height is the same as that of the complete cylinder. This sheet is divided with vertical lines into 16 equal parts; only the first 8 divisions are shown, however, since the right-hand side will be symmetrical to the left-hand side. For clarification, the height of the cylinder (H) is obtained as the sum of all the segments of the axes of the ferrules.
Subsequently, vertical lines are drawn from the divisions of the semicircle to the cut between the first and second ferrules, and these points are projected horizontally onto the divisions made on the sheet (Figure 6b).
These last intersection points are then joined, thereby forming the design of the joint between the first two ferrules. It should be borne in mind that by increasing the number of divisions of the circumference, a greater number of points would be obtained and, therefore, greater precision in the design.
Once that part of the design has been drawn, the rest can be obtained thanks to symmetry. In this way, it can be deduced that the design of the subsequent ferrules will be symmetrical with respect to the dividing lines of the arc, that is to say, if these lines are projected onto the metal sheet, then the rest of the design can be obtained (Figure 6c). Once that part of the design has been drawn, the rest can be obtained thanks to symmetry. In this way, it can be deduced that the design of the subsequent ferrules will be symmetrical with respect to the dividing lines of the arc, that is to say, if these lines are projected onto the metal sheet, then the rest of the design can be obtained ( Figure 6c).
Finally, the same procedure is repeated until the design of all the ferrules is obtained. In Figure 6d, the final result of the development of this cylindrical elbow is shown, and the shape of the metal sheet of each of the ferrules can be appreciated.

Conical Elbows
In this section, the same procedure will be carried out to explain the design and development of a conical elbow [19]. As an example, a 90° conical elbow with 4 ferrules has been selected, whose inlet conduit is twice the diameter of the outlet conduit. Design In Figure 7, the different steps to follow can be observed. Actually, it is the application of the method of bitangent spheres that determine elements constituted by cones of revolution, and which is based on the property that two equal cones of revolution tangent to the same sphere, can be made to coincide by turning the ellipse section 180° on its same plane, around its centre.
In the auxiliary construction where the truncated cone of revolution which axis is equal to the sum of the sides of the polygonal formed by opening 1 + A + B + C + opening 2 and which base are the diameters of opening 1 and 2 has been drawn, then the spheres of centres A, B and C inscribed in it are drawn. It is evident that the four ferrules belong to the truncated cone since they are circumscribed to the spheres of centres A, B and C. Finally, the same procedure is repeated until the design of all the ferrules is obtained. In Figure 6d, the final result of the development of this cylindrical elbow is shown, and the shape of the metal sheet of each of the ferrules can be appreciated.

Conical Elbows
In this section, the same procedure will be carried out to explain the design and development of a conical elbow [19]. As an example, a 90 • conical elbow with 4 ferrules has been selected, whose inlet conduit is twice the diameter of the outlet conduit. Design In Figure 7, the different steps to follow can be observed. Actually, it is the application of the method of bitangent spheres that determine elements constituted by cones of revolution, and which is based on the property that two equal cones of revolution tangent to the same sphere, can be made to coincide by turning the ellipse section 180 • on its same plane, around its centre.
In the auxiliary construction where the truncated cone of revolution which axis is equal to the sum of the sides of the polygonal formed by opening 1 + A + B + C + opening 2 and which base are the diameters of opening 1 and 2 has been drawn, then the spheres of centres A, B and C inscribed in it are drawn. It is evident that the four ferrules belong to the truncated cone since they are circumscribed to the spheres of centres A, B and C. For this reason, the common mouths of the ferrules can be made to coincide by turning them 180 • and so on until obtaining the truncated cone.
Likewise, the sides of the polygonal (opening 1 + A + B + C + opening 2) will coincide with the axes of the cones, as they are the lines that join the centres of the spheres inscribed in them.
For this reason, the common mouths of the ferrules can be made to coincide by turning them 180° and so on until obtaining the truncated cone.
Likewise, the sides of the polygonal (opening 1 + A + B + C + opening 2) will coincide with the axes of the cones, as they are the lines that join the centres of the spheres inscribed in them.
Steps to follow when designing a 90° conical elbow with four ferrules.
In Figure 7a, it can be appreciated how these conduits are positioned. In this case, the horizontal and vertical distances between the centres of the two conduits are equal, and hence neither conduit requires extrusion.
As in the case of the cylindrical elbow, the arc that joins the two conduits is divided into angles of 15° (3), thereby drawing the auxiliary lines perpendicular to the equal divisions of the angle.
As explained previously, these lines represent the axes of the ferrules, and therefore, they are transferred to construct the truncated cone with bases the diameters of the conduits (Figure 7b).
Inscribed circumferences are subsequently drawn on the truncated cone at points A, B, and C, in such a way that the diameter of the inscribed circumferences on the ferrules is obtained. In the next step, these circumferences are transferred to the centres B' and C', so that the ferrules can be drawn. In Figure 7a, it can be appreciated how these conduits are positioned. In this case, the horizontal and vertical distances between the centres of the two conduits are equal, and hence neither conduit requires extrusion.
As in the case of the cylindrical elbow, the arc that joins the two conduits is divided into angles of 15 • (3), thereby drawing the auxiliary lines perpendicular to the equal divisions of the angle.
As explained previously, these lines represent the axes of the ferrules, and therefore, they are transferred to construct the truncated cone with bases the diameters of the conduits (Figure 7b).
Inscribed circumferences are subsequently drawn on the truncated cone at points A, B, and C, in such a way that the diameter of the inscribed circumferences on the ferrules is obtained. In the next step, these circumferences are transferred to the centres B' and C', so that the ferrules can be drawn.
In Figure 7c, it can be observed that the inscribed circumferences have been transferred and that the tangent lines between them have also been drawn. After tracing these lines, drawing can start on the ferrules by simply joining the intersection points between the tangent lines.
Finally, the same procedure is carried out for the remaining ferrules, thereby obtaining the conical elbow (Figure 7d).

Development
In this section, it is explained how to develop said conical elbow on the plane, given the necessary metal sheet for its construction (Figure 8). On this occasion, the elbow comes from a truncated cone, and not from a cylinder as in the previous case. Therefore, the development to be obtained will not be on a rectangle, but instead will be obtained on the surface of a truncated cone.
In Figure 7c, it can be observed that the inscribed circumferences have been transferred and that the tangent lines between them have also been drawn. After tracing these lines, drawing can start on the ferrules by simply joining the intersection points between the tangent lines.
Finally, the same procedure is carried out for the remaining ferrules, thereby obtaining the conical elbow (Figure 7d).

Development
In this section, it is explained how to develop said conical elbow on the plane, given the necessary metal sheet for its construction (Figure 8). On this occasion, the elbow comes from a truncated cone, and not from a cylinder as in the previous case. Therefore, the development to be obtained will not be on a rectangle, but instead will be obtained on the surface of a truncated cone. First, the truncated cone is drawn by transferring the construction of the drawing (Figure 8a). First, the truncated cone is drawn by transferring the construction of the drawing (Figure 8a).
Subsequently, in a similar way to the case of the cylindrical elbow, a semicircle of the largest diameter is drawn and divided into 4 equal parts, that is, at 45 • angles.
On the other hand, the vertex (V) of the cone is obtained by prolonging the generatrices. This vertex is transferred towards point V", and the development is created on the plane of the truncated cone, by dividing it into 8 equal parts (Figure 8b).
In the next step (Figure 8c), the divisions of the semicircle are projected vertically onto the base, and then to the vertex of the cone. The intersection points that are produced with the separations between the ferrules are projected horizontally up to the development of the cone. These last intersection points are joined to form the development of the joint between the ferrules.
Finally (Figure 8d), the same procedure is followed and the symmetry regarding the central generatrix of the development of the cone is employed in order to obtain the development of the ferrules of the conical elbow.

Programming Environment with Visual Basic for Applications (VBA)
Microsoft Visual Basic (VB) is an event-driven programming language, developed by Alan Cooper for Microsoft, while Microsoft VBA (Visual Basic for Applications) is the macro language for Microsoft Visual Basic. Its main utility is to automate daily tasks, and to create applications and database services for the desktop.
In 1998, CATIA, in the V5 version, incorporated VBA into its environment, and was able to carry out macros in Visual Basic [20] and in the C++ language; these remain the macro programming languages available in the V6 version.
A macro consists of a series of functions written in a programming language that groups together a series of commands that allow the required operations to be carried out automatically.
The use of macros for automation in the design process is practically unlimited. Examples thereof include the import of points from Excel to a 3D CAD model, the automatic generation of geometries, and the creation of 3D model drawings, among others.
As indicated, CATIA V5 has the ability to work in the VBA environment. This can be carried out from any module by opening the "Tools" tab, where the "Macro" option appears, within which it is possible to start recording a macro or access the macros already created, and to access libraries or the Visual Basic editor [20].
CATIA macros are stored in macro libraries in one of three ways: Folders (vbscript and CATScript); Project files (catvba); or as documents such as CATParts, CATProducts, and CATDrawings. Only one of these three macro libraries can be used at a time.
In this way, the CATScript files will be saved in the library created. This only needs to be carried out once, and from then on, the library remains loaded even after restarting CATIA [18].
One method of creating macros is to record actions performed with the mouse. For macros recorded in a file, in a CATpart or CATproduct, the declared statements (instructions containing mathematical operators, variables, constants, expressions, loops, functions, and sub-functions) will be recorded for CATScript, but not for MSVBscript. However, macros cannot be recorded using CATIA 'Drafting' module.
In the present investigation, all the codes have been carried out using the option to develop macros that CATIA V5 presents, that is, by means of the Visual Basic editor [20].

Work Environment
In order to start on the code, the work environment is first set to CATIA. In this way, a new element Part can be initiated directly from the application. The necessary statements are the following: Dim documents1 As Documents Set documents1 = CATIA.Documents Dim partDocument1 As PartDocument Set partDocument1 = documents1.Add("Part") Dim part1 As Part Set part1 = partDocument1.Part A new document, the PartDocument object, is created with the Documents object, which enables the CATIA 'Wireframe and Surface Design' module to be activated and, finally, the file where the elbow will be designed is created with the Part object. Subsequently, the Symmetry 2021, 13, 33 13 of 23 operations tree is defined where all the operations and objects that are created in the file will be reflected. In this way, the Bodies object is established and within it a Body is defined.

Definition of Sketch
In order to start drawing any part in CATIA, a sketch on the plane must first be made to later generate the part in 3D.
The Sketch is created within the previous Body and the reference system refers to where the Sketch is to be located. Subsequently, the directions that form the Sketch plane are indicated with a matrix.

Constraints
Once the geometric elements have been drawn in the Sketch, it is necessary to leave all the elements well-defined and fixed, so that nothing can be altered when introducing any other element. This is achieved by setting Constraints.
In order to establish a constraint, it is first necessary to reference the objects to be set, and once the references have been defined, a command is executed that relates them to each other. Commands can relate one, two, and up to three different references to each other.

CATIA 'Wireframe and Surface Design' Module
This section explains the CATIA 'Wireframe and Surface Design' module, which contains all the tools necessary for the generation of wireframe geometry and basic surfaces.
Surfaces are elements called HybridBodies and are found within the Part schema. Within the HybridBodies, the HybridShapeFactory objects are defined, which are those that contain all the tools necessary to work with surfaces.
The main tools for working with surfaces are: Extrude (which creates the surface through the extrusion of a sketch); Revolve (which creates a surface of revolution through a revolved axis and a sketch); Offset (which creates a surface displaced with respect to another surface); Fill (which creates a surface from contours); Multi-section Surface (which creates an extruded surface through various sections and guides); Join (which joins surfaces, thereby creating a global surface); and Split (which removes parts of a surface from an intersection).
Since elbows in metal fabrication can only be designed by extruding a circumference through an axis, the only surface tools used are Extrude and Multi-section Surface. The lines of code for these two tools are:

Extrude
With this tool, a surface can be made by defining only the Sketch to be extruded, the direction, and the required dimension.
First, the direction of the extrusion is determined. In this case, the direction of the normal of Plane.1 is taken, it is referenced, and, with the AddNewDirection command, the direction is assigned.

Multi-Section Surface
With this tool, surfaces can be made by means of an extrusion, and the profile can be varied along this extrusion. To this end, it is only necessary to provide the different Sketches and the guides through which the extrusion is carried out.

Hierarchical Structure of the Application
The application has a hierarchical structure composed of two parts: one part is the main graphical interface, and the other is the part that corresponds to the lines of code necessary to perform all the actions.
Likewise, from a functional point of view, the application is divided into two main blocks: one corresponding to the cylindrical elbows and the other to the conical elbows. Each of these blocks is, in turn, subdivided into two different actions: the creation of the 3D model of the corresponding elbow, and the creation of the 2D sheet-metal development for its construction. Figure 9 shows the graphical interface of the application, which allows a choice between the options of creating either a cylindrical elbow or a conical elbow.

Graphical Interface
Each of these blocks is, in turn, subdivided into two different actions: the creation of the 3D model of the corresponding elbow, and the creation of the 2D sheet-metal development for its construction. Figure 9 shows the graphical interface of the application, which allows a choice between the options of creating either a cylindrical elbow or a conical elbow.

Cylindrical Elbow
If the "Cylindrical Elbow" option is selected, then the corresponding form is displayed ( Figure 10). This form contains: five Text Boxes that correspond to the input parameters necessary to draw the cylindrical elbow (to be entered manually in the text boxes); an Image which is an illustrative sketch to facilitate the compression of the parameters; and two Command Buttons, called "Create 3D model" and "Create development". Moreover, to the left and right of the Text Boxes there are Labels; those on the left symbolize the input parameters, and those on the right, where appropriate, represent the units corresponding to these parameters.

Cylindrical Elbow
If the "Cylindrical Elbow" option is selected, then the corresponding form is displayed ( Figure 10). This form contains: five Text Boxes that correspond to the input parameters necessary to draw the cylindrical elbow (to be entered manually in the text boxes); an Image which is an illustrative sketch to facilitate the compression of the parameters; and two Command Buttons, called "Create 3D model" and "Create development". Moreover, to the left and right of the Text Boxes there are Labels; those on the left symbolize the input parameters, and those on the right, where appropriate, represent the units corresponding to these parameters. As can be observed, in order to create a cylindrical elbow, five input parameters are necessary: : diameter of inlet conduit and outlet conduit (must be the same). : horizontal distance between the centres of the inlet and outlet conduits. : vertical distance between the centres of the inlet and outlet conduits. Regarding the lines of code, the first line is the same as that in the previous section, As can be observed, in order to create a cylindrical elbow, five input parameters are necessary: D: diameter of inlet conduit and outlet conduit (must be the same). H: horizontal distance between the centres of the inlet and outlet conduits.
V: vertical distance between the centres of the inlet and outlet conduits. θ: angle between the inlet and outlet of the elbow. Range of application [5 • −180 • ]. Number of ferrules. Range of application [2−8].
Regarding the lines of code, the first line is the same as that in the previous section, since it is the command that enables the code to be executed upon a single click, and the parameters and the program code are subsequently designated.

End Sub
On executing the action "Create 3D model", the application creates a cylindrical elbow in 3D ( Figure 11) using the CATIA "Wireframe and Surface Design" module, which complies with the parameters designated. As can be observed, in order to create a cylindrical elbow, five input parameters are necessary: : diameter of inlet conduit and outlet conduit (must be the same). : horizontal distance between the centres of the inlet and outlet conduits. : vertical distance between the centres of the inlet and outlet conduits. θ: angle between the inlet and outlet of the elbow. Range of application [5°−180°]. Number of ferrules. Range of application [2−8].
Regarding the lines of code, the first line is the same as that in the previous section, since it is the command that enables the code to be executed upon a single click, and the parameters and the program code are subsequently designated.

End Sub
On executing the action "Create 3D model", the application creates a cylindrical elbow in 3D ( Figure 11) using the CATIA "Wireframe and Surface Design" module, which complies with the parameters designated.  In order to create the sheet-metal development of the cylindrical elbow, and due to the difficulty in programming Visual Basic directly in the CATIA "Drafting" module, the "Part Design" module has been used to first program the development of the elbow in a Sketch and to later project it to the CATIA "Drafting" module. To this end, it is necessary to activate the "Project 3D wireframe" option within the 'Properties' option.
The result of this operation is automatically displayed in a drawing ( Figure 12).

Conical Elbow
In the case of selecting the "Conical Elbow" option, the corresponding form will be displayed automatically (Figure 13). The interface is very similar to that of the Cylindrical Elbow and has the same elements in the form, but with an additional parameter, since there are two different diameters: the diameter of the inlet conduit (D1), and the diameter of the outlet conduit (D2).
In order to create the sheet-metal development of the cylindrical elbow, and due to the difficulty in programming Visual Basic directly in the CATIA "Drafting" module, the "Part Design" module has been used to first program the development of the elbow in a Sketch and to later project it to the CATIA "Drafting" module. To this end, it is necessary to activate the "Project 3D wireframe" option within the 'Properties' option.
The result of this operation is automatically displayed in a drawing ( Figure 12).

Conical Elbow
In the case of selecting the "Conical Elbow" option, the corresponding form will be displayed automatically (Figure 13). The interface is very similar to that of the Cylindrical Elbow and has the same elements in the form, but with an additional parameter, since there are two different diameters: the diameter of the inlet conduit (D1), and the diameter of the outlet conduit (D2). In order to make a conical elbow, six input parameters are required: 1: diameter of the inlet conduit (larger diameter of the conical elbow). 2: diameter of the outlet conduit (smaller diameter of the conical elbow).

Conical Elbow
In the case of selecting the "Conical Elbow" option, the corresponding form will be displayed automatically ( Figure 13). The interface is very similar to that of the Cylindrical Elbow and has the same elements in the form, but with an additional parameter, since there are two different diameters: the diameter of the inlet conduit (D1), and the diameter of the outlet conduit (D2). In order to make a conical elbow, six input parameters are required: 1: diameter of the inlet conduit (larger diameter of the conical elbow). 2: diameter of the outlet conduit (smaller diameter of the conical elbow). When executing the action "Create 3D model", the application creates a conical elbow in 3D (Figure 14) using the "Wireframe and Surface Design" module, which complies with the designated parameters.
In order to create the development of the metal sheet for the conical elbow, as with the development of the cylindrical elbow, it was decided to program directly in the CATIA "Part Design" module.
In the first place, the development is programmed in a Sketch and it is subsequently projected onto the "Drafting" module.
: horizontal distance between the centres of the inlet and outlet conduits. : vertical distance between the centres of the inlet and outlet conduits. θ: angle between the inlet and outlet of the elbow. Range of application [5° and 180°]. Number of ferrules. Range of application [2−8].
When executing the action "Create 3D model", the application creates a conical elbow in 3D (Figure 14) using the "Wireframe and Surface Design" module, which complies with the designated parameters. In order to create the development of the metal sheet for the conical elbow, as with the development of the cylindrical elbow, it was decided to program directly in the CATIA "Part Design" module.
In the first place, the development is programmed in a Sketch and it is subsequently projected onto the "Drafting" module.
The result of this operation is automatically displayed in a drawing ( Figure 15).  The result of this operation is automatically displayed in a drawing ( Figure 15).
bow in 3D ( Figure 14) using the "Wireframe and Surface Design" module, which complies with the designated parameters. In order to create the development of the metal sheet for the conical elbow, as with the development of the cylindrical elbow, it was decided to program directly in the CATIA "Part Design" module.
In the first place, the development is programmed in a Sketch and it is subsequently projected onto the "Drafting" module.
The result of this operation is automatically displayed in a drawing ( Figure 15).

Analysis of Possible Errors
Obviously, it is not possible to give any value to the input parameters, since, for example, an elbow cannot be designed by introducing negative values in the diameter of the conduits. For this reason, it may be the case that when entering a value that lies outside the range or some combination of values with which it is impossible to design the elbow, the application automatically displays an error message that indicates the reason. These errors are shown through a pop-up window that appears when any of the Command Buttons are pressed.
Therefore, a series of error warnings have been programmed in the internal code of each of the Command Buttons. These lines of code are placed immediately after the input parameter designation code.
All the error messages programmed in the application are laid out below.

Angle between the Inlet and Outlet Openings of the Elbow between 5 • and 180 •
The input parameter (θ) represents the angle between the inlet and outlet openings of the elbow. This parameter has been programmed with a range of possible values between 5 and 180 sexagesimal degrees.
It is considered that an elbow of more than 180 • has little application in the metal fabrication sector, and that if it were necessary to design such an elbow, it could be built by joining two elbows of smaller angles.
Elbows with an angle of less than 5 • are not considered, since the two conduits could be joined by a single ferrule, with which their construction would be easier, and the pressure loss would not be much greater.

Number of Ferrules between 2 and 8
The parameter of the number of ferrules designates the number of parts that are employed to build the elbow. In a metal fabrication elbow, the number of ferrules is defined by an integer number of parts, which has a minimum value of two ferrules and could ideally have an infinite number of ferrules (although this would not make sense).
The UNE-EN 10224 [21] standard states: angular elbows with an angle θ ≤ 30 • must be built using two ferrules; elbows with an angle between 30 • < θ ≤ 60 • , with three ferrules; and those with an angle between 60 • < θ ≤ 90 • must have four ferrules. Therefore, since the range of application of the elbow angle is defined up to 180 • , this parameter has been programmed to have a range of application comprised between a minimum of two to a maximum of eight ferrules.

Diameter D1 Must Be Greater Than Diameter D2
As can be perceived, this error only has an effect in the case of the conical elbow, since this is the one that joins two conduits of different diameters.
The application has been programmed in such a way that diameter D1 will always be the diameter corresponding to the opening with the largest diameter in the conical elbow. Therefore, if a value is entered in the input parameters that does not comply with the D1 > D2 relationship, then this error message is automatically displayed.

Unable to Create Elbow
Entering parameter values and trying to run a command may trigger the appearance of an error message, since, with the set of values entered, it may be physically impossible to construct a conical or cylindrical elbow.
There are several situations in which this error can occur.

Case 1
The dimension parameters of the diameters must be positive values. Obviously, the elbow cannot be constructed if any of these diameters has a negative value or is equal to zero. Therefore, the following relationship must be fulfilled: D > 0 (cylindrical elbow) or D1 > 0; D2 > 0 (conical elbow) Furthermore, the elbow will always be considered to develop towards the right. In other words, the parameter of the horizontal distance is also always going to be greater than zero (H > 0). Specifically, it is programmed that if any of these variables is negative or equal to zero, then the error message is automatically displayed, and the Exit Sub command is executed to exit the application. The code is shown below: If CInt(D) <= 0 Or CInt(H) <= 0 Or CInt(V) <= 0 Then MsgBox "Unable to create elbow" Exit Sub End If

Case 2
Another condition that must be met to design the elbow is that the lines of the axes of the inlet and outlet conduits have to intersect at a point with a positive Y coordinate ( Figure 16). than zero ( > 0). Specifically, it is programmed that if any of these variables is negative or equal to zero, then the error message is automatically displayed, and the Exit Sub command is executed to exit the application. The code is shown below: Another condition that must be met to design the elbow is that the lines of the axes of the inlet and outlet conduits have to intersect at a point with a positive Y coordinate (Figure 16). As can be observed in the case on the right, the intersection point of the two axes occurs below the first opening, which is the opening that marks the negative Y coordinate.
Making use of basic trigonometry and the parameters defined for the application, it can be deduced that the necessary relationship to fulfil this condition is: where the variable Y is the value of the Y coordinate at the intersection point of the two axes. When programming, the same loop as in Case 1 is used. The only difference is the conditioner of the loop, that is, Equation (4).

Case 3
In this case, the relative position between the inlet and outlet openings must be fulfilled (Figure 17), that is, point B must be located further to the right than point A. As can be observed in the case on the right, the intersection point of the two axes occurs below the first opening, which is the opening that marks the negative Y coordinate.
Making use of basic trigonometry and the parameters defined for the application, it can be deduced that the necessary relationship to fulfil this condition is: where the variable Y is the value of the Y coordinate at the intersection point of the two axes. When programming, the same loop as in Case 1 is used. The only difference is the conditioner of the loop, that is, Equation (4).

Case 3
In this case, the relative position between the inlet and outlet openings must be fulfilled (Figure 17), that is, point B must be located further to the right than point A. As in the previous case, in order to deduce the relationship that is required to fulfil this condition, it has been based on basic trigonometry and on the parameters defined.
Thus, Equation (5) fulfils the condition that the X coordinate of point B must be greater than the X coordinate of point A. When programming, the same loop is used as in Case 1. The only difference is the conditioner of the loop, that is, Equation (5). As in the previous case, in order to deduce the relationship that is required to fulfil this condition, it has been based on basic trigonometry and on the parameters defined.
Thus, Equation (5) fulfils the condition that the X coordinate of point B must be greater than the X coordinate of point A. When programming, the same loop is used as in Case 1. The only difference is the conditioner of the loop, that is, Equation (5).

Case 4
This situation occurs when the radius of rotation of the elbow, R, is less than the radius of the inlet or outlet conduit (Figure 18). As in the previous case, in order to deduce the relationship that is required to fulfil this condition, it has been based on basic trigonometry and on the parameters defined. Thus, Equation (5) fulfils the condition that the X coordinate of point B must be greater than the X coordinate of point A. When programming, the same loop is used as in Case 1. The only difference is the conditioner of the loop, that is, Equation (5).

Case 4
This situation occurs when the radius of rotation of the elbow, R, is less than the radius of the inlet or outlet conduit (Figure 18). As can be deduced, if said radius of rotation R is less than the radius of the inlet or outlet conduit, then the application would be aborted. As in the previous case, based on basic trigonometry and on the parameters defined, the relationship is defined as: 1/2 cos (90 − ) + − 1 2 * tan (90 − ) > When the left-hand side of Equation (6) is equal to parameter V, then the radius of rotation R is equal to the radius of the inlet conduit of the elbow. When programming, the same loop is used as in Case 1. The only difference is the conditioner of the loop, that is, Equation (6). As can be deduced, if said radius of rotation R is less than the radius of the inlet or outlet conduit, then the application would be aborted. As in the previous case, based on basic trigonometry and on the parameters defined, the relationship is defined as: When the left-hand side of Equation (6) is equal to parameter V, then the radius of rotation R is equal to the radius of the inlet conduit of the elbow. When programming, the same loop is used as in Case 1. The only difference is the conditioner of the loop, that is, Equation (6).

Conclusions
This article has described the process of drawing, rendering in 3D, and developing cylindrical and conical sheet-metal elbows (the most commonly used in industry), thanks to the development of an application developed in VBA for CATIA. Likewise, this application could, from an educational point of view, be useful as a tool in university teaching. Indeed, the application is designed to be used as a didactic resource in the first university year of the industrial engineering career.
The principal motivation has been that CATIA, which is one of the high-level software most used in large areas of engineering, such as aeronautics and the automotive industry, possesses no specific tools for the design of elements of metal fabrication.
The application allows the introduction by keyboard of the geometric and dimensional parameters necessary for the design and development of the elbows analysed and has been programmed to include the analysis of the various possible errors.
Once these values have been entered, and it has been verified that the design of the elbow is indeed plausible, then the CATIA "Wireframe and Surface Design" module has been employed to obtain the 3D model of the elbow, since these elements are built from surfaces.
Likewise, in order to obtain the development of the surfaces of the various ferrules that comprise the elbow, the same module has been used. The complete development has subsequently been projected in the "Drafting" module, since working directly on this module was not possible due to the impossibility of programming in Visual Basic.
As a continuation of this line of research, future lines of development arise for the improvement and expansion of this application, such as the design and development of hoppers and adapter surfaces.