Jump to content

Simple Rectangle LISP


jonhite

Recommended Posts

We often need 15/16" tall rectangles at different lengths. I want to be able to select point a and point b and create a 15/16" tall rectangle perpendicular to the line between the 2 points (no line is needed, just he rectangle)

I also want it to appear on the Defpoints later every time.

 

I know very basics of LISP code, but I'm very much learning.

Thanks for any help!

Link to comment
Share on other sites

Command RF for 15, RS for 16

I presume your dwg is in inch. Otherwise it will simply use 15 or 16 of whichever active units

 

(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))

(defun deg2rad (deg / )
 (/ (* deg 3.14159265359 ) 180)
)
                   
;; rfs for Rectangle Fifteen 
(defun c:rf ( / pa pb baseheading)
 (setq pa (getpoint "\nPoint A: "))
 (setq pb (getpoint "\nPoint B: "))
 (setq baseheading (angle pa pb))
 (setq pc (polar pa (+ baseheading (deg2rad 90)) 15))
 (setq pd (polar pb (+ baseheading (deg2rad 90)) 15))
 (LWPoly (list pa pb pd pc) 1)
)

;; rs for Rectangle Sixteen 
(defun c:rs ( / pa pb baseheading)
 (setq pa (getpoint "\nPoint A: "))
 (setq pb (getpoint "\nPoint B: "))
 (setq baseheading (angle pa pb))
 (setq pc (polar pa (+ baseheading (deg2rad 90)) 16))
 (setq pd (polar pb (+ baseheading (deg2rad 90)) 16))
 (LWPoly (list pa pb pd pc) 1)
)

Link to comment
Share on other sites

oh yes.

See if this does the trick

 

;; draws a polyline on layer "DEFPOINTS"
(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 8 "DEFPOINTS")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))

Link to comment
Share on other sites

Sorry, I'm being a poor American.

Yes it is in Inches. 15/16" = .9375 inches. I just need 1 of that height and to be placed on the Defpoints layer every time. Sorry to be confusing.

Link to comment
Share on other sites

*Defpoints layer every time

 

Please read: https://knowledge.autodesk.com/support/civil-3d/learn-explore/caas/sfdcarticles/sfdcarticles/Putting-objects-on-non-plot-layer.html?st=defpoints%20layer

and: https://forums.autodesk.com/t5/autocad-forum/defpoints/m-p/2297321

 

Many issues related to users using this layer whose sole purpose is for dimension nodes.

 

Use a layer set to Not Plot instead.

Link to comment
Share on other sites

Okay, like this?

Command RFS

;; draws a polyline on layer "DEFPOINTS"
(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 8 "DEFPOINTS")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))
                   
(defun deg2rad (deg / )
 (/ (* deg 3.14159265359 ) 180)
)
                   
;; rfs for Rectangle Fifteen/Sixteen
(defun c:rfs ( / pa pb pc pd baseheading)
 (setq pa (getpoint "\nPoint A: "))
 (setq pb (getpoint "\nPoint B: "))
 (setq baseheading (angle pa pb))
 (setq pc (polar pa (+ baseheading (deg2rad 90.0)) (/ 15.0 16.0) ))
 (setq pd (polar pb (+ baseheading (deg2rad 90.0)) (/ 15.0 16.0) ))
 (LWPoly (list pa pb pd pc) 1)
)

Link to comment
Share on other sites

Emmanuel a couple of suggestions

 

(* deg 3.14159265359 )
(* deg PI )

(deg2rad 90.0)
(setq a90 (/ pi 2.0))
(setq pc (polar pa (+ baseheading a90) (/ 15.0 16.0) ))

Link to comment
Share on other sites

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...