Author Topic: list manipulation  (Read 1949 times)

0 Members and 1 Guest are viewing this topic.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
list manipulation
« on: September 12, 2014, 03:37:03 AM »
Hello!
Iīm not sure to do, how I can a practicle result of a list looking like this
Code: [Select]
(("0" "LWPOLYLINE" 64.6213) ("0" "LINE" 22.4991) ("0" "ARC" 32.7335) ("M-BEF-BELYSNINGSSTOLPE" "CIRCLE" 166.101) ("FEATURELINE-2D" "CIRCLE" 59.7528) ("FEATURELINE-3D" "LINE" 18.5926) ("M-BEF-EL" "LWPOLYLINE" 92.1751))
first item is "Layername"
sec item  "type of DrawingObject"
third item length of item

Now I want I get a list which give me totalvalues in a list
Layer "0"
Type "LWPOLYLINE" 64.2
Type "LINE" 22.5
Type "ARC" 32.7
Total 119.4
Layer "M-BEF-BELYSNINGSSTOLPE"
Type "CIRCLE" 166.1
Total 166.1
...

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: list manipulation
« Reply #1 on: September 12, 2014, 06:31:28 AM »
I do it myself
Code: [Select]
(defun _getsort (lst / f nlst lst)
    (while lst
      (setq f (caar lst))
      (setq nlst
     (foreach pair lst
       (if (member f pair)
(progn
   (setq nlst (append nlst (list (cdr pair))))
   (vl-remove (cdr pair) lst)
   )
)
       nlst
       )
    )
      (setq lst (vl-remove-if (function (lambda (x) (= (car x) f))) lst))
      (setq clst (append clst (list (cons f nlst))))
      (setq nlst nil)
      )
    clst
    )


result
Code: [Select]
(("0" ("LWPOLYLINE" 64.6213) ("LINE" 22.4991) ("ARC" 32.7335)) ("M-BEF-BELYSNINGSSTOLPE" ("CIRCLE" 166.101)) ("FEATURELINE-2D" ("CIRCLE" 59.7528)) ("FEATURELINE-3D" ("LINE" 18.5926)) ("M-BEF-EL" ("LWPOLYLINE" 92.1751)))
« Last Edit: September 12, 2014, 06:40:10 AM by cadplayer »

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: list manipulation
« Reply #2 on: September 12, 2014, 06:32:21 AM »
Hi ,

Try this routine and be aware that the number for circles representing the sum of Circumferences of them .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ ss lst)
  2.   ;;    Tharwat Al Shoufi       ;;
  3.   (if (setq ss (ssget '((0 . "LINE,LWPOLYLINE,ARC,CIRCLE"))))
  4.     ((lambda (i / sn e l o d f)
  5.        (while (setq sn (ssname ss (setq i (1+ i))))
  6.          (setq e (entget sn)
  7.                o (cdr (assoc 0 e))
  8.                l (cdr (assoc 8 e))
  9.          )
  10.          (if (eq o "CIRCLE")
  11.            (setq d (vla-get-Circumference (vlax-ename->vla-object sn)))
  12.            (setq d (vlax-curve-getdistatpoint
  13.                      sn
  14.                      (vlax-curve-getendpoint sn)
  15.                    )
  16.            )
  17.          )
  18.          (if (vl-some '(lambda (x)
  19.                          (if (and (eq (car x) l) (eq (cadr x) o))
  20.                            (setq f x)
  21.                          )
  22.                        )
  23.                       lst
  24.              )
  25.            (setq lst (subst (list l o (+ (caddr f) d)) f lst))
  26.            (setq lst (cons (list l o d) lst))
  27.          )
  28.        )
  29.      )
  30.       -1
  31.     )
  32.   )
  33.   (if lst (print lst))
  34.   (princ)
  35. )
  36.  

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: list manipulation
« Reply #3 on: September 12, 2014, 06:45:43 AM »
very fine... I have to learn what you have done!
Perfect! thank you so much for your help

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: list manipulation
« Reply #4 on: September 12, 2014, 06:47:38 AM »
very fine... I have to learn what you have done!
Perfect! thank you so much for your help

You are welcome . I am happy to be able to help .  :-)

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: list manipulation
« Reply #5 on: September 12, 2014, 06:56:10 AM »
Yeah and here you get length from Splines and Ellipse too (especially for Architects  :wink:)
Code: [Select]
(defun _getlength (ename / ep)
    (if (vl-catch-all-error-p (setq ep (vl-catch-all-apply 'vlax-curve-getendparam (list ename))))
      0.0
      (vlax-curve-getdistatparam ename ep)
      )
    )

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: list manipulation
« Reply #6 on: September 12, 2014, 07:06:42 AM »
Quote
(if (vl-some '(lambda (x)
                         (if (and (eq (car x) l) (eq (cadr x) o))
                           (setq f x)
                         )
                       )
                      lst
             )
           (setq lst (subst (list l o (+ (caddr f) d)) f lst))
           (setq lst (cons (list l o d) lst))
         )

these part looks like very complicate for me, Can you explain me please what exactly should do vl-some. F1 couldnīt realy help me?!

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: list manipulation
« Reply #7 on: September 12, 2014, 07:20:03 AM »
Quote
(if (vl-some '(lambda (x)
                         (if (and (eq (car x) l) (eq (cadr x) o))
                           (setq f x)
                         )
                       )
                      lst
             )
           (setq lst (subst (list l o (+ (caddr f) d)) f lst))
           (setq lst (cons (list l o d) lst))
         )

these part looks like very complicate for me, Can you explain me please what exactly should do vl-some. F1 couldnīt realy help me?!

The vl-some function should stop searching for value if the value found by the function lambda as shown in my routine , and here is the description of the function from help document .

http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-6882.htm

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: list manipulation
« Reply #8 on: September 13, 2014, 09:41:03 AM »
Here's another approach:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:llen ( / a b d e i l s x )
  2.     (if
  3.         (setq s
  4.             (ssget
  5.                '(   (0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
  6.                     (-4 . "<NOT")
  7.                         (-4 . "<AND")
  8.                             (0 . "POLYLINE") (-4 . "&") (70 . 80)
  9.                         (-4 . "AND>")
  10.                     (-4 . "NOT>")
  11.                 )
  12.             )
  13.         )
  14.         (repeat (setq i (sslength s))
  15.             (setq e (ssname s (setq i (1- i)))
  16.                   x (entget e)
  17.                   a (list (cdr (assoc 8 x)) (cdr (assoc 0 x)))
  18.                   d (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
  19.             )
  20.             (if (setq b (assoc a l))
  21.                 (setq l (subst (list a (+ d (cadr b))) b l))
  22.                 (setq l (cons  (list a d) l))
  23.             )
  24.         )
  25.     )
  26.     (mapcar '(lambda ( x ) (append (car x) (cdr x))) l)
  27. )