+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
  1. #1
    Full Member
    Computer Details
    jes_g's Computer Details
    Operating System:
    Windows 10
    Discipline
    Electrical
    Using
    Map 3D 2018
    Join Date
    Dec 2017
    Posts
    26

    Default Create vertices on polyline

    Registered forum members do not see this ad.

    sample_MPoly2.dwg

    Hi all,

    I have six polylines, one of them is closed. I need to create vertices on a closed polyline. The sample drawing is attached. The vertex coordinates to be created are the coordinates of first vertex of other polylines.

    So far I only managed to store the coordinate of starting vertex of one polyline.

    Code:
    (vl-load-com)
    
    (setq s1 (car (entsel)))
    (setq pl (vlax-ename->vla-object s1))
    
    
    (defun vlax-list->2D-point  (lst)
      (if lst
        (cons (list (car lst) (cadr lst))
              (vlax-list->2D-point (cddr lst)))))
    
    (setq vertCoord(vlax-list->2D-point (vlax-get pl 'Coordinates)))
    (setq vertStart (car vertCoord))
    Appreciate your help.
    Thank you

  2. #2
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,490

    Default

    Here are 3 different types of checks if the polyline is closed:
    Code:
    (if (setq polyline (car (entsel)))
      (or
        (= 1 (logand 1 (cdr (assoc 70 (entget polyline)))))
        (vlax-curve-isClosed polyline)
        (eq :vlax-true (vla-get-Closed (vlax-ename->vla-object polyline)))
      )
    )

  3. #3
    Full Member
    Computer Details
    jes_g's Computer Details
    Operating System:
    Windows 10
    Discipline
    Electrical
    Using
    Map 3D 2018
    Join Date
    Dec 2017
    Posts
    26

    Default

    Quote Originally Posted by Grrr View Post
    Here are 3 different types of checks if the polyline is closed:
    Code:
    (if (setq polyline (car (entsel)))
      (or
        (= 1 (logand 1 (cdr (assoc 70 (entget polyline)))))
        (vlax-curve-isClosed polyline)
        (eq :vlax-true (vla-get-Closed (vlax-ename->vla-object polyline)))
      )
    )
    Interesting methods, might be helpful. Thanks
    Last edited by jes_g; 6th Feb 2018 at 10:00 am.

  4. #4
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,806

    Default

    Works for open or closed

    Code:
    ; pline co-ords example
    ; By Alan H
    (defun getcoords (ent)
      (vlax-safearray->list
        (vlax-variant-value
          (vlax-get-property
        (vlax-ename->vla-object ent)
        "Coordinates"
          )
        )
      )
    )
     
    (defun co-ords2xy ()
    ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
    (setq len (length co-ords))
    (setq numb (/ len 2)) ; even and odd check required
    (setq I 0)
    (repeat numb
    (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
    ; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
    (setq co-ordsxy (cons xy co-ordsxy))
    (setq I (+ I 2))
    )
    )
    ; program starts here
    (setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
    (co-ords2xy) ; list of 2d points making pline
    A man who never made mistakes never made anything

  5. #5
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    952

    Default

    Quote Originally Posted by jes_g View Post
    Interesting methods, might be helpful. Unfortunately, the question was still not answered.
    Thank you
    Fwiw .. You've been given some complete solutions to big problems. Time to start learning to fish rather than expect a meal.

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,570

    Default

    Here's an example of how to add a vertex to a polyline.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    702

    Default

    The OP has created 3 topics related to this problem. And Ronjonp has already provided a solution here.
    BricsCAD 18

  8. #8
    Full Member
    Computer Details
    jes_g's Computer Details
    Operating System:
    Windows 10
    Discipline
    Electrical
    Using
    Map 3D 2018
    Join Date
    Dec 2017
    Posts
    26

    Default

    Quote Originally Posted by ronjonp View Post
    Fwiw .. You've been given some complete solutions to big problems. Time to start learning to fish rather than expect a meal.
    You're right, sorry. I'm just new in AutoLISP and really pressed for time. But slowly getting the hang of LISP

  9. #9
    Full Member
    Computer Details
    jes_g's Computer Details
    Operating System:
    Windows 10
    Discipline
    Electrical
    Using
    Map 3D 2018
    Join Date
    Dec 2017
    Posts
    26

    Default

    Quote Originally Posted by BIGAL View Post
    Works for open or closed

    Code:
    ; pline co-ords example
    ; By Alan H
    (defun getcoords (ent)
      (vlax-safearray->list
        (vlax-variant-value
          (vlax-get-property
        (vlax-ename->vla-object ent)
        "Coordinates"
          )
        )
      )
    )
     
    (defun co-ords2xy ()
    ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
    (setq len (length co-ords))
    (setq numb (/ len 2)) ; even and odd check required
    (setq I 0)
    (repeat numb
    (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
    ; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
    (setq co-ordsxy (cons xy co-ordsxy))
    (setq I (+ I 2))
    )
    )
    ; program starts here
    (setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
    (co-ords2xy) ; list of 2d points making pline
    Thanks, BIGAL

  10. #10
    Full Member
    Computer Details
    jes_g's Computer Details
    Operating System:
    Windows 10
    Discipline
    Electrical
    Using
    Map 3D 2018
    Join Date
    Dec 2017
    Posts
    26

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Lee Mac View Post
    Here's an example of how to add a vertex to a polyline.
    Thank you, Lee Mac. I was using your AddLWPolylineVertexV1-0.lsp routine. Could you possibly explain your code just a bit, I've got trouble understanding it.
    I started breaking down the program line by line

    Code:
    ;;----------------=={ Add LWPolyline Vertex }==---------------;;
    ;;                                                            ;;
    ;;  Adds a new vertex to an LWPolyline at a point specified   ;;
    ;;  by the user; compatible with LWPolylines at any           ;;
    ;;  orientation, with varying width and arc segments.         ;;
    ;;------------------------------------------------------------;;
    ;;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com       ;;
    ;;------------------------------------------------------------;;
    ;;  Version 1.0    -    17-12-2012                            ;;
    ;;                                                            ;;
    ;;  First release.                                            ;;
    ;;------------------------------------------------------------;;
    
    (defun c:apv ( / a b e h l n p r w x z )
        (while ;;inf loop
            (progn (setq p (getpoint "\nPick Point for New Vertex: "))
                (cond
                    (   (null p) nil) ;; 1st cond - if p not equal 0 return nil
                    (   (null (setq e (nentselp p))) ;; 2nd cond ? The nentselp function returns a 4×4 transformation matrix. What for?
                        (princ "\nPoint does not lie on an LWPolyline.") ;; so if the returned matrix is empty (nil), print this
                    )
                    (   (= 4 (length e)) ;; 3rd cond - ??
                        (princ "\nObject is Nested.") ;; what is nested object?
                    )
                    (   (/= "LWPOLYLINE" (cdr (assoc 0 (entget (setq e (car e)))))) ;; 4th cond - compare. If not equal...	
                        (princ "\nObject is not an LWPolyline.") ;; ...print this
                    )
                )
            )
        )
        (if (and p e ;; expression returns T if both p and e are not nil, else nil
                (setq p (vlax-curve-getclosestpointto e (trans p 1 0)) ;; the UCS is rotated 90 degrees counterclockwise around the WCS Z axis?? Closest point between e and rotated list
                      n (vlax-curve-getparamatpoint e p) ;; still don't understand what getparamatpoint means
                )
            )
            (if (not (equal n (fix n) 1e-8)) ;; checks if not equal - n and its truncated value with fuzz distance of 1e-8
                (progn
                    (setq e (entget e)
                          h (reverse (member (assoc 39 e) (reverse e))) ;; returns list consisting of 14 lists - what for?
                          l (LM:LWVertices e)
                          z (assoc 210 e)
                    ) 
                    (repeat (fix n)
                        (setq a (cons (car l) a)
                              l (cdr l)
                        )
                    )
                    (setq x (car l)
                          r (- n (fix n))
                          w (cdr (assoc 40 x))
                          w (+ w (* r (- (cdr (assoc 41 x)) w)))
                          b (atan (cdr (assoc 42 x)))
                    )
                    (entmod
                        (append h
                            (apply 'append (reverse a))
                            (list
                                (assoc 10 x)
                                (assoc 40 x)
                                (cons  41 w)
                                (cons  42 (tan (* r b)))
                            )
                            (list
                                (cons  10 (trans p 0 (cdr z)))
                                (cons  40 w)
                                (assoc 41 x)
                                (cons  42 (tan (* (- 1.0 r) b)))
                            )
                            (apply 'append (cdr l))
                            (list z)
                        )
                    )
                )
            )
        )
        (princ)
    )
    
    ;; Tangent  -  Lee Mac
    ;; Args: x - real
    
    (defun tan ( x )
        (if (not (equal 0.0 (cos x) 1e-10))
            (/ (sin x) (cos x))
        )
    )
    
    ;; LW Vertices  -  Lee Mac
    ;; Returns a list of lists in which each sublist describes
    ;; the position, starting width, ending width and bulge of the
    ;; vertex of a supplied LWPolyline
    
    (defun LM:LWVertices ( e )
        (if (setq e (member (assoc 10 e) e))
            (cons
                (list
                    (assoc 10 e)
                    (assoc 40 e)
                    (assoc 41 e)
                    (assoc 42 e)
                )
                (LM:LWVertices (cdr e))
            )
        )
    )
    
    (vl-load-com) (princ)
    
    ;;------------------------------------------------------------;;
    ;;                        End of File                         ;;
    ;;------------------------------------------------------------;;

Similar Threads

  1. List the vertices of MPolygon and create new vertices
    By jes_g in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 5th Feb 2018, 12:11 pm
  2. Vertices of a Polyline
    By Tharwat in forum AutoLISP, Visual LISP & DCL
    Replies: 19
    Last Post: 11th Apr 2015, 06:13 am
  3. add new vertices to 3d polyline
    By motee-z in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 18th May 2014, 10:15 pm
  4. Polyline vertices
    By scottpops in forum AutoLISP, Visual LISP & DCL
    Replies: 18
    Last Post: 9th Jan 2012, 08:22 pm
  5. Replies: 12
    Last Post: 17th Nov 2011, 09:39 pm

Tags for this Thread

Bookmarks

Posting Permissions

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