+ Reply to Thread
Results 1 to 8 of 8

Thread: Draw rectangle

  1. #1
    Full Member
    Computer Details
    spiker7221's Computer Details
    Operating System:
    Windows 7 Pro 64
    Computer:
    Dell T3600
    RAM:
    20 gig
    Graphics:
    nVidia Quadro 4000
    Using
    AutoCAD 2014
    Join Date
    Mar 2013
    Posts
    73

    Question Draw rectangle

    Registered forum members do not see this ad.

    Learning how POLAR works by creating a rectangle at offset points from the midpoint of a line. It works sometimes depending on the rotation of the line selected. LtoR seems to work, but RtoL is off a bit. I'm pretty sure I need some sort of COND statement like...

    Code:
    (if (and (>= entrot 0.0) (<= entrot 90.0))
    Here's what I've come up with so far...

    Code:
    (defun C:drawbox (/)
    
        (defun dtr (a)
          (/ (* a 180.0) pi)
        )
    
        (progn
            (setq ent (car (entsel)))
            (setq entlay (cdr (assoc 8 (entget ent))))
            (setq opt1 (cdr (assoc 10 (entget ent))))
            (setq opt2 (cdr (assoc 11 (entget ent))))
            (setq ang1 (angle opt1 opt2))
            (setq fang (dtr ang1))
            (setq tmpt (/ (distance opt1 opt2) 2.0))
            (setq mpt (polar opt1 ang1 tmpt))
        );end progn
            
        (progn
            (setq d6 18.0)
            (setq a6 5.0)
            (setq npt6 (polar mpt (- fang a6) d6))
            (command "text" npt6 "2.0" fang "6")
    
            (setq d7 16.0)
            (setq a7 14.0)
            (setq npt7 (polar mpt (- fang a7) d7))
            (command "text" npt7 "2.0" fang "7")
    
            (setq d8 18.0)
            (setq a8 7.0)
            (setq npt8 (polar mpt (- fang a8) d8))
            (command "text" npt8 "2.0" fang "8")
    
            (setq d9 18.0)
            (setq a9 14)
            (setq npt9 (polar mpt (+ fang a9) d9))
            (command "text" npt9 "2.0" fang "9")
    
            (command "pline" npt8 npt9 npt6 npt7 "c")
        );end progn
    )
    Thanks for any help,
    Mike

  2. #2
    Senior Member
    Discipline
    Mechanical
    jdiala's Discipline Details
    Occupation
    Cad Manager
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jul 2013
    Location
    Fairfax, VA
    Posts
    100

    Default

    Try this but without the text. Change some variables -> less typing.

    Code:
    (defun C:drawbox (/ e lay p1 p2 a mid d l w npt1 npt2 npt3 npt4 )
    (setq e   (car (entsel))
          lay  (cdr (assoc 8 (entget e))) ;; not needed
          p1   (cdr (assoc 10 (entget e)))
          p2   (cdr (assoc 11 (entget e)))
          a    (angle p1 p2)
          mid  (mapcar '(lambda (a b ) (/ (+ a b ) 2.)) p1 p2)
          l    (distance p1 p2) 
          w    10 ;;; width of rectangle
          npt1 (polar (polar mid (+ a (/ pi 2.)) (/ w 2. ))	(+ a pi) (/ l 2.)) 
          npt2 (polar npt1 (+ a (* pi 1.5)) w)
          npt3 (polar npt2 a l)
          npt4 (polar npt3 (+ a (/ pi 2.)) w)
    )
    (command "_.pline" "_non" npt1 "_non" npt2 "_non" npt3 "_non" npt4 "c")
    (princ)
    )
    Last edited by jdiala; 28th Aug 2013 at 02:08 pm.

  3. #3
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,745

    Default

    A simple fix but it needs your co-operation you don't pick near mid rather always what you want as near left end this way it will always create the rectang on the correct side. Even upside down. This is an oldie pretty sure there is a shorter VL lisp version.

    Code:
    (defun sel_obj ()
      (SETQ TP1 (entsel "\nSelect inside wall near left end: "))
      (setq tpp1 (entget (car tp1)))
      (setq clay (cdr (assoc 8 tpp1)))
      (setq p1 (cdr (assoc 10 tpp1)))
      (setq p2 (cdr (assoc 11 tpp1)))
      (setq p3 (cadr tp1))
      (setq ht (cdr (assoc 40 tpp1)))
      (setq el (caddr p1))
      (setq d1 (distance p1 p3))
      (setq d2 (distance p2 p3))
        (if (> d1 d2)
        (progn
        (setq temp p1)
        (setq p1 p2)
        (setq p2 temp)
        )
        )                  
        (setq ang (angle p1 p2))
      (setq ang1 (+ ang 1.5708))
     )
    (sel_obj)
    A man who never made mistakes never made anything

  4. #4
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,519

    Default

    a couple things jump out
    Code:
    (setq ang1 (angle opt1 opt2))
    (setq fang (dtr ang1))
    (angle) returns radians
    no further conversions are needed


    As an aside, the (dtr) call you have is really a RadianToAngle conversion

    Code:
    (defun AtoR (a) (* pi (/ a 180.0)))            ;Angle To Radian
    (defun RtoA (r) (/ (* r 180.0) pi))            ;Radian To Angle
    A (polar) call required the angle in radians.

    -David
    R12 (Dos) - A2K

  5. #5
    Senior Member
    Discipline
    Mechanical
    jdiala's Discipline Details
    Occupation
    Cad Manager
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jul 2013
    Location
    Fairfax, VA
    Posts
    100

    Default

    Here is a nice tutorial in regards with polar function.

    http://www.afralisp.net/autolisp/tut...ics-part-3.php

  6. #6
    Full Member
    Computer Details
    spiker7221's Computer Details
    Operating System:
    Windows 7 Pro 64
    Computer:
    Dell T3600
    RAM:
    20 gig
    Graphics:
    nVidia Quadro 4000
    Using
    AutoCAD 2014
    Join Date
    Mar 2013
    Posts
    73

    Default draw box

    Good morning/afternoon JDiala,
    Here's your modified code to work for my scenerio..

    Code:
                (setq entmpt (mapcar '(lambda (ang1 b ) (/ (+ ang1 b ) 2.)) pt1a pt2a))
                (setq npt6 (polar (polar entmpt (+ ang1 (/ pi 2.)) (/ w 2.0 ))    (+ ang1 pi) (/ l 2.)))
                (setq npt7 (polar npt6 (+ ang1 (* pi 1.5)) w))
                (setq npt8 (polar npt7 ang1 l))
                (setq npt9 (polar npt8 (+ ang1 (/ pi 2.)) w))
    ;........................ capture text ...................................
    
                (setq entxt (ssget "_WP" (list npt8 npt9 npt6 npt7)
                            '((0 . "TEXT") (8 . "A-ANNO*"))
                            );end ssget
                );end setq
    It works great...if my lines are drawn from left to right. I know how to capture for the entity rotation, but how do I flip the rectangle calculation to flip as well?

    Thanks,
    Mike

    Quote Originally Posted by jdiala View Post
    Try this but without the text. Change some variables -> less typing.

    Code:
    (defun C:drawbox (/ e lay p1 p2 a mid d l w npt1 npt2 npt3 npt4 )
    (setq e   (car (entsel))
          lay  (cdr (assoc 8 (entget e))) ;; not needed
          p1   (cdr (assoc 10 (entget e)))
          p2   (cdr (assoc 11 (entget e)))
          a    (angle p1 p2)
          mid  (mapcar '(lambda (a b ) (/ (+ a b ) 2.)) p1 p2)
          l    (distance p1 p2) 
          w    10 ;;; width of rectangle
          npt1 (polar (polar mid (+ a (/ pi 2.)) (/ w 2. ))    (+ a pi) (/ l 2.)) 
          npt2 (polar npt1 (+ a (* pi 1.5)) w)
          npt3 (polar npt2 a l)
          npt4 (polar npt3 (+ a (/ pi 2.)) w)
    )
    (command "_.pline" "_non" npt1 "_non" npt2 "_non" npt3 "_non" npt4 "c")
    (princ)
    )

  7. #7
    Senior Member
    Discipline
    Mechanical
    jdiala's Discipline Details
    Occupation
    Cad Manager
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jul 2013
    Location
    Fairfax, VA
    Posts
    100

    Default

    Can you post a picture on what you are trying to do. Where do you want your first point? will it clockwise or counter clockwise?
    Last edited by jdiala; 29th Aug 2013 at 02:11 pm.

  8. #8
    Senior Member
    Discipline
    Mechanical
    jdiala's Discipline Details
    Occupation
    Cad Manager
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jul 2013
    Location
    Fairfax, VA
    Posts
    100

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by spiker7221 View Post
    It works great...if my lines are drawn from left to right. I know how to capture for the entity rotation, but how do I flip the rectangle calculation to flip as well?

    Like this:

    Code:
    (defun C:drawbox (/ e lay p1 p2 a mid d l w npt1 npt2 npt3 npt4 )
    (setq e   (car (entsel))
          lay  (cdr (assoc 8 (entget e))) ;; not needed
          p1   (cdr (assoc 10 (entget e)))
          p2   (cdr (assoc 11 (entget e)))
          a    (LM:MakeReadable (angle p1 p2))
          mid  (mapcar '(lambda (a b ) (/ (+ a b ) 2.)) p1 p2)
          l    (distance p1 p2) 
          w    10 ;;; width of rectangle
          npt1 (polar (polar mid (+ a (/ pi 2.)) (/ w 2. ))	(+ a pi) (/ l 2.)) 
          npt2 (polar npt1 (+ a (* pi 1.5)) w)
          npt3 (polar npt2 a l)
          npt4 (polar npt3 (+ a (/ pi 2.)) w)
    )
    (command "_.pline" "_non" npt1 "_non" npt2 "_non" npt3 "_non" npt4 "c")
     (setq entxt (ssget "_CP" (list npt1 npt2 npt3 npt4)
                            '((0 . "TEXT") (8 . "A-ANNO*"))
                            );end ssget
                )
    (princ)
    )
    ;;------------------------------------------------------------;;
    ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
    ;;------------------------------------------------------------;;
    (defun LM:MakeReadable ( a )
      ((lambda ( a )
          (cond
            ( (and (> a (/ pi 2)) (<= a pi)) (- a pi))
            ( (and (> a pi) (<= a (/ (* 3 pi) 2))) (+ a pi))
            ( a )
          )
        )
        (rem a (* 2 pi))
      )
    )
    Last edited by jdiala; 29th Aug 2013 at 02:46 pm.

Similar Threads

  1. Draw Rectangle Dimension
    By nejadarea in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 18th Apr 2013, 04:39 pm
  2. Draw a rectangle on a Block
    By rodrigo_sjc_sp in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 8th Apr 2013, 02:38 pm
  3. Draw a circle centered in a rectangle
    By AutoCAD Tips Blog in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 17th Jan 2012, 03:50 am
  4. How to accurately draw a rectangle ?
    By JamFam in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 11th Apr 2006, 07:47 pm
  5. Draw Rectangle by Area
    By Brunello19 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 9th Nov 2005, 04:50 am

Bookmarks

Posting Permissions

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