Author Topic: help: Add Vertices to selected overlaping polylines at intersecting point  (Read 1067 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
hi. I use this code to add vertex on intersection of polylines, but this code works only for one polyline a time. Is it possible to select multyle polylines and insert to all the extra vertex?

Code - Auto/Visual Lisp: [Select]
  1. ;;; pvx - adds vertices at intersection of pline and selection set of curves ;;;
  2.  
  3. (defun c:pvx ( / intersobj1obj2 LM:Unique AT:GetVertices member-fuzz add_vtx
  4.                       s1 ss ent n entx intpts intptsall plpts par f )
  5.  
  6.  
  7.   (defun intersobj1obj2 ( obj1 obj2 / coords pt ptlst )
  8.     (if (eq (type obj1) 'ENAME) (setq obj1 (vlax-ename->vla-object obj1)))
  9.     (if (eq (type obj2) 'ENAME) (setq obj2 (vlax-ename->vla-object obj2)))
  10.     (setq coords (vl-catch-all-apply 'vlax-safearray->list (list (vl-catch-all-apply 'vlax-variant-value (list (vla-intersectwith obj1 obj2 AcExtendNone))))))
  11.     (if (vl-catch-all-error-p coords)
  12.       (setq ptlst nil)
  13.       (repeat (/ (length coords) 3)
  14.         (setq pt (list (car coords) (cadr coords) (caddr coords)))
  15.         (setq ptlst (cons pt ptlst))
  16.         (setq coords (cdddr coords))
  17.       )
  18.     )
  19.     ptlst
  20.   )  
  21.  
  22.   (defun LM:Unique ( lst )
  23.     (if lst (cons (car lst) (LM:Unique (vl-remove (car lst) (cdr lst)))))
  24.   )
  25.  
  26.   (defun AT:GetVertices ( e / p l )
  27.     (LM:Unique
  28.       (if e
  29.         (if (eq (setq p (vlax-curve-getEndParam e)) (fix p))
  30.           (repeat (setq p (1+ (fix p)))
  31.             (setq l (cons (vlax-curve-getPointAtParam e (setq p (1- p))) l))
  32.           )
  33.         )
  34.       )
  35.     )
  36.   )
  37.  
  38.   (defun member-fuzz ( expr lst fuzz )
  39.     (while (and lst (not (equal (car lst) expr fuzz)))
  40.       (setq lst (cdr lst))
  41.     )
  42.     lst
  43.   )
  44.  
  45.   (defun add_vtx ( obj add_pt ent_name / bulg sw ew )
  46.       (vla-GetWidth obj (fix add_pt) 'sw 'ew)
  47.       (vla-addVertex
  48.           obj
  49.           (1+ (fix add_pt))
  50.           (vlax-make-variant
  51.               (vlax-safearray-fill
  52.                   (vlax-make-safearray vlax-vbdouble (cons 0 1))
  53.                       (list
  54.                           (car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
  55.                           (cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
  56.                       )
  57.               )
  58.           )
  59.       )
  60.       (setq bulg (vla-GetBulge obj (fix add_pt)))
  61.       (vla-SetBulge obj
  62.           (fix add_pt)
  63.           (/
  64.               (sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
  65.               (cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
  66.           )
  67.       )
  68.       (vla-SetBulge obj
  69.           (1+ (fix add_pt))
  70.           (/
  71.               (sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
  72.               (cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
  73.           )
  74.       )
  75.       (vla-SetWidth obj (fix add_pt) sw (+ sw (* (- ew sw) (- add_pt (fix add_pt)))))
  76.       (vla-SetWidth obj (1+ (fix add_pt)) (+ sw (* (- ew sw) (- add_pt (fix add_pt)))) ew)
  77.       (vla-update obj)
  78.   )
  79.  
  80.   (prompt "\nPick source POLYLINE...")
  81.   (setq s1 (ssget "_+.:E:S:L" (list '(0 . "*POLYLINE") '(-4 . "<or") '(70 . 0) '(70 . 1) '(70 . 128) '(70 . 129) '(-4 . "or>") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  82.   (while (not s1)
  83.     (prompt "\nMissed... Try picking source POLYLINE on unlocked layer again...")
  84.     (setq s1 (ssget "_+.:E:S:L" (list '(0 . "*POLYLINE") '(-4 . "<or") '(70 . 0) '(70 . 1) '(70 . 128) '(70 . 129) '(-4 . "or>") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  85.   )
  86.   (prompt "\nNow select intersecting curves...")
  87.   (setq ss (ssget (list '(0 . "*POLYLINE,SPLINE,LINE,ARC,CIRCLE,ELLIPSE,HELIX,RAY,XRAY") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  88.   (while (not ss)
  89.     (prompt "\nEmpty sel.set... Please reselect intersecting curves again...")
  90.     (setq ss (ssget (list '(0 . "*POLYLINE,SPLINE,LINE,ARC,CIRCLE,ELLIPSE,HELIX,RAY,XRAY") (cons 410 (if (= 1 (getvar 'cvport)) (getvar 'ctab) "Model")))))
  91.   )
  92.   (setq ent (ssname s1 0))
  93.   (if (= (cdr (assoc 0 (entget ent))) "POLYLINE")
  94.     (progn
  95.       (command "_.CONVERTPOLY" "_L" ent "")
  96.       (entupd (setq ent (entlast)))
  97.       (vla-update (vlax-ename->vla-object ent))
  98.       (setq f t)
  99.     )
  100.   )
  101.   (repeat (setq n (sslength ss))
  102.     (setq entx (ssname ss (setq n (1- n))))
  103.     (setq intpts (intersobj1obj2 ent entx))
  104.     (setq intptsall (append intpts intptsall))
  105.   )
  106.   (foreach intpt intptsall
  107.     (setq plpts (AT:GetVertices ent))
  108.     (if
  109.       (and
  110.         (not (member-fuzz intpt plpts 1e-6))
  111.          (setq par (vlax-curve-getparamatpoint ent (vlax-curve-getclosestpointto ent intpt)))
  112.       )
  113.       (add_vtx (vlax-ename->vla-object ent) par ent)        
  114.     )
  115.   )
  116.   (if f
  117.     (progn
  118.       (command "_.CONVERTPOLY" "_H" ent "")
  119.       (entupd (setq ent (entlast)))
  120.       (vla-update (vlax-ename->vla-object ent))
  121.     )
  122.   )
  123.   (princ)
  124. )
  125.  
  126.  

Thanks

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Here are my plintav*.lsp routines from my PLINETOOLS archive...
You should be able to achieve what you asked with some of them...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

PM

  • Guest
Thanks. What the differense between this 4 files. The plintav-new.lsp is the last version?