Jump to content

How to create rectangle (polyline) with AutoLISP DXF codes


Recommended Posts

Posted

I want to make a rectangle with entmake but somehow it does not work
 

(This code below is supposed to create a rectangle based on a center point)

 

(setq base (getpoint "Set base point")
      xlen (getreal "Set width")
      ylen (getreal "Set height")
)
(entmake (list (cons 0 "LWPOLYLINE") (cons 10 (list (+ (car base) xlen) (+ (cadr base) ylen) 0.0)) (cons 10 (list (+ (car base) xlen) (- (cadr base) ylen) 0.0)) (cons 10 (list (- (car base) xlen) (- (cadr base) ylen) 0.0)) (cons 10 (list (- (car base) xlen) (+ (cadr base) ylen) 0.0)) ))

 

Can someone please tell me what did I do wrong? Thank you

Posted

Here's a way

 


;; list of elements to entmake
;; https://www.cadtutor.net/forum/topic/18257-entmake-functions/

(defun drawLWPoly (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 c:rect ( / base xlen ylen)
	(setq base (getpoint "Set base point: ")
		  xlen (getreal "Set width: ")
		  ylen (getreal "Set height: ")
	)
	(drawLWPoly 
		(list
			base
			(list (+ (nth 0 base) xlen) (nth 1 base))
			(list (+ (nth 0 base) xlen) (+ (nth 1 base) ylen))
			(list (nth 0 base) (+ (nth 1 base) ylen))
		) 
		1
	)

)

 

Posted

Sir Emmanuel can you explain to me the minimum dxf code requirements to make a polyline? Thank you

Posted

Its in his lisp. you have to feed this function a list of points and if you want it to be closed or not (0 or 1)

 

(defun drawLWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst)) ;if their are 5 points this will be (90 . 5)
                         (cons 70 cls)) ;(70 . 0) open (70 . 1) closed
                   (mapcar (function (lambda (p) (cons 10 p))) lst)))) ;this will make 5 (10 . (x y z))
Posted

Non entmake

 

(defun AHpllst ( lst / x)
(command "_pline")
(while (= (getvar "cmdactive") 1 )
(repeat (setq x (length lst))
(command (nth (setq x (- x 1)) lst))
)
(command "") ; want closed use "C"
)
)

 

  • 10 months later...
Posted
On 2/9/2023 at 8:44 PM, Emmanuel Delay said:
1

why this 1 is used please clarify

Posted
4 hours ago, annadurai said:

why this 1 is used please clarify

 

That 1 means closed polyline.

It's the second parameter given to this function: 

 

(defun drawLWPoly (lst cls)

...

)

  • Like 1
Posted (edited)

For the cons 70, open or closed polyline. Set to 0 to have open, 1 to close, open will give a 'U' shape unless you repeat the first point.

 

 

 

(or what he said above, just as I was typing)

Edited by Steven P
  • Like 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...