Counting certain entities in list?

Discussion in 'AutoCAD' started by Fatfreek, Aug 19, 2003.

  1. Fatfreek

    Fatfreek Guest

    The following is a list of entity pairs which I need to parse in certain
    ways.
    I want to be able to count how many times 7ef71e18 occurs in column 1 (6).
    Or
    how many time 7ef71eb8 occurs in the second column (2).

    Any suggestions?

    Len Miller

    (
    (<Entity name: 7ef71e00> <Entity name: 7ef71df8>)
    (<Entity name: 7ef71e18> <Entity name: 7ef71eb8>)
    (<Entity name: 7ef71e18> <Entity name: 7ef71ec0>)
    (<Entity name: 7ef71e18> <Entity name: 7ef71ec8>)
    (<Entity name: 7ef71e18> <Entity name: 7ef71f60>)
    (<Entity name: 7ef71e18> <Entity name: 7ef71f68>)
    (<Entity name: 7ef71e18> <Entity name: 7ef71fa0>)
    (<Entity name: 7ef71ec8> <Entity name: 7ef71eb8>)
    (<Entity name: 7ef71ec8> <Entity name: 7ef71ec0>)
    (<Entity name: 7ef71f68> <Entity name: 7ef71f60>)
    )
     
    Fatfreek, Aug 19, 2003
    #1
  2. Fatfreek

    Mark Propst Guest

    one way:
    (defun test ( / l1)
    (setq l1
    (list
    (list "<Entity name: 7ef71e00>" "<Entity name: 7ef71df8>")
    (list "<Entity name: 7ef71e18>" "<Entity name: 7ef71eb8>")
    (list "<Entity name: 7ef71e18>" "<Entity name: 7ef71ec0>")
    (list "<Entity name: 7ef71e18>" "<Entity name: 7ef71ec8>")
    (list "<Entity name: 7ef71e18>" "<Entity name: 7ef71f60>")
    (list "<Entity name: 7ef71e18>" "<Entity name: 7ef71f68>")
    (list "<Entity name: 7ef71e18>" "<Entity name: 7ef71fa0>")
    (list "<Entity name: 7ef71ec8>" "<Entity name: 7ef71eb8>")
    (list "<Entity name: 7ef71ec8>" "<Entity name: 7ef71ec0>")
    (list "<Entity name: 7ef71f68>" "<Entity name: 7ef71f60>")
    )
    )
    (countlist l1)
    )
    (defun countlist (l / lst thislist cl cl2)
    ; (setq lst nil thislist nil cl nil cl2 nil)
    (foreach lst l
    (if (setq thislist(assoc (car lst) cl))
    (setq cl
    (subst
    (list (car lst)(+ 1 (cadr thislist)))
    thislist
    cl)
    );setq
    (setq cl (cons (list (car lst) 1) cl))
    )
    );for

    (foreach lst l
    (if (setq thislist(assoc (cadr lst) cl2))
    (setq cl2
    (subst
    (list (cadr lst)(+ 1 (cadr thislist)))
    thislist
    cl2)
    );setq
    (setq cl2 (cons (list (cadr lst) 1) cl2))
    )
    );for

    (list cl cl2)
    );d
     
    Mark Propst, Aug 19, 2003
    #2
  3. Fatfreek

    Fatfreek Guest

    Hmmm ... let's see if I understand this. I loaded both defuns in my
    Vlide -- then ran (test).
    That yielded the following:
    ((
    ("<Entity name: 7ef71f68>" 1)
    ("<Entity name: 7ef71ec8>" 2)
    ("<Entity name: 7ef71e18>" 6)
    ("<Entity name: 7ef71e00>" 1)
    )
    (("<Entity name: 7ef71fa0>" 1)
    ("<Entity name: 7ef71f68>" 1)
    ("<Entity name: 7ef71f60>" 2)
    ("<Entity name: 7ef71ec8>" 1)
    ("<Entity name: 7ef71ec0>" 2)
    ("<Entity name: 7ef71eb8>" 2)
    ("<Entity name: 7ef71df8>" 1)
    ))

    It appears that counts for both columns is in the first list, and counts for
    column 2 is in second. If that is correct I think I can live with that.

    Thanks, Mark.
     
    Fatfreek, Aug 19, 2003
    #3
  4. Fatfreek

    Fatfreek Guest

    Oops!! Duuuhhh! First list has counts for that list. Perfect!

    Len
     
    Fatfreek, Aug 19, 2003
    #4
  5. Fatfreek

    Mark Propst Guest

    cool
     
    Mark Propst, Aug 20, 2003
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.