LWPOLYLINE entmake

LWPOLYLINE entmake

mmitchellH6TRW
Enthusiast Enthusiast
921 Views
3 Replies
Message 1 of 4

LWPOLYLINE entmake

mmitchellH6TRW
Enthusiast
Enthusiast

This is mainly a list processing question.

Please help create the LWPOLYLINE entlist for entmake:

;; LWPOLYLINE.lsp
;; 
;; test for LWPOLYLINE creation
;;
(defun test () 

  (setq plverts '((1 2) (2 3) (5 6))
        plbulg  (0.0 0.5 0.0)
        entdef  (append 
                  (list 
                    '(0 . "LWPOLYLINE")
                    (cons 8 0)
                    (cons 67 0)
                    '(100 . "AcDbPolyline")
                    (cons 90 (length plverts))
                    (cons 70 0)
                    (cons 43 0.0)
                    (cons 38 0.0)
                    (cons 39 0.0)
                  )
                  (mapcar ; this is the peice that doesn't work
                    '(lambda (#10 #42) 
                       (list 
                         (cons 10 #10)
                         (cons 42 #42)
                       )
                     )
                    plverts
                    plbulg
                  )
                 (list
                  (cons 210 (0.0 0.0 1.0))
                  )
                )
  )
  (princ entdef)
  (entmake entdef)
)
0 Likes
Accepted solutions (1)
922 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

5 issues.

BTW It's good to always start HERE 

 

(defun c:test ()
  
  (setq plverts '((1 2) (2 3) (5 6))
	plbulg  '(0.0 0.5 0.0) ; !
	entdef  (append
		  (list
		    '(0 . "LWPOLYLINE")
		    (cons 8 "0") ; !
		    (cons 67 0)
		    (cons 100 "AcDbEntity") ; !
		    '(100 . "AcDbPolyline")
		    (cons 90 (length plverts))
		    (cons 70 0)
		    (cons 43 0.0)
		    (cons 38 0.0)
		    (cons 39 0.0)
		    )
		  (apply 'append ; !
			 (mapcar
			   '(lambda (#10 #42)
			      (list 
				(cons 10 #10)
				(cons 42 #42)
				)
			      )
			   plverts
			   plbulg
			   ))
		  (list
		    (cons 210 '(0.0 0.0 1.0)) ; !
		    )
		  )
	)
  (princ entdef)
  (entmake entdef)
  )

 

Message 3 of 4

hak_vz
Advisor
Advisor

If you want to use visual lisp

(defun make_lw_poly (plverts plbulg / adoc space newline i)
	(setq adoc (vla-get-ActiveDocument (vlax-get-acad-object)))
	(setq space
		(if (zerop (vla-get-activespace adoc))
			  (if 
				(= (vla-get-mspace adoc) :vlax-true)
					(vla-get-modelspace adoc)
					(vla-get-paperspace adoc)
			  )
			(vla-get-modelspace adoc)
		)
	)
	(if (= (length (car plverts)) 2)
		(setq plverts (apply 'append plverts))
		(setq plverts (apply 'append (mapcar '(lambda (x) (list (car x) (cadr x))) plverts)))
	)
	(setq newline
		(vla-addlightweightpolyline space
			(vlax-make-variant
				(vlax-safearray-fill
					(vlax-make-safearray vlax-vbdouble (cons 0 (1- (length plverts))))
						plverts
					)
			)
		)
	)
   (setq i -1)
   (while (< (setq i (1+ i)) (length plbulg))
		(vla-SetBulge newline i (nth i plbulg))
   )
)
(setq 
   plverts '((1 2) (2 3) (5 6))
   plbulg  '(0.0 0.5 0.0)
)
(setq lw (make_lw_poly plverts plbulg))

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 4 of 4

john.uhden
Mentor
Mentor

@hak_vz 

That's sorta like my style, but I got into the habit of building the list of vertices as...

(setq plist '((b1 x1 y1)(b2 x2 y2)...(bn xn yn))  ;; No, I don't use variables like b1, x1, etc.

Then add a LWPolyline with just two random vertices (or maybe even just one, but I don't remember) and then

(vlax-put object 'Coordinates (apply 'append (mapcar 'cdr plist)))

and

(setq i -1)

(repeat (length plist)(vla-setbulge object (setq i (1+ i))(car (nth i plist))))

That way it's easy to add or remove a vertex (including bulge) to/from plist.

I think my VEDIT and 3DEDIT command functions work that way, with the obvious difference that LWs are only (x y) but have bulges, and 3Ds are just (x y z).

That's where my @group function comes into play...

   ;; Function to group a list ofitems into a list of
   ;; multiple lists, each of length N, e.g.
   ;; '(A B C D E F G H I) -> '((A B C)(D E F)(G H I))
   (defun @group (lst n / item new)
     (foreach element (reverse lst)
       (setq item (cons element item))
       (if (= (length item) n)
         (setq new (cons item new) item nil)
       )
     )
     new
   )

John F. Uhden

0 Likes