Author Topic: List Printer  (Read 2862 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
List Printer
« on: June 14, 2010, 10:46:54 AM »
I needed something similar to MP's Elist function, but for general lists, so I came up with this:

Code: [Select]
(defun prt ( lst / subprt )
  ;; © Lee Mac 2010
  (vl-load-com)

  (defun subprt ( lst ind / pritem )

    (defun pritem ( item ind )
      (repeat ind (princ "   "))
      (if (member item '("(" ")"))
        (princ item)
        (prin1 item)
      )
      (terpri)
    )

    (if lst
      (if (vl-some 'vl-consp lst)
        (progn
          (pritem "(" ind)
          (foreach x lst
            (if (vl-consp x)
              (if (vl-list-length x)
                (subprt x (1+ ind))
                (pritem x (1+ ind))
              )
              (pritem x (1+ ind))
            )
          )
          (pritem ")" ind)
        )
        (pritem lst ind)
      )     
    )
  )

  (cond (  (not lst) (princ "nil"))

        (  (eq 'ENAME (type lst))

           (subprt (entget lst) 0)
        )
        (  (subprt lst 0))
  )
  (princ)
)

I hope it will help someone, and of course suggestions for improvement are welcome.  :-)
« Last Edit: July 31, 2010, 11:01:53 AM by Lee Mac »

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: List Printer
« Reply #1 on: June 14, 2010, 10:58:21 AM »
Whats the Elist function?

(Looking at code now)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: List Printer
« Reply #2 on: June 14, 2010, 11:02:51 AM »
hey?! My list was reformatted?! ...what did you do that for? I'm guessing that youre just reporting something back to the user right 'cause i dont really see a need for reformatting a list other then for aesthetics. Right?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: List Printer
« Reply #3 on: June 14, 2010, 11:06:18 AM »
Yeah, its just for reformatting for clarity - I would use it if I am debugging code with a big list structure... else the list is printed in one long line...  :|

Example:

Code: [Select]
(1 2 (3 5) (1 . 2) 1 2 (1 (2 (3 4) 2)) 1)

becomes:

Code: [Select]
(
   1
   2
   (3 5)
   (1 . 2)
   1
   2
   (
      1
      (
         2
         (3 4)
         2
      )
   )
   1
)
« Last Edit: June 14, 2010, 11:10:55 AM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: List Printer
« Reply #4 on: June 14, 2010, 11:08:33 AM »
Whats the Elist function?

(Looking at code now)

I'm sure its on here somewhere elist.lsp - prints the list in almost the same format as mine, but is used for 'entget' returns...

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: List Printer
« Reply #5 on: June 14, 2010, 11:10:13 AM »
Ah, well, good job. Carry on.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: List Printer
« Reply #6 on: June 14, 2010, 11:27:54 AM »
 :-)

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: List Printer
« Reply #7 on: June 15, 2010, 02:37:41 AM »
Code: [Select]
(defun pprint (lst ind)
  (strcat ind
 "(\n"
 (apply 'strcat
(mapcar (function (lambda (e)
    (if (and e (listp e) (vl-list-length e) (vl-some 'listp e))
      (pprint e (strcat ind " "))
      (strcat ind " " (vl-prin1-to-string e) "\n")
    )
  )
)
lst
)
 )
 ind
 ")\n"
  )
)
(princ (pprint '(1 2 (3 5) (1 . 2) 1 2 (1 (2 (3 4) 2)) 1) ""))
i use something of this kind to write formatted xml files