# Thread: Create an X (2 lines) inside a rectangle

1. Login to Give a bone

## Create an X (2 lines) inside a rectangle

How can I create an X inside a rectangle by picking only 2 points?

2. Login to Give a bone

## Re: Create an X (2 lines) inside a rectangle

Store the two selected points in variables, then use the X/Y coordinates from each point combined to make the alternate, unpicked, points.

3. Login to Give a bone

## Re: Create an X (2 lines) inside a rectangle

i am a beginner lisp user...can you please explain how to get the x,y coordinates without actually listing them as my 2 pick points...
this is all i have so far. pt3 and pt4 i still don't know how to get.

(defun c:LX (/ pt1 pt2 pt3 pt4)
(INITGET 1)
(SETQ pt1 (GETPOINT "\nPICK 1st POINT OF LINE: "))
(SETQ pt2 (GETPOINT "\nPICK 2nd POINT OF LINE: "))
(SETQ pt3 ()
(SETQ pt4 ()
(command ".layer" "m" "G-FINE-XTRA" "C" "1" "" "")
(vl-cmdf ".LINE" pt1 pt2 "")
(vl-cmdf ".LINE" pt3 pt4 "")
(princ)
)

4. Login to Give a bone

## Re: Create an X (2 lines) inside a rectangle

Code:
```(setq pt3 (list (car pt1)(cadr pt2)))
(setq pt4 (list (car pt2)(cadr pt1)))```
you may also want put this line in
Code:
`(SETQ pt2 (getcorner "\nPICK 2nd POINT OF LINE: " pt1))`

5. Login to Give a bone

## Re: Create an X (2 lines) inside a rectangle

Originally Posted by CISCO
i am a beginner lisp user...can you please explain how to get the x,y coordinates without actually listing them as my 2 pick points...
this is all i have so far. pt3 and pt4 i still don't know how to get.

Code:
```(defun c:LX (/ pt1 pt2 pt3 pt4)
(INITGET 1)
(SETQ pt1	(GETPOINT "\nPICK 1st POINT OF LINE: "))
(SETQ pt2	(GETPOINT "\nPICK 2nd POINT OF LINE: "))
(SETQ pt3	()
(SETQ pt4	()
(command ".layer" "m" "G-FINE-XTRA" "C" "1" "" "")
(command ".LINE" pt1 pt2 "")
(command ".LINE" pt3 pt4 "")
(princ)
)```
In addition to lpseifert's comments, may I offer a few other suggestions since you are just starting out?

• Stick with lower case letters for all the pre-defined functions. Your code is difficult to read given the mixed use of full caps vs. lower caps.
• Attempt to emulate the prompting of OOTB commands. Don't use all uppercaps at the command prompt.
• Use the underscore for OOTB commands and options, to allow international folks to try your code in their languages.
• Be consistent in using (initget) where desired. You are leaving the user open to cancelling the routine at the 2nd prompt, but not trapping the exit.
• Use (and) to verify inputs before executing commands that need the input (see sample code).
• Use longer command function names for the main code, and provide a 2nd command function for the keyboard shortcut. This gives your users the ability to make their own shortcuts of your command functions.
• Leave the user's environment as you found it. You set the current layer, but don't restore the original one.
• Users like running OSnaps. If you use the command function to draw objects, make sure you use the None OSnap override.
• Trap common errors that can occur, such as your desired layer being frozen.
• Never use hard-coded data more than once. For instance, the layer name is bound to a variable to reduce typing errors and provide a single location to change the layer's name.

Code:
```;;; Main command function
(defun C:DrawBoxX  (/ pt1 pt2 pt3 pt4 cLayer layerName)
(cond ((and (setq pt1 (getpoint "\nSpecify first corner point: "))
(setq pt2 (getcorner "\nSpecify other corner point: " pt1)))
(setq pt3 (list (car pt1) (cadr pt2)))
(setq pt4 (list (car pt2) (cadr pt1)))
(setq cLayer (getvar "CLayer"))
(setq layerName "G-Fine-Xtra")
(cond ((not (tblsearch "Layer" layerName))
(command "._Layer" "_m" layerName))
((command "._Layer" "_t" layerName "_on" layerName "_s" layerName)))
(command "_c" "1" layerName "")
(vl-cmdf "._Line" "_non" pt1 "_non" pt2 "")
(vl-cmdf "._Line" "_non" pt3 "_non" pt4 "")
(setvar "CLayer" cLayer)))
(princ))
;;; Below is a shortcut command function
(defun C:LX () (C:DrawBoxX))```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•