Results 1 to 5 of 5

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

  1. #1
    Member
    Join Date
    2007-10
    Location
    Arlington, TX
    Posts
    20
    Login to Give a bone
    0

    Default Create an X (2 lines) inside a rectangle

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

    thanks in advance.

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default 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.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  3. #3
    Member
    Join Date
    2007-10
    Location
    Arlington, TX
    Posts
    20
    Login to Give a bone
    0

    Default 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. #4
    I could stop if I wanted to
    Join Date
    2003-12
    Location
    Pittsburgh, PA
    Posts
    355
    Login to Give a bone
    0

    Default 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. #5
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

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

    Quote Originally Posted by CISCO View Post
    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))
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

Similar Threads

  1. Offset a rectangle to separate lines.
    By BrianTFC in forum AutoLISP
    Replies: 2
    Last Post: 2012-02-06, 09:53 PM
  2. Create rectangle then move at center point
    By CISCO in forum AutoLISP
    Replies: 12
    Last Post: 2010-11-14, 04:33 PM
  3. create an excel of block attributes from within a specified rectangle
    By christopher.r.schroll in forum VBA/COM Interop
    Replies: 1
    Last Post: 2008-05-20, 02:33 PM
  4. How to make a routine to create rectangle?
    By mhannan.100562 in forum AutoLISP
    Replies: 15
    Last Post: 2006-09-06, 07:51 PM
  5. Rectangle command draws 4 Lines instead of 1 Polyline
    By jeff.garr in forum AutoCAD General
    Replies: 8
    Last Post: 2004-10-01, 03:43 PM

Posting Permissions

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