Jump to content

Recommended Posts

Posted (edited)

for example i select 10 polyline to a list then i want to sort this list by coordinate y of firt point of each polyline ( every polyline have many point)

Edited by superlong
Posted

Assuming LWPolylines, and that their direction of definition is suitable... see

 

 

http://forums.augi.com/showthread.php?137837-Sort-Selectionset-by-X-coord&p=1164026&viewfull=1#post1164026

 

 

That post (i.e. the line of code in point 2) describes how you would sort a list by x value.

To sort by y, take that code, and just replace BOTH occasions of "cadr" with "caddr".

To sort by z, you would do the same but replacing "cadr" with "last", or "cadddr".

Posted

this is my code to get area for many polyline select but i want to sort their polyline before get area

(defun c:yeah ( / dt dt1 dt2 rec1 rec2 pt ss)

(if (not sc3) (setq sc3 2))
(setq sc1 (getreal (strcat "\nChi\U+1EC1u cao Text <")))
(if (not sc1) (setq sc1 sc3) (setq sc3 sc1))
(setq sc9 (cdr (assoc 1 (entget (car (entsel "\nChon Text Ly Trinh <end of> : "))))))
(setq dt (ssget '((0 . "LWPOLYLINE"))))

(setq sdt (sslength dt)
K SDT
i 0)
(while
(setq dt1 (ssname dt i)


dt2 (ssname dt (1+ i))
       i (1+ i)
K (- K 1)

rec1 (acet-geom-vertex-list dt1)




rec2 (acet-geom-vertex-list dt2)

pt (nth 0 rec1)

)

(if (and (< (car (nth 0 rec1)) (car (nth 2 rec1))) (< (car (nth 0 rec2)) (car (nth 2 rec2))))
(setq ss (append rec1 (reverse rec2) (list pt))))
(if (and (> (car (nth 0 rec1)) (car (nth 2 rec1))) (> (car (nth 0 rec2)) (car (nth 2 rec2))))
(setq ss (append rec1 (reverse rec2) (list pt))))
(if (and (< (car (nth 0 rec1)) (car (nth 2 rec1))) (> (car (nth 0 rec2)) (car (nth 2 rec2))))
(setq ss (append rec1 rec2 (list pt))))
(if (and (> (car (nth 0 rec1)) (car (nth 2 rec1))) (< (car (nth 0 rec2)) (car (nth 2 rec2))))
(setq ss (append rec1 rec2 (list pt))))



(acet-pline-make (list ss))
(command "area" "o" (entlast))
(setq dientich (getvar "area"))

(setq s (strcat (rtos dientich 2 2)))
(command "INSERT" "DIENTICHL" (nth 1 rec2) SC1 SC1 0 sc9 K S)
)

(princ "\nThanks for Using - Ho\U+00E0ng Long Auto Lisp
Phone:0933118500
Mail:longnguyen4563@gmail.com")
(PRINC))

Posted

This would take your original selection set of LWPolylines, sort them by the y value of the FIRST vertex of each polyline in DESCENDING order, and then recreate your selection set IN THAT ORDER.

 

 

You might want to be localising more variables than you currently are. There doesn't seem to be any point in having both SC1 and SC3 as global variables. And SC9? SDT? And so on...

 

 

(defun c:yeah ( / dt dt1 dt2 rec1 rec2 pt ss)
 (setq
   sc3
    (setq
      sc1
       (cond
         ((getreal "\nChi\U+1EC1u cao Text <"))
         (sc3)
         (2.0)
         )
       )
   )
 (if
   (and
     (setq sc9 (entsel "\nChon Text Ly Trinh <end of> : "))
     (setq sc9 (cdr (assoc 1 (entget (car sc9)))))
     (setq dt (ssget '((0 . "LWPOLYLINE"))))
     (> (setq sdt (sslength dt)) 1)
     )
   (progn
     (
      (lambda ( / i e ss )
        (repeat (setq i sdt)
          (setq e (ssname dt (setq i (1- i)))
                ss (cons
                     (cons
                       (caddr
                         (assoc 10 (entget e))
                         )
                       e
                       )
                     ss
                     )
                )
          )
        (setq dt (ssadd))
        (foreach x (vl-sort
                     ss
                     (function
                       (lambda ( a b )
                         (> (car a) (car b))
                         )
                       )
                     )
          (ssadd (cdr x) dt)
          )
        )
       )
     
     ;; I'm not touching anything below here!!
     (setq K SDT
           i 0)
     (while
       (setq dt1 (ssname dt i)
             dt2 (ssname dt (1+ i))
             i (1+ i)
             K (- K 1)
             rec1 (acet-geom-vertex-list dt1)
             rec2 (acet-geom-vertex-list dt2)
             pt (nth 0 rec1)
             )
       (if (and (< (car (nth 0 rec1)) (car (nth 2 rec1))) (< (car (nth 0 rec2)) (car (nth 2 rec2))))
         (setq ss (append rec1 (reverse rec2) (list pt))))
       (if (and (> (car (nth 0 rec1)) (car (nth 2 rec1))) (> (car (nth 0 rec2)) (car (nth 2 rec2))))
         (setq ss (append rec1 (reverse rec2) (list pt))))
       (if (and (< (car (nth 0 rec1)) (car (nth 2 rec1))) (> (car (nth 0 rec2)) (car (nth 2 rec2))))
         (setq ss (append rec1 rec2 (list pt))))
       (if (and (> (car (nth 0 rec1)) (car (nth 2 rec1))) (< (car (nth 0 rec2)) (car (nth 2 rec2))))
         (setq ss (append rec1 rec2 (list pt))))
       (acet-pline-make (list ss))
       (command "area" "o" (entlast))
       (setq dientich (getvar "area"))
       (setq s (strcat (rtos dientich 2 2)))
       (command "INSERT" "DIENTICHL" (nth 1 rec2) SC1 SC1 0 sc9 K S)
       )
     (princ "\nThanks for Using - Ho\U+00E0ng Long Auto Lisp
     Phone:0933118500
     Mail:longnguyen4563@gmail.com")
     )
   )
 (princ)
 )

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...