See the top rated post in this thread. Click here

Results 1 to 3 of 3

Thread: AutoCAD - Add Vertices at Interval - Multiple Polylines Simultaneously

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2020-05
    Posts
    1
    Login to Give a bone
    1

    Default AutoCAD - Add Vertices at Interval - Multiple Polylines Simultaneously

    Hi all,

    I was wondering if someone could help out getting Vertices inserted into multiple polylines (simultaneously) at a specified interval. It must work with arcs as well.

    I've searched the web and I've found the following LISP, which works fine but only selects 1 object at a time.


    Code:
    (defun c:demo ( / add_vtx pl int in pt flag )
     
     (vl-load-com)
     
     (defun add_vtx ( obj add_pt ent_name / bulg )
         (vla-addVertex
             obj
             (1+ (fix add_pt))
             (vlax-make-variant
                 (vlax-safearray-fill
                     (vlax-make-safearray vlax-vbdouble (cons 0 1))
                         (list
                             (car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
                             (cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
                         )
                 )
             )
         )
         (setq bulg (vla-GetBulge obj (fix add_pt)))
         (vla-SetBulge obj
             (fix add_pt)
             (/
                 (sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
                 (cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
             )
         )
         (vla-SetBulge obj
             (1+ (fix add_pt))
             (/
                 (sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
                 (cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
             )
         )
         (vla-update obj)
     )
     
     (setq pl (car (entsel "\nSelect pline entity")))
     (if (not (wcmatch (cdr (assoc 0 (entget pl))) "*POLYLINE"))
       (progn
         (alert "\nPicked entity isn't polyline - quitting")
         (exit)
       )
       (if (and (or (eq (cdr (assoc 70 (entget pl))) 0) (eq (cdr (assoc 70 (entget pl))) 1)) (eq (cdr (assoc 0 (entget pl))) "POLYLINE"))
         (progn
           (setq flag T)
           (command "_.convertpoly" "l" pl "")
         )
         (if (not (eq (cdr (assoc 0 (entget pl))) "LWPOLYLINE"))
           (progn
             (alert "\nYou picked 3d polyline - quitting")
             (exit)
           )
         )
       )
     )
     (setq int (getdist "\nEnter Interval: "))
     (setq in int)
     (while (setq pt (vlax-curve-getPointAtDist pl int))
       (add_vtx (vlax-ename->vla-object pl) (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl pt)) pl)
       (setq int (+ int in))
     )
     (if flag
       (command "_.convertpoly" "h" pl "")
     )
     (princ)
    )
    Last edited by Opie; 2021-01-05 at 01:33 PM. Reason: [code] tags display code better

  2. #2
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    561
    Login to Give a bone
    0

    Default Re: AutoCAD - Add Vertices at Interval - Multiple Polylines Simultaneously

    Changing from select 1 to many is very simple for this task, so this is how and have a go your self you use ssget with *Polyline as a filter so it only gets plines etc. Then you would use repeat (sslength selectionset)

    (repeat (setq x (sslength ss)) to get each pl now use (setq pl (ssname ss (setq x (- x 1)))) you can change the test to make sure SS exists.

  3. #3
    Member
    Join Date
    2001-03
    Location
    ROMANIA
    Posts
    35
    Login to Give a bone
    0

    Default Re: AutoCAD - Add Vertices at Interval - Multiple Polylines Simultaneously

    Quote Originally Posted by tiago.caldeira789919 View Post
    Hi all,

    I was wondering if someone could help out getting Vertices inserted into multiple polylines (simultaneously) at a specified interval. It must work with arcs as well.

    I've searched the web and I've found the following LISP, which works fine but only selects 1 object at a time.


    Code:
    (defun c:demo ( / add_vtx pl int in pt flag )
     
     (vl-load-com)
     
     (defun add_vtx ( obj add_pt ent_name / bulg )
         (vla-addVertex
             obj
             (1+ (fix add_pt))
             (vlax-make-variant
                 (vlax-safearray-fill
                     (vlax-make-safearray vlax-vbdouble (cons 0 1))
                         (list
                             (car (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
                             (cadr (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name))
                         )
                 )
             )
         )
         (setq bulg (vla-GetBulge obj (fix add_pt)))
         (vla-SetBulge obj
             (fix add_pt)
             (/
                 (sin (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
                 (cos (/ (* 4 (atan bulg) (- add_pt (fix add_pt))) 4))
             )
         )
         (vla-SetBulge obj
             (1+ (fix add_pt))
             (/
                 (sin (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
                 (cos (/ (* 4 (atan bulg) (- (1+ (fix add_pt)) add_pt)) 4))
             )
         )
         (vla-update obj)
     )
     
     (setq pl (car (entsel "\nSelect pline entity")))
     (if (not (wcmatch (cdr (assoc 0 (entget pl))) "*POLYLINE"))
       (progn
         (alert "\nPicked entity isn't polyline - quitting")
         (exit)
       )
       (if (and (or (eq (cdr (assoc 70 (entget pl))) 0) (eq (cdr (assoc 70 (entget pl))) 1)) (eq (cdr (assoc 0 (entget pl))) "POLYLINE"))
         (progn
           (setq flag T)
           (command "_.convertpoly" "l" pl "")
         )
         (if (not (eq (cdr (assoc 0 (entget pl))) "LWPOLYLINE"))
           (progn
             (alert "\nYou picked 3d polyline - quitting")
             (exit)
           )
         )
       )
     )
     (setq int (getdist "\nEnter Interval: "))
     (setq in int)
     (while (setq pt (vlax-curve-getPointAtDist pl int))
       (add_vtx (vlax-ename->vla-object pl) (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl pt)) pl)
       (setq int (+ int in))
     )
     (if flag
       (command "_.convertpoly" "h" pl "")
     )
     (princ)
    )
    If is enough for you 2D polyline, then try this:
    Code:
    (DEFUN C:ARRAY-VERTICES (/ *error* add_vtx in interval pl pt LSE CNT)
    
    
      (defun *error* (s)
        (or (wcmatch (strcase s) "*BREAK,*CANCEL*,*EXIT*") (prompt (strcat "\nError: " s)))
        (setq LSE nil)
        (princ)
      ) ;;*error*
    
    
      (defun add_vtx (add_pt ent_name / obj pct)
        (setq   obj (vlax-ename->vla-object ent_name)
                pct (trans (vlax-curve-getpointatparam obj add_pt) 0 ent_name)
        )
        (vla-addvertex
          obj
          (1+ (fix add_pt))
          (vlax-make-variant
            (vlax-safearray-fill
              (vlax-make-safearray vlax-vbdouble (quote (0 . 1)))
              (list (car pct) (cadr pct))
            )
          )
        )
      ) ;;add_vtx
    
    
    ;;Main
      (initget 15)
      (setq LSE       (ssget (list (quote  (0 . "LWPOLYLINE"))))
            interval  (getdist "\nSpecify interval: ")
            in        interval
            CNT       0
      )
      (while (< CNT (sslength LSE))
        (setq pl (ssname LSE CNT))
        (while (setq pt (vlax-curve-getpointatdist pl interval))
          (command "_.POINT" pt) ;;Test!
          (add_vtx (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl pt)) pl)
          (setq interval (+ interval in))
        )
        (setq   interval  in
                CNT       (1+ CNT)
        )
      )
      (setq LSE nil)
      (princ)
    ) ;;C:ARRAY-VERTICES
    (vl-load-com)

Similar Threads

  1. List the vertices of MPolygon and create vertices
    By jes_g_autocad in forum AutoLISP
    Replies: 1
    Last Post: 2018-02-07, 10:11 AM
  2. Replies: 1
    Last Post: 2012-01-05, 09:13 PM
  3. Polylines with multiple vertices same x,y, looks like one segment
    By norrin in forum AutoCAD Map 3D - General
    Replies: 2
    Last Post: 2009-09-11, 01:54 PM
  4. Add interval column to presentations animation
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 0
    Last Post: 2009-02-08, 01:36 AM
  5. Add multiple vertices to pline.
    By pgastelum77763 in forum AutoCAD General
    Replies: 4
    Last Post: 2005-02-26, 04:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •