+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Junior Member leo321's Avatar
    Computer Details
    leo321's Computer Details
    Operating System:
    w7 64bt
    Computer:
    TOSHIBA / DELL
    CPU:
    i5 3°generation
    RAM:
    4 gb other 6gb
    Graphics:
    1gb other 2gb
    Primary Storage:
    500gb
    Secondary Storage:
    2 tera
    Monitor:
    21' and 17'
    Discipline
    Structural
    leo321's Discipline Details
    Occupation
    design Project
    Discipline
    Structural
    Details
    Pipelines, Industrials Units, Wind Farms, Minig, transmission line, thermoelectric, etc..
    Using
    AutoCAD 2012
    Join Date
    Jan 2013
    Location
    São Paulo / Brazil
    Posts
    19

    Default help! Masters; EXTRACT VERTEX X,Y choose first point at way clockwise (need upgrade)

    Registered forum members do not see this ad.

    I had this from Lee, but usually always go way counter-clockwise and only select the polyline, not the point.

    ;; Polyline Vertex Exporter ~ by Lee McDonnell ~ 26.11.2009
    (defun c:pExp2 (/ ss tmp i j ent tot dis pt)
    (vl-load-com)
    (if (and (setq ss (ssget '((0 . "*POLYLINE"))))
    (setq tmp (getfiled "Output File" (cond (*load) ("")) "txt;csv" 9)))
    (progn
    (setq *load tmp tmp (open tmp "a") i -1)
    (write-line "X,Y,Layer" tmp)
    (while (setq ent (ssname ss (setq i (1+ i))))
    (setq tot 0. j (1- (vlax-curve-getStartParam ent)))
    (while (<= (setq j (1+ j)) (vlax-curve-getEndParam ent))
    (setq pt (mapcar 'rtos (vlax-curve-getPointatParam ent j)))
    (write-line
    (strcat (car pt) (chr 44) (cadr pt) (chr 44) (vla-get-layer (vlax-ename->vla-object ent)))
    tmp))
    (write-line "" tmp))
    (close tmp)))
    (princ))

    THX for any tips.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Wow, that's some old code...
    I don't quite understand, what do you want the code to do?

    PS: Please edit your post and enclose your code with code tags:

    [code]Your code here[/code]
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  3. #3
    Junior Member leo321's Avatar
    Computer Details
    leo321's Computer Details
    Operating System:
    w7 64bt
    Computer:
    TOSHIBA / DELL
    CPU:
    i5 3°generation
    RAM:
    4 gb other 6gb
    Graphics:
    1gb other 2gb
    Primary Storage:
    500gb
    Secondary Storage:
    2 tera
    Monitor:
    21' and 17'
    Discipline
    Structural
    leo321's Discipline Details
    Occupation
    design Project
    Discipline
    Structural
    Details
    Pipelines, Industrials Units, Wind Farms, Minig, transmission line, thermoelectric, etc..
    Using
    AutoCAD 2012
    Join Date
    Jan 2013
    Location
    São Paulo / Brazil
    Posts
    19

    Default

    I´ll try explian;

    the file returns the polyline reverse clockwise way sample;

    X,Y,Layer
    485172.23,6691696.77,FC 0059
    485157.93,6691697.48,FC 0059
    485156.58,6691666.50,FC 0059
    485171.15,6691665.78,FC 0059
    485172.23,6691696.77,FC 0059

    I would like th clockwise side return, (above)

    485172.23,6691696.77,FC 0059
    485171.15,6691665.78,FC 0059
    485156.58,6691666.50,FC 0059
    485157.93,6691697.48,FC 0059

    If can select the FIRST vertex it will be perfect;

    take this oportunite to say I follow this years, your are the guy, congrates
    sorry for my bad english
    Last edited by leo321; 14th Sep 2017 at 07:43 pm.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Thank you for your compliments

    Please try the following:
    Code:
    (defun c:ptx ( / *error* des ent enx lay lst txt )
    
        (defun *error* ( msg )
            (if (= 'file (type des)) (close des))
            (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
    
        (if (setq txt (getfiled "Create Output File" (cond ( ptx:dir ) ( "" )) "txt;csv" 1))
            (while
                (not
                    (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect 2D polyline <Done>: ")))
                        (cond
                            (   (= 7 (getvar 'errno))
                                (prompt "\nMissed, try again.")
                            )
                            (   (null ent))
                            (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                                (prompt "\nThe selected object is not a 2D polyline.")
                            )
                            (   (not
                                    (or des
                                        (and (setq des (open txt "w"))
                                             (setq ptx:dir (strcat (vl-filename-directory txt) "\\"))
                                             (write-line "X,Y,Layer" des)
                                        )
                                    )
                                )
                                (princ (strcat "\nUnable to open \"" txt "\" for writing."))
                            )
                            (   (setq lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx))
                                      lay (list "," (strcat "," (cdr (assoc 8 enx))))
                                )
                                (foreach vtx (if (LM:listclockwise-p lst) lst (reverse lst))
                                    (write-line (apply 'strcat (mapcar 'strcat (mapcar 'rtos vtx) lay)) des)
                                )
                                (write-line "" des)
                                (prompt (strcat "\n" (itoa (length lst)) " vertices written to " (vl-filename-base txt) (vl-filename-extension txt) "."))
                            )
                        )
                    )
                )
            )
            (princ "\n*Cancel*")
        )
        (*error* nil) (princ)
    )
    
    ;; List Clockwise-p - Lee Mac
    ;; Returns T if the point list is clockwise oriented
    
    (defun LM:listclockwise-p ( lst )
        (minusp
            (apply '+
                (mapcar
                    (function
                        (lambda ( a b )
                            (- (* (car b) (cadr a)) (* (car a) (cadr b)))
                        )
                    )
                    lst (cons (last lst) lst)
                )
            )
        )
    )
    
    (princ)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    And another, allowing optional selection of a start point:
    Code:
    (defun c:ptx ( / *error* cnt des dis ent enx idx lay lst spt tmp txt )
    
        (defun *error* ( msg )
            (if (= 'file (type des)) (close des))
            (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
    
        (if (setq txt (getfiled "Create Output File" (cond ( ptx:dir ) ( "" )) "txt;csv" 1))
            (while
                (not
                    (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect 2D polyline <Done>: ")))
                        (cond
                            (   (= 7 (getvar 'errno))
                                (prompt "\nMissed, try again.")
                            )
                            (   (null ent))
                            (   (/= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
                                (prompt "\nThe selected object is not a 2D polyline.")
                            )
                            (   (not
                                    (or des
                                        (and (setq des (open txt "w"))
                                             (setq ptx:dir (strcat (vl-filename-directory txt) "\\"))
                                             (write-line "X,Y,Layer" des)
                                        )
                                    )
                                )
                                (princ (strcat "\nUnable to open \"" txt "\" for writing."))
                            )
                            (   (setq lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx))
                                      lst (if (LM:listclockwise-p lst) lst (reverse lst))
                                      lay (list "," (strcat "," (cdr (assoc 8 enx))))
                                )
                                (if (setq spt (getpoint "\nSpecify start point <use first vertex>: "))
                                    (progn
                                        (setq idx 0
                                              cnt 1
                                              spt (trans spt 1 ent)
                                              dis (distance spt (car lst))
                                        )
                                        (foreach pnt (cdr lst)
                                            (if (< (setq tmp (distance spt pnt)) dis)
                                                (setq dis tmp
                                                      idx cnt
                                                )
                                            )
                                            (setq cnt (1+ cnt))
                                        )
                                        (repeat idx (setq lst (append (cdr lst) (list (car lst)))))
                                    )
                                )
                                (foreach vtx lst
                                    (write-line (apply 'strcat (mapcar 'strcat (mapcar 'rtos vtx) lay)) des)
                                )
                                (write-line "" des)
                                (prompt (strcat "\n" (itoa (length lst)) " vertices written to " (vl-filename-base txt) (vl-filename-extension txt) "."))
                            )
                        )
                    )
                )
            )
            (princ "\n*Cancel*")
        )
        (*error* nil) (princ)
    )
    
    ;; List Clockwise-p - Lee Mac
    ;; Returns T if the point list is clockwise oriented
    
    (defun LM:listclockwise-p ( lst )
        (minusp
            (apply '+
                (mapcar
                    (function
                        (lambda ( a b )
                            (- (* (car b) (cadr a)) (* (car a) (cadr b)))
                        )
                    )
                    lst (cons (last lst) lst)
                )
            )
        )
    )
    
    (princ)
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  6. #6
    Junior Member leo321's Avatar
    Computer Details
    leo321's Computer Details
    Operating System:
    w7 64bt
    Computer:
    TOSHIBA / DELL
    CPU:
    i5 3°generation
    RAM:
    4 gb other 6gb
    Graphics:
    1gb other 2gb
    Primary Storage:
    500gb
    Secondary Storage:
    2 tera
    Monitor:
    21' and 17'
    Discipline
    Structural
    leo321's Discipline Details
    Occupation
    design Project
    Discipline
    Structural
    Details
    Pipelines, Industrials Units, Wind Farms, Minig, transmission line, thermoelectric, etc..
    Using
    AutoCAD 2012
    Join Date
    Jan 2013
    Location
    São Paulo / Brazil
    Posts
    19

    Default

    Thanks a lot, when come to Brazil your beer is guarantees, it´ll be a honor.

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Registered forum members do not see this ad.


    ..
    ..

    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

Similar Threads

  1. lisp needed : extract poly line vertex X,Y into txt file
    By ayman_48 in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 11th May 2016, 05:09 pm
  2. closest vertex to a point an polyline
    By HARRY-PLOTTER in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 30th Jan 2014, 03:51 pm
  3. Choose a useful point style in AutoCAD
    By AutoCAD Tips Blog in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 26th Nov 2012, 01:10 am
  4. Replies: 17
    Last Post: 6th Apr 2012, 07:57 pm
  5. Block to a certain point or to a vertex
    By JORYROJ in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 4th Oct 2011, 12:48 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