To merge / add two polylines by removing intersecting part using (entmod ...) or (vlax-put ...)

To merge / add two polylines by removing intersecting part using (entmod ...) or (vlax-put ...)

mmkkmmv
Contributor Contributor
3,105 Views
21 Replies
Message 1 of 22

To merge / add two polylines by removing intersecting part using (entmod ...) or (vlax-put ...)

mmkkmmv
Contributor
Contributor

Hi,

 

To merge 2 polylines by removing intersecting part using (entmod ...) or (vlax-put ...) see snapshot below :

 

mmkkmmv_1-1605105909981.png

 

Is below code is correct method to follow, to join 2 lwpoly using "vlax-put ..." ?

I tried below code, but it is not working if lwpoly is closed or open with its start, end points at same location, any suggestions?

 

 

 

;;; e1 to join with e2 lwpoly
(defun c:test(/ e1 e2 )
(vl-load-com)
  (setq e1(car(entsel))
        e2(car(entsel))
	obj1 (vlax-ename->vla-object e1)
  	obj2 (vlax-ename->vla-object e2)        
  	;pts1(vlax-get obj1 'Coordinates)
  	;pts2(vlax-get obj2 'Coordinates)
  ) ; end setq

  (if (= (cdr(assoc 0 (entget e1))) "LWPOLYLINE") (PROGN
    (setq e1_pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e1))))
  )) ; end if
  
  (if (= (cdr(assoc 0 (entget e2))) "LWPOLYLINE")(PROGN
    (setq e2_pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e2))))
  )) ; end if
  
  (setq st_pt(car e2_pts)
        end_pt (last e2_pts)
   	idx1(vlax-curve-getparamatpoint e1 st_pt)
        idx2(vlax-curve-getparamatpoint e1 end_pt)
  	idx1_fix(fix(vlax-curve-getparamatpoint e1 st_pt))
        idx2_fix(fix(vlax-curve-getparamatpoint e1 end_pt))
        reverse1 nil
  ) ; setq 
  
  (if (<= idx1_fix idx2_fix) (progn
  (if (< idx1_fix idx2_fix) (progn
  (setq c1 0
   	list1 '()
  	list2 '()) ; setq
  
  (if (= (zerop (- idx1_fix idx1)) nil) (progn
  (repeat (+ idx1_fix 1)    
  	(setq list1(append list1 (list (nth c1 e1_pts))))
  	(setq c1(1+ c1))
  ) ; repeat
  )) ; if & progn
  (setq c2 (1+ idx2_fix))  
  (repeat (- (- (length e1_pts) 1) idx2_fix)
  (setq list2(append list2 (list (nth c2 e1_pts) ) ))
    (setq c2(1+ c2))
    ) ; repeat  
  )
 (progn ; if both index equal
  ;  if required
   ) ; progn
    ) ; if
  )) ; if & progn
  
 (if (> idx1_fix idx2_fix) (progn
  (setq reverse1 T  
  	c1 (1- (length e1_pts))
  	list1 '()
  	list2 '()) ;setq
  (if (= (zerop (- idx1_fix idx1)) nil) (progn
  (repeat (- (1- (length e1_pts)) idx1_fix)    
  	(setq list1(append list1 (list (nth c1 e1_pts))))
  	(setq c1(1- c1))
  ) ; repeat
  )) ; if & progn
  
  (setq list1(reverse list1)) ; to check
  (setq c2 0)  
  (repeat (+ idx2_fix 1)
  	(setq list2(append list2 (list (nth c2 e1_pts) ) ))
    	(setq c2(1+ c2))
  ) ; repeat 
  )) ;if & progn
  
  (setq new_coords '())
  (if (= reverse1 nil)(progn
  (setq new_coords(append list1 e2_pts list2))
  )
    (progn
      (setq new_coords(append list2 (reverse e2_pts) list1))
      )
    ) ; if

  (setq obj_coords '())  
  (foreach item new_coords
    (setq obj_coords (append obj_coords (list (car item) (cadr item)) )   )
	)
  (vlax-put obj1 'Coordinates obj_coords )
  (command ".erase" e2 "")
  (vlax-release-object obj1)
  (vlax-release-object obj2)
  (princ) 
  
  ) ; end defun

 

 

suggestions will be helpful

 

Thanks & Regards,

(mmkkmmv)

0 Likes
3,106 Views
21 Replies
Replies (21)
Message 21 of 22

mmkkmmv
Contributor
Contributor

@john.uhdenwrote

 

Thinking conceptually only (because my own laptop is temporarily not available), it seems that...
0. You probably have to check that both are at the same elevation
1. You need to find out if the two polylines intersect (probably using extendboth or maybe just the lesser one).

 

@john.uhdenchecking elevation, snapping to big polyline, all is done, just need to merge or reshape big poly with small poly, i tried and still writing code and testing, right now my approach is get 2 index(using vlax-curve-getparamatpoint ...) and remove all index between them of course with conditions if index is integer or real and so on, Requirement as of now is only for lines not bulges in poly and i am still trying

 

Thanks & Regards,

(mmkkmmv)

 

0 Likes
Message 22 of 22

mmkkmmv
Contributor
Contributor

john.uhden wrote

Thinking conceptually only (because my own laptop is temporarily not available), it seems that...
0. You probably have to check that both are at the same elevation
1. You need to find out if the two polylines intersect (probably using extendboth or maybe just the lesser one).
...

 

still trying and testing for it


Thanks & Regards,
(mmkkmmv)

0 Likes