Author Topic: Selection Set processing - sorting SS based on a block attribute. Help needed  (Read 650 times)

0 Members and 1 Guest are viewing this topic.

0john0

  • Mosquito
  • Posts: 17
Hi all,

My first post after lurking for a while!

With the help of the forums here and elsewhere (cadtutor, Adesk etc), and Lee Mac et al I have managed to find and understand enough functions to be able to modify them and glue them together to write a batch plotter to make life easier at work.

We create all our electrical drawings in modelspace, and have multiple drawing sheets in the same modelspace - it's the way it's been done for time immemorial, and getting people to change is harder than learning LISP. Each drawing sheet is defined by a border, inserted as a block, and always the the same paper size. The layout of the blocks is not fixed, and depends on how many sheets - which can range between 4 and 60+ sheets.

As mentioned above - I've managed to cobble together enough bits of LISP and DCL to make a reasonably successful program. I have designed it to either print to PDF from A4 to A0 (via DWG to PDF.PC3) or to select a paper printer for A4 or A3 printing.

The PDF printing works fine as it appends the sheet number to the PDF filename - this means the output files are always in sheet order.

The issue is with the paper printing - the selection set processing run through the inserted blocks in the order they were inserted, which can be random when additional sheets have been added. This results in the paper printing coming out in that order, rather than in sheet number order.

I'm getting a little confused by how the selection set processing works and how attributes are extracted and handled, and can't figure out a way to sort the processing by the SHEETNO attribute.

Any pointers would be greatly appreciated - I can find a lot of examples that do bits of what I want, but they're generally uncommented, and I'm struggling to undertand how they work enough to be able to modify them to suit.

Code below - any questions/comments, please ask  :-)

Block Processing and Plotting functions
Code - Auto/Visual Lisp: [Select]
  1. ;;;################################ Block Processing Function ################################;;;
  2. (defun blockproc (dwgname       path   ofst   pltyp  plsize /
  3.                   ss     i      hnd    tab    lst    at     ax
  4.                   shtno  file   dest   llpt   urpt   mn     mx
  5.                  )
  6.   (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "*A*BORDER*"))))
  7.     (repeat (setq i (sslength ss))
  8.       (setq hnd (ssname ss (setq i (1- i)))
  9.             tab (cdr (assoc 410 (entget hnd)))
  10.             lst (cons (cons tab hnd) lst)
  11.       )
  12.       (setq at (entnext hnd)
  13.             ax (entget at)
  14.       )
  15.       (while
  16.         (/= "SEQEND" (cdr (assoc 0 ax)))
  17.          (if
  18.            (= "SHEETNO" (cdr (assoc 2 ax)))
  19.             (progn (setq shtno (cdr (assoc 1 ax))))
  20.          )
  21.          (setq at (entnext at)
  22.                ax (entget at)
  23.          )
  24.       ) ;_while
  25.       (setq file (strcat dwgname "_SHEET_" shtno ".pdf"))
  26.       (setq dest (strcat path "\\" file))
  27.       (vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx)
  28.       (setq llpt (vlax-safearray->list mn)
  29.             urpt (mapcar '+ llpt ofst)
  30. ;;;                      urpt (vlax-safearray->list mx)
  31.       )
  32.       (mainplot pltyp plsize llpt urpt plstyle dest)
  33.                                         ; Call mainplot function and pass parameters
  34.     ) ;_repeat
  35.   ) ;_if
  36. ) ;_defun
  37.  
  38. ;;;################### Plot Function ####################;;;
  39.  
  40. (defun mainplot (pltyp plsize llpt urpt plstyle dest)
  41.   (if (= pltyp "DWG to PDF.pc3")        ; If PDF
  42.     (command "-plot"                    ; Run PDF plot
  43.              "Y"    "Model"       pltyp  plsize "M"    "L"    "N"
  44.              "W"    llpt   urpt   "F"    "C"    "Y"    plstyle
  45.              "Y"    "A"    dest   "N"    "Y"
  46.             ) ;_command
  47.                                         ; Else run paper plot
  48.     (command "_.plot"      "Y"    "Model"       pltyp  plsize "M"
  49.              "L"    "N"    "W"    llpt   urpt   "F"    "C"    "Y"
  50.              plstyle       "Y"    "A"    "N"    "N"    "Y"
  51.             ) ;_command
  52.   ) ;_if
  53. ) ;_defun

Main program code
Code - Auto/Visual Lisp: [Select]
  1. (defun C:X-PLOT (/ dcl_id status plsize pltyp plstyle view userclick)
  2.   (or op1 (setq op1 "r1"))
  3.   (or op2 (setq op2 ""))
  4.   (or op3 (setq op3 ""))
  5.   (setvar "CMDECHO" 0)
  6.   (setq dwgname (strcat (vl-filename-base (getvar "dwgname"))))
  7.   (setq path (strcat "C:\\PDF\\" dwgname))
  8.  
  9. ;;;############################### DCL Dialog Box Handling ##############################;;;
  10.   (if
  11.     (setq dcl_id
  12.            (load_dialog "K:\\wallsend\\Electrical\\LISP\\x-plot.dcl")
  13.     )
  14.      (if
  15.        (new_dialog "xplot" dcl_id)
  16.         (progn
  17.           (set_tile "rb1" "1")
  18.           (setq plstyle "standard.ctb")
  19.           (set_tile "rb5" "1")
  20.           (setq op1 "rb5")
  21.           (setq op2 "")
  22.           (setq op3 "")
  23.           (setq plsize "ISO A0 (841.00 x 1189.00 MM)")
  24.           (setq pltyp "DWG to PDF.pc3")
  25.  
  26. ;;;################################ Plot Style Selection ################################;;;
  27.           (action_tile
  28.             "rb1"
  29.             "(setq plstyle \"standard.ctb\")"
  30.           )
  31.  
  32.           (action_tile
  33.             "rb2"
  34.             "(setq plstyle \"hyd circuit.ctb\")"
  35.           )
  36.  
  37.           (action_tile
  38.             "rb3"
  39.             "(setq plstyle \"colour assy.ctb\")"
  40.           )
  41.  
  42. ;;;############################# Size and Output Selection #############################;;;
  43.           (action_tile
  44.             "op1"
  45.             "(progn
  46.             (set_tile op3 \"0\")
  47.                              (setq op1 $value op3 \"\")
  48.            (set_tile op2 \"0\")
  49.                              (setq op1 $value op2 \"\")
  50.            )"
  51.           )
  52.  
  53.           (action_tile
  54.             "op2"
  55.             "(progn
  56.             (set_tile op1 \"0\")
  57.                              (setq op2 $value op1 \"\")
  58.             (set_tile op3 \"0\")
  59.                              (setq op2 $value op3 \"\")
  60.            )"
  61.           )
  62.  
  63.           (action_tile
  64.             "op3"
  65.             "(progn
  66.             (set_tile op2 \"0\")
  67.                              (setq op3 $value op2 \"\")
  68.            (set_tile op1 \"0\")
  69.                              (setq op3 $value op1 \"\")
  70.            )"
  71.           )
  72.           (set_tile "op1" op1)
  73.           (set_tile "op2" op2)
  74.           (set_tile "op3" op3)
  75.  
  76. ;;;################################ OK/Cancel Selection ################################;;;
  77.           (action_tile
  78.             "cancel"
  79.             "(done_dialog)(setq userclick nil)"
  80.           )
  81.           (action_tile
  82.             "accept"
  83.             "(done_dialog) (setq userclick T)"
  84.           )
  85.  
  86.           (setq status (start_dialog))
  87.           (unload_dialog dcl_id)
  88.         )
  89.         (exit)
  90.      )
  91.   )
  92. ;;;======================================================================================;;;
  93.  
  94. ;;;############################# Processing Print Selection #############################;;;
  95.   (if userclick
  96.     (progn
  97.       (cond                             ; Conditional test of radio button
  98.  
  99. ;;;#################################### A0 PDF Print ####################################;;;
  100.         ((= op1 "rb5")
  101.          (setq plsize "ISO expand A0 (841.00 x 1189.00 MM)")
  102.          (setq pltyp "DWG to PDF.pc3")
  103.          (setq ofst '(1160.0 812.0 0.0))
  104.          (vl-mkdir path)
  105.  
  106.          (blockproc dwgname path ofst pltyp plsize)
  107.                                         ; Call blocproc function and pass parameters
  108.  
  109.          (startapp "explorer" path)
  110.          (princ)
  111.         )
  112.  
  113. ;;;#################################### A1 PDF Print ####################################;;;
  114.         ((= op1 "rb6")
  115.          (setq plsize "ISO expand A1 (841.00 x 594.00 MM)")
  116.          (setq pltyp "DWG to PDF.pc3")
  117.          (setq ofst '(812.0 563.0 0.0))
  118.          (vl-mkdir path)
  119.  
  120.          (blockproc dwgname path ofst pltyp plsize)
  121.                                         ; Call blocproc function and pass parameters
  122.  
  123.          (startapp "explorer" path)
  124.          (princ)
  125.         )
  126.  
  127. ;;;#################################### A2 PDF Print ####################################;;;
  128.         ((= op1 "rb7")
  129.          (setq plsize "ISO expand A2 (594.00 x 420.00 MM)")
  130.          (setq pltyp "DWG to PDF.pc3")
  131.          (setq ofst '(564.0 388.0 0.0))
  132.          (vl-mkdir path)
  133.  
  134.          (blockproc dwgname path ofst pltyp plsize)
  135.                                         ; Call blocproc function and pass parameters
  136.  
  137.          (startapp "explorer" path)
  138.          (princ)
  139.         )
  140.  
  141. ;;;#################################### A3 PDF Print ####################################;;;
  142.         ((= op1 "rb8")
  143.          (setq plsize "ISO expand A3 (420.00 x 297.00 MM)")
  144.          (setq pltyp "DWG to PDF.pc3")
  145.          (setq ofst '(396.0 270.0 0.0))
  146.          (vl-mkdir path)
  147.  
  148.          (blockproc dwgname path ofst pltyp plsize)
  149.                                         ; Call blocproc function and pass parameters
  150.  
  151.          (startapp "explorer" path)
  152.          (princ)
  153.         )
  154.  
  155. ;;;#################################### A4 PDF Print ####################################;;;
  156.         ((= op1 "rb9")
  157.          (setq plsize "ISO expand A4 (297.00 x 210.00 MM)")
  158.          (setq pltyp "DWG to PDF.pc3")
  159.          (setq ofst '(277.0 187.0 0.0))
  160.          (vl-mkdir path)
  161.  
  162.          (blockproc dwgname path ofst pltyp plsize)
  163.                                         ; Call blocproc function and pass parameters
  164.          
  165. ;;;      (setq dwgname (strcat (vl-filename-base (getvar "dwgname"))))
  166. ;;;      (setq path (strcat "C:\\PDF\\" dwgname))
  167. ;;;      (if
  168. ;;;        (setq ss (ssget "_X" '((0 . "INSERT") (2 . "*A*BORDER*"))))
  169. ;;;         (repeat (setq i (sslength ss))
  170. ;;;           (setq hnd (ssname ss (setq i (1- i)))
  171. ;;;                 tab (cdr (assoc 410 (entget hnd)))
  172. ;;;                 lst (cons (cons tab hnd) lst)
  173. ;;;           )
  174. ;;;           (setq at (entnext hnd)
  175. ;;;                 ax (entget at)
  176. ;;;           )
  177. ;;;           (while
  178. ;;;             (/= "SEQEND" (cdr (assoc 0 ax)))
  179. ;;;              (if
  180. ;;;                (= "SHEETNO" (cdr (assoc 2 ax)))
  181. ;;;                 (progn (setq shtno (cdr (assoc 1 ax))))
  182. ;;;              )
  183. ;;;              (setq at (entnext at)
  184. ;;;                    ax (entget at)
  185. ;;;              )
  186. ;;;           ) ;_while
  187. ;;;           (setq file (strcat
  188. ;;;                        dwgname
  189. ;;;                        "_SHEET_"
  190. ;;;                        shtno
  191. ;;;                        ".pdf"
  192. ;;;                      )
  193. ;;;           )
  194. ;;;           (setq
  195. ;;;             dest (strcat path "\\" file)
  196. ;;;           )
  197. ;;;           (vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx)
  198. ;;;           (setq llpt (vlax-safearray->list mn)
  199. ;;;                 urpt (vlax-safearray->list mx)
  200. ;;;                                     ;A4 URPT is LLPT +396, +270
  201. ;;;           )
  202. ;;;           (mainplot pltyp plsize llpt urpt plstyle dest)
  203. ;;;                                     ; call mainplot function
  204. ;;;         ) ;_repeat
  205. ;;;
  206. ;;;      ) ;_if
  207.          (startapp "explorer" path)
  208.          (princ)
  209.         )
  210.  
  211. ;;;#################################### A3 O1D Paper Print ####################################;;;
  212.         ((= op2 "rb10")
  213.          (setq plsize "A3")
  214.                                         ;        (setq pltyp "Office 1 Downstairs Printer Colour.pc3")
  215.          (setq pltyp "\\\\TW3\\Office 1 Downstairs Printer")
  216.          (blockproc dwgname path ofst pltyp plsize)
  217.                                         ; Call blocproc function and pass parameters
  218.  
  219.         ) ;_while
  220.  
  221.  
  222. ;;;#################################### A4 O1D Paper Print ####################################;;;
  223.         ((= op2 "rb11")
  224.          (setq plsize "A4")
  225.                                         ;        (setq pltyp "Office 1 Downstairs Printer Colour.pc3")
  226.          (setq pltyp "\\\\TW3\\Office 1 Downstairs Printer")
  227.          (blockproc dwgname path ofst pltyp plsize)
  228.                                         ; Call blocproc function and pass parameters
  229.         )
  230.  
  231.  
  232. ;;;#################################### A3 O1U Paper Print ####################################;;;
  233.         ((= op2 "rb12")
  234.          (setq plsize "A3")
  235.                                         ;        (setq pltyp "Office 1 Upstairs Printer.pc3")
  236.          (setq pltyp "\\\\TW3\\OFFICE1UP")
  237.          (blockproc dwgname path ofst pltyp plsize)
  238.                                         ; Call blocproc function and pass parameters
  239.         )
  240.  
  241.  
  242. ;;;#################################### A4 O1U Paper Print ####################################;;;
  243.         ((= op2 "rb13")
  244.          (setq plsize "A4")
  245.                                         ;        (setq pltyp "Office 1 Upstairs Printer.pc3")
  246.          (setq pltyp "\\\\TW3\\OFFICE1UP")
  247.          (blockproc dwgname path ofst pltyp plsize)
  248.                                         ; Call blocproc function and pass parameters
  249.         )
  250.  
  251.  
  252. ;;;#################################### A3 i19 Paper Print ####################################;;;
  253.         ((= op3 "rb14")
  254.          (setq plsize "A3")
  255.                                         ;        (setq pltyp "i19DOWNSTAIRS.pc3")
  256.          (setq pltyp "\\\\TT2\\i19DOWNSTAIRS")
  257.          (blockproc dwgname path ofst pltyp plsize)
  258.                                         ; Call blocproc function and pass parameters
  259.         )
  260.  
  261. ;;;#################################### A4 i19 Paper Print ####################################;;;
  262.         ((= op3 "rb15")
  263.          (setq plsize "A4")
  264.                                         ;        (setq pltyp "i19DOWNSTAIRS.pc3")
  265.          (setq pltyp "\\\\TT2\\i19DOWNSTAIRS")
  266.          (blockproc dwgname path ofst pltyp plsize)
  267.                                         ; Call blocproc function and pass parameters
  268.         )
  269.  
  270. ;;;#################################### A3 O3 Paper Print ####################################;;;
  271.         ((= op3 "rb16")
  272.          (setq plsize "A3")
  273.                                         ;        (setq pltyp "Office 3.pc3")
  274.          (setq pltyp "\\\\TW3\\Office 3")
  275.          (blockproc dwgname path ofst pltyp plsize)
  276.                                         ; Call blocproc function and pass parameters
  277.         )
  278.  
  279.  
  280. ;;;#################################### A4 O3 Paper Print ####################################;;;
  281.         ((= op3 "rb17")
  282.          (setq plsize "A4")
  283.                                         ;        (setq pltyp "Office 3.pc3")
  284.          (setq pltyp "\\\\TW3\\Office 3")
  285.          (blockproc dwgname path ofst pltyp plsize)
  286.                                         ; Call blocproc function and pass parameters
  287.         )
  288.  
  289.  
  290.       ) ;_cond
  291.  
  292.  
  293.     ) ;_progn
  294.   ) ;_if
  295.  
  296.   (princ)
  297. )
  298.  
  299. ;;;################################ Block Processing Function ################################;;;
  300. (defun blockproc (dwgname       path   ofst   pltyp  plsize /
  301.                   ss     i      hnd    tab    lst    at     ax
  302.                   shtno  file   dest   llpt   urpt   mn     mx
  303.                  )
  304.   (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "*A*BORDER*"))))
  305.     (repeat (setq i (sslength ss))
  306.       (setq hnd (ssname ss (setq i (1- i)))
  307.             tab (cdr (assoc 410 (entget hnd)))
  308.             lst (cons (cons tab hnd) lst)
  309.       )
  310.       (setq at (entnext hnd)
  311.             ax (entget at)
  312.       )
  313.       (while
  314.         (/= "SEQEND" (cdr (assoc 0 ax)))
  315.          (if
  316.            (= "SHEETNO" (cdr (assoc 2 ax)))
  317.             (progn (setq shtno (cdr (assoc 1 ax))))
  318.          )
  319.          (setq at (entnext at)
  320.                ax (entget at)
  321.          )
  322.       ) ;_while
  323.       (setq file (strcat dwgname "_SHEET_" shtno ".pdf"))
  324.       (setq dest (strcat path "\\" file))
  325.       (vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx)
  326.       (setq llpt (vlax-safearray->list mn)
  327.             urpt (mapcar '+ llpt ofst)
  328. ;;;                      urpt (vlax-safearray->list mx)
  329.       )
  330.       (mainplot pltyp plsize llpt urpt plstyle dest)
  331.                                         ; Call mainplot function and pass parameters
  332.     ) ;_repeat
  333.   ) ;_if
  334. ) ;_defun
  335.  
  336. ;;;################### Plot Function ####################;;;
  337.  
  338. (defun mainplot (pltyp plsize llpt urpt plstyle dest)
  339.   (if (= pltyp "DWG to PDF.pc3")        ; If PDF
  340.     (command "-plot"                    ; Run PDF plot
  341.              "Y"    "Model"       pltyp  plsize "M"    "L"    "N"
  342.              "W"    llpt   urpt   "F"    "C"    "Y"    plstyle
  343.              "Y"    "A"    dest   "N"    "Y"
  344.             ) ;_command
  345.                                         ; Else run paper plot
  346.     (command "_.plot"      "Y"    "Model"       pltyp  plsize "M"
  347.              "L"    "N"    "W"    llpt   urpt   "F"    "C"    "Y"
  348.              plstyle       "Y"    "A"    "N"    "N"    "Y"
  349.             ) ;_command
  350.   ) ;_if
  351. ) ;_defun

DCL code
Code: [Select]
xplot : dialog {
    label = "Plot a Load of Sheetz";
: row {

     : boxed_radio_column {
      label = "Choose Plot Style :";

        //change the plot style to suit your own
        : radio_button { label = "Standard"; key = "rb1";}
        //change the plot style to suit your own
        : radio_button { label = "Hydraulic"; key = "rb2";}
//change the plot style to suit your own
        : radio_button { label = "Colour"; key = "rb3";}

     }
: boxed_row {
label = "Output Format :";
: radio_column {
   key = "op1";
      label = "Plot PDF :";


        : radio_button : tile { label = "A&0 -  1189 x 841"; key = "rb5"; value = "1";}
        : radio_button : tile { label = "A&1 -   841 x 594"; key = "rb6";}
        : radio_button : tile { label = "A&2 -   594 x 420"; key = "rb7";}
        : radio_button : tile { label = "A&3 -   420 x 297"; key = "rb8";}
        : radio_button : tile { label = "A&4 -   297 x 210"; key = "rb9";}

     
     }
: boxed_radio_row {
label = "Plot to Paper :";
// key = "op2";
: radio_column {
   key = "op2";



        : radio_button : tile { label = "A3 - Office 1 Dn"; key = "rb10"; value = "0";}
        : radio_button : tile { label = "A4 - Office 1 Dn"; key = "rb11";}
        : radio_button : tile { label = "A3 - Office 1 Up"; key = "rb12";}
        : radio_button : tile { label = "A4 - Office 1 Up"; key = "rb13";}

     
     }
: radio_column {
   key = "op3";



        : radio_button : tile { label = "A3 - i19"; key = "rb14"; value = "0";}
        : radio_button : tile { label = "A4 - i19"; key = "rb15";}
        : radio_button : tile { label = "A3 - Office 3"; key = "rb16";}
        : radio_button : tile { label = "A4 - Office 3"; key = "rb17";}

     
     }
}
}
}
      ok_cancel ; 

               : paragraph {
: text_part {
                   label = "Hacked and Cobbled together";
                 }
                 : text_part {
                   label = "by John Stewart";
                 }
               }
}

« Last Edit: October 18, 2018, 08:13:16 AM by 0john0 »

ronjonp

  • Needs a day job
  • Posts: 7050
Welcome to TheSwamp :) .. see if this helps out a bit:
Code - Auto/Visual Lisp: [Select]
  1. (defun blockproc
  2.        (dwgname path ofst pltyp plsize / ss i hnd tab l lst at ax shtno file dest llpt urpt mn mx)
  3.   (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "*A*BORDER*"))))
  4.     (progn (repeat (setq i (sslength ss))
  5.              (setq hnd (ssname ss (setq i (1- i)))
  6.                    tab (cdr (assoc 410 (entget hnd)))
  7.                    lst (cons (cons tab hnd) lst)
  8.              )
  9.              (setq at (entnext hnd)
  10.                    ax (entget at)
  11.              )
  12.              (while (/= "SEQEND" (cdr (assoc 0 ax)))
  13.                (if (= "SHEETNO" (cdr (assoc 2 ax)))
  14.                  (progn (setq shtno (cdr (assoc 1 ax))))
  15.                )
  16.                (setq at (entnext at)
  17.                      ax (entget at)
  18.                )
  19.              ) ;_while
  20.              (setq file (strcat dwgname "_SHEET_" shtno ".pdf"))
  21.              (setq dest (strcat path "\\" file))
  22.              (vla-getboundingbox (vlax-ename->vla-object hnd) 'mn 'mx)
  23.              (setq llpt (vlax-safearray->list mn)
  24.                    urpt (mapcar '+ llpt ofst)
  25.              )
  26.              ;; Store the information in a list to sort
  27.              (setq l (cons (list shtno llpt urpt dest) l))
  28.            )
  29.            ;; Sort the list by shtno and run 'mainplot'
  30.            ;; Sorting strings get funky sometimes
  31.            ;; example (print (vl-sort (mapcar 'itoa '(1 2 3 4 5 6 7 8 9 10 100 101 102 103)) '<))
  32.            (foreach tb (vl-sort l '(lambda (a b) (< (car a) (car b))))
  33.              (mainplot pltyp plsize (cadr tb) (caddr tb) plstyle (last tb))
  34.            )
  35.     ) ;_repeat
  36.   ) ;_if
  37. ) ;_defun

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

0john0

  • Mosquito
  • Posts: 17
Hi Ron,

Thanks for the welcome  :-) and thanks for the assistance!

I've added your code and it works perfectly  :-D (well it did once I'd noticed I'd missed adding the "l" to the variables list  :oops:!

I'm at home so I've just stuck a little line print in place of the paper print function to dump out the "llpt" and "urpt" values to prove that the sheets are sorted in the correct order.

Time to study how your code works! It's 15 years since I did C and VB at uni so I'm a little rusty!!

Thanks again for the help!

ronjonp

  • Needs a day job
  • Posts: 7050
Hi Ron,

Thanks for the welcome  :-) and thanks for the assistance!

I've added your code and it works perfectly  :-D (well it did once I'd noticed I'd missed adding the "l" to the variables list  :oops:!

I'm at home so I've just stuck a little line print in place of the paper print function to dump out the "llpt" and "urpt" values to prove that the sheets are sorted in the correct order.

Time to study how your code works! It's 15 years since I did C and VB at uni so I'm a little rusty!!

Thanks again for the help!
Glad to help out. Holler if you have more questions.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

0john0

  • Mosquito
  • Posts: 17
I've done a little more testing this morning at work, and found a slight issue...

I tried it on a 25 sheet drawing and ran into the issue of vl-sort handling ascii numbers - it prints sheet 1, then 10, 11, 12 etc, rather than 1, 2, 3, 4, etc.

I naively thought I could just atoi the shtno further up, but that results in:  error: bad argument type: stringp 1

I'm trying to find an alternative to vl-sort that will work - it's probably my lack of understanding how the 
Code - Auto/Visual Lisp: [Select]
  1. (foreach tb (vl-sort tsl '(lambda (a b) (< (car a) (car b))))
works as any other I try from http://www.theswamp.org/index.php?topic=38292 results in too many argument errors  :-(

Sadly I have actual design work to do today! I'll try and have a look later on this evening to better my understanding of what is happening  :-)
« Last Edit: October 18, 2018, 08:11:44 AM by 0john0 »

0john0

  • Mosquito
  • Posts: 17
Panic over - used my grey matter to do a search and found a solution based on this one: http://www.theswamp.org/index.php?topic=43116.msg483279#msg483279

Putting the atoi inside the vl-sort function  :idea:

Code - Auto/Visual Lisp: [Select]
  1. (foreach tb (vl-sort l '(lambda (a b) (< (atoi (car a)) (atoi (car b)))))

 :-)

ronjonp

  • Needs a day job
  • Posts: 7050
Panic over - used my grey matter to do a search and found a solution based on this one: http://www.theswamp.org/index.php?topic=43116.msg483279#msg483279

Putting the atoi inside the vl-sort function  :idea:

Code - Auto/Visual Lisp: [Select]
  1. (foreach tb (vl-sort l '(lambda (a b) (< (atoi (car a)) (atoi (car b)))))

 :-)
Nice job figuring it out! If you look at the comments in my code above there is an example that shows this behavior:
Code - Auto/Visual Lisp: [Select]
  1.            ;; Sorting strings get funky sometimes
  2.            ;; example (print (vl-sort (mapcar 'itoa '(1 2 3 4 5 6 7 8 9 10 100 101 102 103)) '<))
Result:
Code - Auto/Visual Lisp: [Select]
  1. ("1" "10" "100" "101" "102" "103" "2" "3" "4" "5" "6" "7" "8" "9")

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

0john0

  • Mosquito
  • Posts: 17
Ah, yes - spotted that now!

My mind was melting a bit trying to figure out the lambda bit - it is sinking in, slowly!

Thanks again for the help  :-)