Jump to content

Merge two polylines


MastroLube

Recommended Posts

Hello guys, I don't know why but i got stacked with my lisp!

 

I've to create a polyline from a list of points and I really can't understand how to do that. I just searched everywhere but something is missed..

 

That's what I'm doing:

1. create a polyline -> extract coordinates

(SETQ coordinate1 (VLAX-SAFEARRAY->LIST
                    (VLAX-VARIANT-VALUE (VLAX-GET-PROPERTY obj1 'Coordinates))
                  )
 )

2. doing an offset from it and extract coordinates

(SETQ coordinate3 (VLAX-SAFEARRAY->LIST
                    (VLAX-VARIANT-VALUE (VLAX-GET-PROPERTY obj1 'Coordinates))
                  )
 )

 

Now I want to merge these lines (merge list of points and entmake a polyline).

The second one is oriented as the first one, I need to invert it!

 

I have 2 problems:

1. can't append the list of points, because i got something like that:

(1 2 3 4 5 6 ..) instead of ((1 2) (3 4) (5 6) (..) ..)

(setq lista_punti (append lista_punti (list (nth n coordinate1) (nth (1+ n) coordinate1))))

 

2. Really don't know exactly of to entmake that.. I saw something with lamda funcion.

 

(entmakex
       (append
  (list
    '(0 . "LWPOLYLINE")		;nome
    '(100 . "AcDbEntity")
    '(100 . "AcDbPolyline")
    ;'(8 . "Muri")		;layer
    ;'(62 . 5)			;colore
    (cons 90 (length coordinate1))			;numero vertici
    '(90 . 4)
    '(70 . 1)			;1 chiusa, 0 aperta
    )
 ;istructions here?
 )
 )

 

Can someone give me an advice please?

 

KxOIYqb.png

Thanks

Link to comment
Share on other sites

A guy named freerefill put this together a while back. Not the cleanest code ever, but it's super reliable.

 

  (defun plverts (ent / retn listy retDum add1 add2) ;
   (vl-load-com)
   (if	(= (cdr (assoc 0 (entget ent))) "LWPOLYLINE")
     (progn
(setq retn  nil
      listy (vlax-safearray->list
	      (vlax-variant-value
		(vla-get-coordinates (vlax-ename->vla-object ent))
	      )
	    )
)
(while (and (setq var1 (car listy)) (setq var2 (cadr listy)))
  (setq retn (append retn (list (list var1 var2 0))))
  (setq listy (cddr listy))
)
     )
   )
   retn
 )					; Returns a list of 3D coordinates defining the vertices of a polygon

Link to comment
Share on other sites

I guess that I don't understand.

 

Do you want a continuous pline to incorporate the 2 exiting lines with vertices thru the mid points of the shape and add end caps as well ?

 

The vertex order shown in attached jpg would not have any overlaying segment

 

-David

vpt.jpg

Link to comment
Share on other sites

This is another example create a pline form a list of points.

 

; co-ordsxy is a list of 2d points
(setq x -1) ; so x starts at nth 0 at start and closing
(command "PLINE" (while (= (getvar "cmdactive") 1)
                   (COMMAND (repeat (length co-ordsxy) 
                            (nth (setq x (+ x 1)) co-ordsxy)
                            )
                    )
                 )   
)
(command "C")

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