Help combining two lisp routines (plot and vl-sort)

Help combining two lisp routines (plot and vl-sort)

fleshget
Participant Participant
345 Views
5 Replies
Message 1 of 6

Help combining two lisp routines (plot and vl-sort)

fleshget
Participant
Participant

Hi there.

 

i'm using plot lisp routine below.

 

(defun c:pazpdf ( / f i s )
    (setq f (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname))))
    (if (setq s (ssget '((0 . "LWPOLYLINE"))))
        (repeat (setq i (sslength s))
            (apply 'plotwindow (cons f (windowpoints (ssname s (setq i (1- i))))))
        )
    )
    (princ)
)

(defun plotwindow ( f p q )
    (command
        "_.-plot"
        "_Yes"  ; Detailed plot configuration?
        "Model" ; Enter Layout Name
        "DWG To PDF.pc3" ; Enter an output device name
        "User 1 (867.00 x 620.00 MM)" ; Enter Paper Size (User Defined)
        "_M"  ; Enter paper Units
        "_L"  ; Enter Drawing Orientation
        "_N"  ; Plot Upside Down?
        "_W"  ; Enter Plot Area
        "_non" p "_non" q
        "1:1"  ; Enter Plot Scale
        "_C"  ; Enter plot offset
        "_Y"  ; Plot with Style
        "Pazarcık.ctb"   ; Enter plot style table name (none)
        "_Y"  ; Plot with lineweights?
        "As Displayed" ; Enter Shade Plot Settings
        (uniquefilename f ".pdf") ; this line is pdf file name, if you use it, remove the comma from the start
        ;"_N"  ; Write the plot to a file (if you convert to pdf, this line wil be deleted...)
        "_N"  ; Save Changes to page setup
        "_Y"  ; Proceed with plot
    )
        
)

(defun uniquefilename ( pth ext / fnm tmp )
    (if (findfile (setq fnm (strcat pth ext)))
        (progn
            (setq tmp 1)
            (while (findfile (setq fnm (strcat pth "(" (itoa (setq tmp (1+ tmp))) ")" ext))))
        )
    )
    fnm
)

(defun windowpoints ( ent )
    (   (lambda ( lst ) (mapcar '(lambda ( x ) (apply 'mapcar (cons x lst))) '(min max)))
        (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))
    )
)

(princ)

 

i must select the outer polylines by bottom-right to top-left then it plot to opposite sort like top-left to bottom-right.

 

that's okey no problem for me. it's working like a charm about many years 🙂

 

then i think it's should be more useful like plot all sheets one-click.

 

i do search google about selection sort properties. i've find it out one then i customize a little bit. like below:

 

 

;SANIRIM OLDU !!!!!
(defun c:eaa ( / ss lst i )

  (setq ss (ssget '((0 . "LWPOLYLINE") (8 . "PLOTLINE"))))
  
  (repeat (setq i (sslength ss))
    (setq lst (cons (ssname ss (setq i (1- i))) lst)))

  (setq lst (vl-sort lst (function (lambda (x y) (< (cadr (assoc 10 (entget x)))
						    (cadr (assoc 10 (entget y)))))))
	lst (vl-sort lst (function (lambda (x y) (> (caddr (assoc 10 (entget x)))
						    (caddr (assoc 10 (entget y))))))))

  (command "pline")
  (foreach e lst (command "_none" (cdr (assoc 10 (entget e)))))
  (command)	   
    
  (princ)
)

 

its sorted plines (top-left to bottom-right) about selected with window method one click.

 

problem is here because i do not know about autolisp well to combine them.

 

now i need a lisp routine like that:

i will select all polylines by window method then it's will plot first top-left to bottom right.

thanks for advance.

 

0 Likes
Accepted solutions (1)
346 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

I have a routine for making a list of Block names sorted in any directions you like, called BlockSSSort.lsp, >here<.  It could be modified easily enough to sort Polylines if they're as regular as in your sample drawing, and if they always start at the same corner [as yours all do at the bottom right].  It reads the location to sort by from the DXF-code 10 entry in entity data, which is the insertion points of a Block, but the first of multiple such entries is the starting vertex of a Polyline.  Would all of them always start at the same corner like that, and be the same size?

 

There are two ways to sort from top left to bottom right, resulting in these sequences in your drawing:

Top row first, each row sorted from Left to right [I assume this is what you want, but maybe not]:

6 5 4 1 2 3

[which BlockSSSort would give you from the usage (bsss "T" "L")]

or Left column first, each column sorted from Top down:

6 1 5 2 4 3

[from (bsss "L" "T")]

Kent Cooper, AIA
0 Likes
Message 3 of 6

fleshget
Participant
Participant

thanks for answer mate.

my sheets sorted regular as always like sample drawing. it could be sorted like 6 5 4 1 2 3

i will try to modify your bsss routine but it look like complex little bit for me 🙂

 

my english is bad and i cant understood you correctly. so i think misspeak to you about second lisp that i shared. find it out quickly and understand about selection sorting logic. my purpose is not shorting any vertex of polylines. purpose is convert to pdf inside of all selected polylines with window method. first top-left to the bottom-right. as sample 6 5 4 1 2 3

 

is there any way to combine these logic with working together?

 

thanks again for your answer mate!

0 Likes
Message 4 of 6

paullimapa
Mentor
Mentor
Accepted solution

give this a try

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-combining-two-lisp-routines-plot-and-vl-sort/td-p/11543674
(defun c:pazpdf ( / f i s lst)
    (setq f (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname))))
    (if (setq s (ssget '((0 . "LWPOLYLINE")(8 . "PLOTLINE"))))
      (progn ; progn
        ; build list of plines selected
        (repeat (setq i (sslength s))
         (setq lst (cons (ssname s (setq i (1- i))) lst))
        ) ; repeat
        ; sort function 1
        (setq lst 
         (vl-sort lst 
          (function (lambda (y x) (< (cadr (assoc 10 (entget x)))(cadr (assoc 10 (entget y))))))
         )
        ; sort function 2
	          lst 
         (vl-sort lst 
          (function (lambda (y x) (> (caddr (assoc 10 (entget x)))(caddr (assoc 10 (entget y))))))
         )
        ) ; setq
        ; apply plotwindow function on now sorted list of plines
        (repeat (setq i (length lst))
            (apply 'plotwindow (cons f (windowpoints (nth (setq i (1- i)) lst))))
        )
	  ) ; progn
    )
    (princ)
) 

(defun plotwindow ( f p q )
    (command
        "_.-plot"
        "_Yes"  ; Detailed plot configuration?
        "Model" ; Enter Layout Name
        "DWG To PDF.pc3" ; Enter an output device name
        "User 1 (867.00 x 620.00 MM)" ; Enter Paper Size (User Defined)
        "_M"  ; Enter paper Units
        "_L"  ; Enter Drawing Orientation
        "_N"  ; Plot Upside Down?
        "_W"  ; Enter Plot Area
        "_non" p "_non" q
        "1:1"  ; Enter Plot Scale
        "_C"  ; Enter plot offset
        "_Y"  ; Plot with Style
;        "Pazarcık.ctb"   ; Enter plot style table name (none)
        "monochrome.ctb"  ;  Enter plot style table name (none)
        "_Y"  ; Plot with lineweights?
        "As Displayed" ; Enter Shade Plot Settings
        (uniquefilename f ".pdf") ; this line is pdf file name, if you use it, remove the comma from the start
        ;"_N"  ; Write the plot to a file (if you convert to pdf, this line wil be deleted...)
        "_N"  ; Save Changes to page setup
        "_Y"  ; Proceed with plot
    )
        
)

(defun uniquefilename ( pth ext / fnm tmp )
    (if (findfile (setq fnm (strcat pth ext)))
        (progn
            (setq tmp 1)
            (while (findfile (setq fnm (strcat pth "(" (itoa (setq tmp (1+ tmp))) ")" ext))))
        )
    )
    fnm
)

(defun windowpoints ( ent )
    (   (lambda ( lst ) (mapcar '(lambda ( x ) (apply 'mapcar (cons x lst))) '(min max)))
        (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget ent)))
    )
)

(princ)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 6

fleshget
Participant
Participant

we imagine, you make it happen 🙂 thanks so much paul! it is worked perfectly! now i take a look to codes \m/

 

and also thanks to kent1cooper ✌️

 

greetings!

0 Likes
Message 6 of 6

paullimapa
Mentor
Mentor

Glad to have helped....cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes