Message 1 of 22
To merge / add two polylines by removing intersecting part using (entmod ...) or (vlax-put ...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
To merge 2 polylines by removing intersecting part using (entmod ...) or (vlax-put ...) see snapshot below :
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)