Print Page | Close Window

LISP define the position of a rectangle

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DWF formats, Design Review, AutoCAD 360, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=12380
Printed Date: 01.Jun.2026 at 01:06


Topic: LISP define the position of a rectangle
Posted By: lumpy92
Subject: LISP define the position of a rectangle
Date Posted: 29.Jun.2017 at 14:19
Hi all!

I try to write an autoLISP execution.
I need to draw rectangles with it. After I define the first point, I send "d" (diameters dimensions), then I send the numbers for it's height and width. But at the end, I need to select it's position with the cursor.
My question is: is there any possible way, to do that WITHOUT the cursor? I want it to draw it into the right bottom position every time (and write it into my LISP code).

Thank you for your suggestions! Wink



Replies:
Posted By: John Connor
Date Posted: 29.Jun.2017 at 15:01
Wouldn't that "D" be for "Dimensions?  Why would you specify diameters if you are drawing rectangles?  Makes no sense.


-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: lumpy92
Date Posted: 29.Jun.2017 at 15:06
Sorry, my fault. It is stand for Dimensions.


Posted By: Kent Cooper
Date Posted: 29.Jun.2017 at 19:54
Simple example, lightly tested:
(defun C:TEST () (command "_.rectang" pause "_d" 15 10 (polar (getvar 'lastpoint) (* pi 1.75) 10)))
 
The red part will feed in a point always in the right-bottom-ward direction.  Adjust the blue parts to suit your needs, or use pauses for the first two, if you want to give it different sizes each time.


Posted By: lumpy92
Date Posted: 03.Jul.2017 at 15:49
Thank you very much, it is works Wink


Posted By: lumpy92
Date Posted: 03.Jul.2017 at 16:05
Could you explain me what is the difference between ._rectangle and _rectangle?
Why is the dot is necessary? Both of them works for me.
Thanks!


Posted By: John Connor
Date Posted: 04.Jul.2017 at 13:27
Adding the "dot" before a command name ensures that the generic AutoCAD command will be used instead of one that might be substituted (or missing) by virtue of the command having been undefined.

-------------
"Humans have a strength that cannot be measured. This is John Connor. If you are reading this, you are the resistance."

<<AutoCAD 2015>>



Posted By: Kent Cooper
Date Posted: 05.Jul.2017 at 18:48
Another way to do it, that uses the RECTANG command without the Dimensions option, but rather by calculating the opposite corner in the right-bottom-ward direction:
 
(defun C:RULS (/ UL xdim ydim); = Rectang from Upper Left by specifying Size
  (setq
    UL (getpoint "\nUpper Left corner: ")
    xdim (getdist "\nHorizontal size: ")
    ydim (getdist "\nVertical size: ")
  )
  (command "_.rectang" UL (mapcar '+ UL (list xdim (- ydim))))
  (princ)
)
 
An advantage is that the prompts are clearer about what is being asked for.  I can never remember which direction they mean for "length" and "width" in RECTANG's Dimension-option prompts, and I can easily get it wrong because I think of "width" as being horizontal, but they use "length" for the horizontal size and "width" for what I would prefer to call "height."
 



Print Page | Close Window