Jump to content

Draw rectangle with rotation (Preview rectangle getting drawn)


Recommended Posts

Posted

I have this simple code below to pick the lower corner, the rotation and then the upper far corner which is handy for tracing maps with rectangular buildings on them.

 

I would like to preview the rectangle getting drawn.

 

Maybe it's late but I can't see how to do this easily without grread but perhaps there is.

 

;; Idea from this: https://www.theswamp.org/index.php?topic=55203.msg594646#msg594646

;; TO DO:
;; Add proper undo handling
;; Show preview of the rectangle

(defun C:Survey_Rectangle (/ pt1 pt2 ptr)

  (if
    (and
      (setq pt1 (getpoint "\nBottom left corner :"))
      (setq ptr (getpoint "\nRotation :"))
      (setq pt2 (getpoint pt1 "\nTop Right corner :"))
    )

    (progn
      (command "_.rectang" pt1 "_R" ptr pt2)
      (command "_.rectang" pt1 "_R" 0 \) ;; Set the rectangle rotation back to 0 without going into the command
    )
  )
)

(c:Survey_Rectangle)

 

Posted

You can do it with temporarily changing UCS rotation and just processing RECTANGLE command...

 

 

(defun c:foo ( / *error* ucsf ll lr )

  (defun *error* ( m )
    (if ucsf
      (if command-s
        (command-s "_.UCS" "_P")
        (vl-cmdf "_.UCS" "_P")
      )
    )
    (if m
      (prompt m)
    )
    (princ)
  )

  (if (= 0 (getvar 'worlducs))
    (progn
      (vl-cmdf "_.UCS" "_W")
      (setq ucsf t)
    )
  )
  (vl-cmdf "_.UCS" "_Z" (cvunit (getangle (setq ll (getpoint "\nBase point : ")) (setq lr (getpoint "\nDirection : ")) "radian" "degree"))
  (vl-cmdf "_.RECTANGLE" "_non" (trans ll 0 1) "\\")
  (*error* nil)
)

 

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...