Thursday, February 18, 2010

Creating a List

In AutoLISP a list can be generated using either the LIST function (LIST [expr...]) or by placing the elements of the list inside an opening and closing parenthesis preceded by a single quote '(4 5 6). The LIST function, when supplied with one or more arguments (either expressions and/or non-expressions) returns a list. For example, to create a list containing coordinates 5, 4, 3 the following syntax would be used.

(SETQ point (LIST 5 4 3))            ;The expression returns (5 4 3).

Once a list containing coordinate information has been created and its value set to a variable, then it may be used with any of the AutoCAD commands where point information is required. For example, to construct a line starting at the coordinates supplied in the previous example, the variable name preceded by an exclamation point would by entered at the "from point" LINE prompt. This would extract the information held by the variable and return it to the LINE command.

Command: LINE ~EnterKey~

Specify first point: !point ~EnterKey~

(5 4 3)

Specify next point or [Undo]:

Other examples of lists created using the LIST function include:

  1. (SETQ list_example (LIST "A" "B" "C"))
  2. (SETQ list_example (LIST 0.5 10 "ORANGE" "GRAPE"))
  3. (SETQ list_example (LIST '(SETQ d 5) '(SETQ f 7)))
  4. In this example a list is created containing the strings A, B and C and set to the variable list_example.
  5. In this example a list is created containing the real number 0.5, the integer 10 and the strings orange and grape.
  6. In this example a list is constructed containing AutoLISP expressions. In order for a list to contain actual expression and not their evaluated results, a single quotation mark must precede the list. The single quotation mark tells AutoLISP to return the expression without evaluating it.

No comments:

Post a Comment