+ Reply to Thread
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 10 of 39
  1. #1
    Junior Member
    Using
    not applicable
    Join Date
    Dec 2009
    Posts
    13

    Arrow Modifying Schedule Lisp. Please help.

    Registered forum members do not see this ad.

    Can anyone modify the following lisp for me? I found it on cadalyst and its almost what I need, but I would like a little more functionality.

    Here's how it works:

    1) I have a block, that I use as a label, named key-plant and it has 2 attributes: planttype and quantity. "Planttype" is the symbol/code that represents a certain plant species and "quantity" is the quantity that I assign to a group of certain plant blocks.

    2.) I use this "key-plant" block with a leader and label all of my plant blocks.

    3.) I run it typing "pll" and it gives me a plant list in a notepad document...example shown below:

    PLANT-TYPE QUANTITY
    AM ............. 19
    CS .............170
    PA ...............4
    PCA ..............2
    VL ...............78
    cas ..............490

    Here are my questions/requests:

    1.) The lisp currently just throws together a comprehensive list of all blocks in the drawing. I want to add one more attribute like - "Category" - to the "key-plant" block so that I can organize the plant list by the following plant categories:

    -Deciduous Shade Trees
    -Ornamental Trees
    -Evergreen Trees
    -Deciduous Shrubs
    -Evergreen Shrubs
    -Perennials and Ornamental Grasses

    2.) I'd like the list to output in that order (shown above) and then alphabetize for each category.

    3.) I'd like to output to an excel file instead of a notepad file.

    Can anyone help me with this? I know this is very specific, but It would really make my work a lot more efficient. There are so many gurus here and I'm a total noob to Lisp code.

    This is what the "ideal" output would look like:

    PLANT-TYPE QUANTITY

    Deciduous Shade Trees
    AM .................19
    CS .................170

    Ornamental Trees
    APB .................4
    BN ...................78

    Evergreen Trees
    PA................... 490
    PGD ................. 25


    etc...etc...
    Attached Files
    Last edited by mexmr10; 2nd Feb 2010 at 04:20 pm.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,590

    Default

    I wrote this a while back, untested, but give it a go:

    Code:
    ;; Summing Attributes Before Extraction
    ;; By Lee McDonnell
    
    (defun c:AttSum (/ ss ofile file attlst x y lst)
      (vl-load-com)
      
      (if (and (setq ss   (ssget "_X" '((0 . "INSERT") (2 . "KEY-PLANT") (66 . 1))))
               (setq file (getfiled "Output File" "" "csv" 9)))
        (progn
          
          (setq ofile (open file "a"))
          (write-line (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")) ofile)
          (write-line "ITEM,QUANTITY" ofile)
          
          (setq attlst
            (mapcar
              (function
                (lambda (x)
                  (mapcar
                    (function vla-get-TextString) x)))
              
              (mapcar
                (function
                  (lambda (x)
                    (vl-sort x
                      (function
                        (lambda (x1 x2)
                          (< (vla-get-TagString x1)
                             (vla-get-TagString x2)))))))
                (mapcar
                  (function
                    (lambda (x)
                      (vlax-safearray->list
                        (vlax-variant-value
                          (vla-getAttributes x)))))
                  
                  (mapcar
                    (function vlax-ename->vla-object)
                      (mapcar (function cadr) (ssnamex ss)))))))
          
          (while (setq x (car attlst))
            (if (setq y (assoc (car x) lst))
              (setq lst (subst (append y (cdr x)) y lst))
              (setq lst (cons x lst)))
            (setq attlst (cdr attlst)))
          
          (foreach x lst
            (write-line
              (strcat (car x) (chr 44)
                (rtos
                  (apply (function +)
                    (mapcar (function distof) (cdr x))))) ofile))
          
          (write-line "-----,-----" ofile)      
          (close ofile))
        
        (princ "\n<!> No Blocks Found <!>"))
      
      (princ))
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Junior Member
    Using
    not applicable
    Join Date
    Dec 2009
    Posts
    13

    Default

    Works great but..... can you make it organize/alphabetize the excel output based on a third attribute named "category" ?

    Thanks for your help Lee.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,590

    Default

    Perhaps.

    Would you be able to upload an example of the block you are using?
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Junior Member
    Using
    not applicable
    Join Date
    Dec 2009
    Posts
    13

    Default

    Sure...give me 2 minutes.

  6. #6
    Junior Member
    Using
    not applicable
    Join Date
    Dec 2009
    Posts
    13

    Default

    oops...completely forgot the last 4 categories (groundcovers, vines, annuals, seed mixes)

    So the final excel output should have the following categories in the following order and alphabetized per category.

    -Deciduous Shade Trees
    -Ornamental Trees
    -Evergreen Trees
    -Deciduous Shrubs
    -Evergreen Shrubs
    -Perennials and Ornamental Grasses
    -Groundcovers
    -Vines
    -Annuals and Bulbs
    -Seed Mixes

    One last request....Would it be possible to get a selection set prompt so I can selectively choose which blocks I'd like to get this info from? Could I use a polyline boundary for this selection set.?

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,590

    Default

    Didn't see your last request, but try this for the first part:

    Code:
    ;; Summing Attributes Before Extraction
    
    (defun c:AttSum (/ *error* Get_Unique ATTLST CAT CAT_TAG ENT FILE I
                                 N NUM NUM_TAG OBJ OFILE SS SYM SYM_TAG)
      (vl-load-com)
      ;; Lee Mac  ~  01.02.10
    
      (setq Cat_Tag "CATEGORY"
            Sym_Tag "SYMBOL"
            Num_Tag "QUANTITY")
    
      (defun *error* (msg)
        (and ofile (close ofile))
        (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
            (princ (strcat "\n** Error: " msg " **")))
        (princ))
    
      (defun Get_Unique (lst / Remove_n x ass result)
    
        (defun Remove_n (n lst)
          (setq i -1)
          (vl-remove-if
            (function
              (lambda (x) (= (setq i (1+ i)) n))) lst))
        
        (while (setq x (car lst)) (setq lst (cdr lst))
    
          (while (setq ass (assoc (car x) lst))
    
            (setq x (cons (car x) (append (cdr x) (cdr ass))))
    
            (setq lst (Remove_n (vl-position ass lst) lst)))
    
          (setq result (cons x result)))
    
        result)
    
      (mapcar (function set) '(Cat_Tag Sym_Tag Num_Tag)
              (mapcar (function strcase) (list Cat_Tag Sym_Tag Num_Tag)))
      
      (if (and (setq i -1 ss (ssget '((0 . "INSERT") (2 . "KEY-PLANT") (66 . 1))))
               (setq file    (getfiled "Output File" "" "csv" 9)))
        (progn
          
          (setq ofile (open file "a"))
          (write-line (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")) ofile)
          (write-line "PLANT-TYPE,QUANTITY" ofile)
    
          (while (setq ent (ssname ss (setq i (1+ i))))
            (setq obj (vlax-ename->vla-object ent))
    
            (foreach att (vlax-invoke obj 'GetAttributes)       
    
              (cond (  (eq Cat_Tag (strcase (vla-get-TagString att)))
                       (setq Cat (vla-get-TextString att)))
    
                    (  (eq Sym_Tag (strcase (vla-get-TagString att)))
                       (setq Sym (vla-get-TextString att)))
    
                    (  (eq Num_Tag (strcase (vla-get-TagString att)))
                       (setq Num (vla-get-TextString att)))))
    
            (if (and Cat Sym Num)
              (setq AttLst (cons (cons Cat (list (cons Sym (list Num)))) AttLst))))
    
          (setq AttLst (vl-sort (mapcar
                                  (function
                                    (lambda (x)
                                      (cons (car x)
                                            (vl-sort (Get_Unique (cdr x))
                                              (function
                                                (lambda (a b)
                                                  (< (car a) (car b)))))))) (Get_Unique AttLst))
                                (function
                                  (lambda (a b)
                                    (< (car a) (car b))))))     
          
          (foreach x Attlst
            (write-line (car x) ofile)
    
            (foreach y (cdr x)
              (write-line
                (strcat (car y) (chr 44)
                  (rtos
                    (apply (function +)
                      (mapcar (function distof) (cdr y))))) ofile))
    
            (write-line "" ofile))
    
          (setq ofile (close ofile)))
    
        (princ "\n<!> No Blocks Found <!>"))
      
      (princ))
    EDIT: Updated as per last request
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Junior Member
    Using
    not applicable
    Join Date
    Dec 2009
    Posts
    13

    Default

    This is almost dead on...You sir are a genius!

    The category names showed up alphabetized, but I need them in this specific order:

    -Deciduous Shade Trees
    -Ornamental Trees
    -Evergreen Trees
    -Deciduous Shrubs
    -Evergreen Shrubs
    -Perennials and Ornamental Grasses
    -Groundcovers
    -Vines
    -Annuals and Bulbs
    -Seed Mixes

    What I need alphabetized is the content in each category.

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,590

    Default

    Quote Originally Posted by mexmr10 View Post
    This is almost dead on...You sir are a genius!

    The category names showed up alphabetized, but I need them in this specific order:

    -Deciduous Shade Trees
    -Ornamental Trees
    -Evergreen Trees
    -Deciduous Shrubs
    -Evergreen Shrubs
    -Perennials and Ornamental Grasses
    -Groundcovers
    -Vines
    -Annuals and Bulbs
    -Seed Mixes

    What I need alphabetized is the content in each category.
    You don't ask for much...
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Junior Member
    Using
    not applicable
    Join Date
    Dec 2009
    Posts
    13

    Default

    Registered forum members do not see this ad.

    Im sorry...and I really appreciate your help.

    Ok would it work if I inserted a number in front of each category name so that it would read the number first instead of the first letter?

Similar Threads

  1. Help modifying lisp for sqft
    By vladthedog in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 28th Oct 2009, 12:42 am
  2. Modifying Dimension Style using lisp
    By briankstan in forum AutoLISP, Visual LISP & DCL
    Replies: 19
    Last Post: 6th Aug 2009, 06:11 pm
  3. Modifying layers with lisp
    By Henryjohn in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 2nd Jan 2009, 12:16 pm
  4. Help Modifying LISP (Break Routine)
    By herkenbrack@gmail.com in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 25th Aug 2008, 03:32 pm
  5. Help Modifying LISP that copies attribues
    By icevapor in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 18th Jun 2008, 02:48 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts