Alexandru PINTILIE, Elena-Rita AVRAM
CONSIDERATIONS ON OBJECT-ORIENTED PROGRAMMING ENVIRONMENT
                          AUTOCAD DRAWINGS
      Abstract: In recent years, Low Cost CAD systems are widespread in the technical world. Currently, the
      highest-rated CAD system is AutoCAD due to the fact that in association with AutoLISP programming
      language covered a broad range of production needs.
      As a high-level programming language, AutoLISP provides an easy and efficient programming technique
      that leads to automation and parameterization of AutoCAD commands and reduces the time spending for
      designing the drawings.
      This paper aims to highlight the advantages of using AutoLISP programming environment in the 2D drafting
      and 3D modeling using AutoCAD tools.
      Key words: AutoCAD, AutoLISP, function, programming, automation, parameterization.
1. INTRODUCTION                                             menu bar by the succession of command "Tools> Load
                                                            Application ...> Load> name_file.lsp".
    A CAD system has to provide to the user the                In Table 1 is illustrated the AutoLISP program syntax
possibility to implement its own executable functions       which draws standardized format A4 (210x297).
(routines) via a programmable interface.
    Autodesk chose AutoLISP programming environment                                                         Table 1
due to the following advantages [1]:                           Syntax AutoLISP program for drawing standardized
 Storing and manipulating lists, and therefore the                          format A4 (210x297)
  coordinates of points;                                     Line                 AutoLISP program
 Possibility of adding new features;                          1    (DEFUN C:A4()
                                                               2    (GETSTRING "Outer contour draw of the format A4
 Direct dialing of all AutoCAD functions without the
                                                                    (210,297). <Enter>")
  building of other functions.                                 3    (COMMAND "RECTANG" "0,0" "210,297")
    Unlike other programming languages (FORTRAN,               4    (COMMAND "ZOOM" "ALL")
BASIC, PASCAL, etc.), AutoLISP is focused on                   5    (GETSTRING "Inner contour draw of the format A4
manipulating objects. For this reason, programming in               (210,297). <Enter>")
AutoLISP presents some features [1]:                           6    (COMMAND "RECTANG" "20,10" "200,287")
 There is no difference between data and programs (this       7    (COMMAND "PEDIT" "L" "W" 0.5 "")
  makes it possible for a program to create new programs       8    (GETSTRING "Contour draw of indicator.
                                                                    <Enter>")
  or modify existing programs);
                                                               9    (COMMAND "RECTANG" "200,10" "20,50")
 No data types, so they should not be declared               10    (COMMAND "PEDIT" "L" "W" 0.5 "")
  explicitly;                                                 11    (GETSTRING "Filing edge draw. <Enter>")
 Contains LISP functions and self-defined functions;         12    (COMMAND "LINE" "20,0" "20,297" "")
 LISP functions can be defined recursively;                  13    (COMMAND "LINE" "0,148.5" "20,148.5" "")
 Data structures can be defined as high due to dynamic       14    )
  memory management.
                                                                The significance the AutoLISP programming routine
2. DRAWING PROGRAMMING                                      is explained in Table 2.
    If the classification of a single standardized format                                                     Table 2
drawing board is desired, the using of AutoCAD                Significance the AutoLISP program lines for drawing
commands is acceptable. However, if the drawing of a                    standardized format A4 (210x297)
standardized format it becomes repetitive, when more         Line     Significance the AutoLISP program lines
individual drawing are desired, then the using of             1     It defines an AutoLISP function, specifying the
AutoCAD commands are no longer profitable in terms of               command to launch the keyboard (A4)
                                                              2     Line stop running program. Running continuously by
time consuming. In this case, it is preferable to use a
                                                                    pressing the <Enter> key
programming algorithm.                                        3     Draw the outer contour of the format A4 (210,297)
    To achieve AutoLISP program only a text editor (e.g.      4     View the entire drawing
Notepad running under Windows) and obviously                  5     Line stop running program. Running continuously by
programming skills are needed. The program is saved                 pressing the <Enter> key
with the extension ".lsp" anywhere on the computer's          6     Draw the inner contour of the format A4 (210,297)
hard, then it is loaded into AutoCAD session from the         7     Editing thickness inner contour of the format A4
                                                                    (210x297)
                                      JOURNAL OF INDUSTRIAL DESIGN AND ENGINEERING GRAPHICS 43
Consideration on object-oriented programming environment AutoCAD drawings
   8     Line stop running program. Running continuously by    AutoLISP program syntax that performs 2D sketch bath
         pressing the <Enter> key                             in top view is reflected in Table 3.
  9      Draw the contour of indicator
  10     Editing thickness contour of indicator                                                                Table 3
  11     Line stop running program. Running continuously by    The AutoLISP program syntax to achieve a bathroom 2D
         pressing the <Enter> key                                               sketch in top view
  12     Draw vertical edge binder A4 format (210x297)
  13     Fix the center line filing of A4 format (210x297)
                                                                                 AutoLISP program
  14     End of AutoLISP program                              (DEFUN C:baie ()
                                                              ; Drawing frame
   Some comments are required:                                (COMMAND "RECTANG" "0,0" "210,150")
 The pausing of AutoLISP program         run is done by      (COMMAND "RECTANG" "10, 0" "200,140")
                                                              (COMMAND "ZOOM" "ALL")
 calling the GETSTRING, pending the introduction of a         ; Building bathtub
 character from the keyboard. When the interpreter            (COMMAND "RECTANG" "200,140" "140,30")
 detects entering a character from the keyboard,  the         (COMMAND "RECTANG" "195,135" "145,35")
                                                              (COMMAND "CIRCLE" "170,125" 5)
 program continues execution;
                                                              ; Building WC
                                                              (COMMAND "RECTANG" "130,135" "85,125")
 AutoCAD commands are recognized by the interpreter          (COMMAND "ELLIPSE" "107.5,85" "107.5,120" "120,105")
  by calling COMMAND function only if they are                ; Building washbasin
                                                              ………………………….
  enclosed in double quotes. AutoCAD command options          ; Building entrance door
  must be enclosed in double quotes;                          (PROGN
 The coordinates x, y and z of points in AutoCAD               (SETQ Pt (LIST '75 '20))
                                                                 (COMMAND "RECTANG" "10,15" "D" 65 5 Pt)
                                                              )
  separated by commas and quotation marks fall;               (COMMAND "ARC" "C" "10,20" "75,20" "10,85")
 The individual numerical values shall not be placed in      )
  quotation marks;
 The meaning of <Enter> key pressed, typical          for
 AutoCAD interpreter commands, is recognized by
  placing two quotes;
 Between AutoLISP command line arguments must be a
  "blank" and the brackets and arguments must not be left        In the example above could be observed the PROGN
  blank. Also, at the end of the control line there should    function that allows sequential processing of several
  not be free space;                                          individual functions. Some functions written offset are
 Any change in the program AutoLISP interpreter is           SETQ that assigns variable "Pt" value list (LIST)
 recognized if the file     is modified and saved in          containing x and y coordinates of the point 2D,
 AutoCAD recharged          by the command "Load              COMMAND respectively, which allows placing an order
 Application".                                                AutoCAD.
                                                                  Using AutoLISP programming language in the
3. DRAWING AUTOMATION                                         AutoCAD drawing saves time and automates the drawing
                                                              routines.
    In civil engineering and interior fittings are required       Once done the program in AutoLISP, it could be
sketches to position equipment that will equip space. In      called at any time, adapted and modified according to
the example of Figure 1 is represented, how minimal, top      design requirements to be achieved.
view of a room Bathroom.                                          Building interactive programming lines, which are
                                                              requiring the input date from the keyboard, the user can
                                                              use the same programming algorithm for other similar
                                                              drawings.
                                                              4. DRAWING PARAMETERIZATION
                                                                  AutoCAD drawing environment facilities enables
                                                              interactive data input required to achieve a design using
                                                              programming techniques.
                                                                  Dialog boxes, for example, allow the user to
                                                              implement custom graphical
                                                              layout and facilities of its
44 VOLU EM10 | SPECIAL ISSUE ICEGD | JUNE 2015
                                               toCAD.                        interfaces with the same
                                                                              own graphical interface
                                                 A dialog box is defined as an ASCII file, written in
                                               own programming language (DCL - Dialog Control
                                               Language) [2]. For a dialog box to become functional,
                                               DCL file must have an associated AutoLISP file.
                                                   In Table 4 is shown an AutoLISP        routine that
                                               programming dialog boxes      to draw 3D parametric
                                               primitives in AutoCAD.
Fig. 1 2D sketch of a bath, in a top view
                               JOURNAL OF INDUSTRIAL DESIGN AND ENGINEERING GRAPHICS 45
                                      Consideration
Consideration on object-oriented programming        on object-oriented
                                             environment               programming environment AutoCAD drawings
                                                          AutoCAD drawings
                                                        Table 4       The start line ": dialog" defines the dialog box, which
   The AutoLISP program syntax to draw 3D parametric               will be called "box". When is called, the associated
                      primitives                                   AutoLISP routine is calling DCL file with this name.
                      AutoLISP program                                The dialog box is defined by all the elements between
(defun C:case()                                                    braces {}.
       (setq a (load_dialog "D:/box.dcl"))                            The name of dialog box is given          by "label ="
       (if (not (new_dialog "box" a))                              (Parameterization).
       (exit))
  (action_tile "selecteaza" "(setq b (atoi
  $value))") (setq b (atoi (get_tile "selecteaza")))                  The separator ";" must            appear after each title
  (setq lista (list "CONE" "CYLINDER"                              identifier.
  "BOX")) (setq c (nth b lista))
  (start_dialog)                                                      After the defining of the name of the dialog box,
  (unload_dialog a)                                                comes the section of 3D primitive type selection (CONE,
  (if (= b 1) (con))                                               CYLINDER, BOX).
  (if (= b 2) (cilindru))                                             Depending on the option chosen, the AutoLISP
  (if (= b 3) (prisma))                                            program opens the edit box associated to 3D primitive
)                                                                  type selected, where there are the fields for input of data
 (defun con()
…………………………
                                                                   necessary for construction (Fig. 2, b).
 )                                                                    The ASCII file "box1.dcl" syntax associated to edit
 (defun cilindru()                                                 box for building 3D primitive is found in Table 6.
…………………………
 )                                                                                                                          Table 6
(defun prisma()                                                           The syntax of the file associated with the edit box
…………………………
 )                                                                  Line                           ASCII file
                                                                      1       box1 : dialog {
                                                                      2                label = "Parameters";
                                                                      3           : edit_box {
   CASE function, user-defined begin by loading the file              4                   label = "Center :";
"box.dcl" which allows you to select 3D primitive to be               5                   key = "d";
built (Fig. 2, a).                                                    6                   value = 000;
                                                                      7                   }
                                                                      8           : edit_box {
                                                                      9                   label = "Radius :";
                                                                     10                   key = "e";
                                                                     11                   value = 000;
                                                                     12                   }
                                                                     13           : edit_box {
                                                                     14                   label = "Height :";
                                                                     15                   key = "f";
                                                                     16                   value = 000;
                                                                     17                   }
                                                                     18          ok_only;
                                                                     19         }
                a                           b
     Fig. 2 Dialog boxes for draw 3D parametric primitives            By parameterization techniques, the drawing process
                         ASCII file "box.dcl"
                                                                   becomes much easier, and enables automation saves
    Syntax checkbox associated to the primitive 3D, is             time. Moreover, the user can design their own graphical
                                                                   user interface in AutoCAD or work can schedule
shown in the Table 5.
                                                                   customized drawing tools.
                                                         Table 5
        The syntax of the file associated with the checkbox        5. CASE STUDY. THE DRAWING OF THE SHIP
 Line                            ASCII file                        FORMS USING PROGRAMMING ALGORITHMS
    1  box : dialog {
    2             label = "Parameterization";                          A ship form means longitudinal, traverse and
    3       : list_box {                                           horizontal sections drawing at the theoretical surface of
    4                 label = "TYPE OF PRIMITIVE";                 the hull.
    5                 multiple_select = false;                         The steps for drawing the plane of forms using the
    6                 key = "selecteaza";                          cross-section of ship or reference model are the
    7                list = "\n... \n CONE \n CYLINDER \n
                                                                   following [3]:
       BOX";
   8
46 VOLU EM10 | SPECIALallow_accept
                                 ISSUE= true;
                                          ICEGD | JUNE 2015
   9                  fixed_height = 0.5;
  10                  fixed_width = 0.5;
  11                 }
  12       ok_only;
  13     }
                 Determining the main dimensions of the ship;
                 Selection the representation scale;
                 Grid drawing;
                 Theoretical couples drawing to line of full load water
                  line (CWL);
                 Deck line drawing in board;
                 Stem and stem lines drawing;
JOURNAL OF INDUSTRIAL DESIGN AND ENGINEERING GRAPHICS 47
Consideration on object-oriented programming environment AutoCAD drawings
                                                              In general, except for ships with atypical features of
 Theoretical couplings drawing in a line deck board and  hull construction, the program can be used to plane forms
  projection of this line to the transverse plane forms;  drawing for any ship intended for the carriage of goods.
 Deck line drawing in a diametrically plan of ship (PD);
 Water line drawing and the projection line deck board
  to the horizontal plane forms;                          6. CONCLUSIONS
 Longitudinal drawing in the longitudinal plane forms;
 Trimming curve drawing under the horizontal plane           The AutoLISP programming language is improved
  forms.                                                  with every version of AutoCAD until 1995, when
    At first sight, even for an experienced user, the     AutoDesk Company developed new trends Autodesk
example in Figure 3 is a challenge. Curves plan forms     Software (VBA, .NET, Active X). The last major
through dozens, even hundreds of points determined by     development AutoLISP programming language occurs in
the design load, curves bending to ensure optimum drag
hull and material continuity, requires maximum               1999, when AutoDesk AutoCAD incorporates an
concentration and a long time for completion of an           improved version of the program, called Visual Lisp.
appropriate plan forms.                                          The Visual Lisp is an advanced version of AutoLISP
                                                             and includes an editor, a debugger, compiler and new
                                                             features.
                                                                 Although Autodesk has developed the application
                                                             quit, AutoLISP remains by far the easiest and popular
                                                             programming language in AutoCAD.
                                                                 The major advantage of using AutoLISP
                                                             programming routines in AutoCAD environment is the
                                                             economy of time needed for execution of 2D or 3D
                 Fig. 3 Ship’s plane forms                   drawing as complex.
                                                                Moreover, AutoLISP is useful in the design of
   Since curves plan forms are built by a plurality of any   mathematical algorithms in operating databases in
coordinated entered incorrectly assumes full redesign        handling graphical objects and interfaces to achieve other
curves through specific AutoCAD commands.                    programming languages (C +, C ++ etc.).
    Using programming algorithm offered by AutoLISP,            Once designed code programming AutoLISP enables
the drawing plan forms of the ship becomes a formality,      automation and parameterization, providing versatility in
and the result will always be the correct one.               AutoCAD drawing process, the same program may be
    The result AutoLISP program to draw a plan forms         achieved different solutions for different design load.
parameterized of ship is shown in Figure 4.                     Relatively simple syntax of the language, is making
                                                             the programming AutoLISP a useful solution for
                                                             AutoCAD users, optimizing computer assisted drawing
                                                             process and significantly reducing working time.
                                                             REFERENCES
                                                             [1] MANOLEA, D., (1996). Programare în AutoLisp sub
                                                                 AutoCad, Editura Albastră, Cluj-Napoca, pp. 9-10
                                                             [2] ***, AutoCAD Tutorial, Autodesk Inc., USA
                                                             [3] MAIER, V., (1985). Mecanica şi construcţia navei.
  Fig. 4 The result AutoLISP program to draw a plan forms        Statica navei, Vol. 1, Editura Tehnică, Bucureşti, pp.
                    parameterized of ship                        38-41
   The program allows the introduction of interactive
data input, the user having the freedom to draw curves       Authors:
depending on the specific design requirements (main          Ph.D. Alexandru PINTILIE, Ovidius               University,
dimensions of the ship, the number and spacing               Department of    Naval, Port   and Power     Engineering,
theoretical couplings, water line number etc).               Faculty of Mechanical, Industrial         and    Maritime
   In this example, the AutoLISP program is running in       Engineering, Constanta, Romania
conjunction with an external file in which are recorded      [email protected]
the values of the half the width of the ship.                Ph.D. Elena -     Rita AVRAM, Ovidius University,
46 VOLU EM10 | SPECIAL ISSUE ICEGD | JUNE 2015
   Once built AutoLISP      programming algorithm, the        Department of   Naval, Port   and Power   Engineering,
user only needs to update the external file containing half   Faculty of Mechanical, Industrial     and    Maritime
the width values of the ship, which provides universal        Engineering, Constanta, Romania
method.                                                       [email protected]
   Running takes seconds and achieving results,        the
most time consuming to complementing file containing
half the width of the ship.
                                       JOURNAL OF INDUSTRIAL DESIGN AND ENGINEERING GRAPHICS 47