Jump to content

Modifying Plant Schedule Lisp. Please help.


mexmr10

Recommended Posts

Not sure if this would work?

 

;; Summing Attributes Before Extraction

(defun c:AttSum (/ *error* Get_Unique ATTLST CAT CATS CAT_TAG ENT FILE I N
                NEWATTLST NEWORDER NUM NUM_TAG OBJ OFILE ORD OTHER SS SYM SYM_TAG)
 (vl-load-com)
 ;; Lee Mac  ~  01.02.10

 ;; ----------<< Attribute Tag Names >>----------

 (setq Cat_Tag "CATEGORY"
       Sym_Tag "SYMBOL"
       Num_Tag "QUANTITY")

 ;; ----------<< Attribute Tag Order >>----------

 (setq Ord '("Deciduous Shade Trees"
             "Ornamental Trees"
             "Evergreen Trees"
             "Deciduous Shrubs"
             "Evergreen Shrubs"
             "Perennials and Ornamental Grasses"
             "Groundcovers"
             "Vines"
             "Annuals and Bulbs"
             "Seed Mixes"
 ))

 ;; ---------------------------------------------

 (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)

 (defun lst2str (lst del)
   (if (cdr lst)
     (strcat (car lst) del (lst2str (cdr lst) del))
     (car lst)))

 (mapcar (function set) '(Cat_Tag Sym_Tag Num_Tag)
         (mapcar (function strcase) (list Cat_Tag Sym_Tag Num_Tag)))

 (setq Ord (mapcar (function strcase) Ord))
 
 (if (and (setq i -1 ss (ssget '((0 . "INSERT") (2 . "KEY-PLANT") (66 . 1))))
          (setq file    (getfiled "Output File" "" "csv" 9))
          (setq ofile   (open file "a")))
   (progn
           
     (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 (distof (vla-get-TextString att))))

               (t (setq Other (cons (vla-get-TextString att) Other)))))

       (if (and Cat Sym Num)
         (setq AttLst (cons (cons Cat (list (cons Sym (list (cons Num Other))))) AttLst)))

       (setq Other nil Cat nil Sym nil Num nil))

     (setq AttLst (mapcar
                    (function
                      (lambda (x)
                        (cons (car x)
                              (vl-sort (Get_Unique (cdr x))
                                       (function
                                         (lambda (a b)
                                           (< (car a) (car b)))))))) (Get_Unique AttLst)))
     
     (setq Cats (mapcar
                  (function
                    (lambda (x) (strcase (car x)))) AttLst))

     (setq Ord   (vl-remove-if-not (function (lambda (x) (vl-position x Cats))) Ord))

     (setq newOrder (vl-remove 'nil
                      (mapcar
                        (function
                          (lambda (x) (vl-position x Cats))) Ord)))

     (setq NewAttLst (mapcar (function (lambda (x) (nth x AttLst))) newOrder))

     (setq AttLst    (append NewAttLst (vl-remove-if
                                         (function
                                           (lambda (x) (vl-position x NewAttLst))) AttLst)))

     (foreach x Attlst
       (write-line (car x) ofile)

       (foreach y (cdr x)
         (write-line
           (strcat (car y) (chr 44) (lst2str (cdr y) (chr 44))) ofile))

       (write-line "" ofile))

     (setq ofile (close ofile)))

   (princ "\n<!> No Blocks Found <!>"))
 
 (princ))

Link to comment
Share on other sites

  • Replies 38
  • Created
  • Last Reply

Top Posters In This Topic

  • mexmr10

    12

  • Lee Mac

    11

  • One_Punchman

    9

  • Roy_043

    5

Top Posters In This Topic

Posted Images

this is what i get:

 

Error: bad argument type: stringp (1.0)

 

 

EDIT: With these extra attributes, say you have two blocks with the same 'Symbol' attribute.

 

Currently, these will be grouped and the quantities summed.

 

What will happen at this point to the extra attributes?

Link to comment
Share on other sites

  • 7 years later...

Reviving this thread. So how do I make the program work? Copy and paste to a notepad then rename the file extension? How to execute to command after appload?

Link to comment
Share on other sites

Copy and paste to notepad saveas say Attsum.lsp no need for rename.

 

Appload Attsum

 

Just type Attsum on command line

 

The C:attsum means the function following the C: can be typed on the command line to run.

Link to comment
Share on other sites

Copy and paste to notepad saveas say Attsum.lsp no need for rename.

 

Appload Attsum

 

Just type Attsum on command line

 

The C:attsum means the function following the C: can be typed on the command line to run.

 

Thanks Mr. Bigal. Will try that.

Link to comment
Share on other sites

So here is what happened. I opened a CAD file, created 3 attributes namely: plant-type, quantity and category. Next I created a block out of those attributes collectively, named 'key-plant'. To experiment, I inserted 2 of those blocks with their own details, as shown below:

 

Sample CAD.jpg

 

Then as instructed by Bigal, I loaded the attsum, windowed the aforementioned 2 blocks (2 blocks selected; acknowledged by AutoCAD), then an excel file was created. I opened that excel file and found this:

 

Excel result.jpg

 

As you can see, there is a filename location above, then 2 parameters namely the PLANT-TYPE and CATEGORY only. There were no further details that followed. Could have I made a mistake in the procedure?

Link to comment
Share on other sites

Thanks for the suggestion, Roy_043. I tried using capital letters in the tags before creating the 'key-plant' block, as shown below:

 

Before blocking.jpg

 

But I still got the same excel result. :(

Link to comment
Share on other sites

I repeat:

Have you updated the 'Attribute Tag Names' section to match your tags (note: use CAPS)?

IOW: you have to change that portion of the code.

 

And if that does not help: post your dwg.

Link to comment
Share on other sites

@Roy_043, sorry I'm a total newbie at this, so I don't know how to execute that last instruction. What I can do is show you the steps I did. First off I created 3 attributes that indicate 'PLANTTYPE', 'QUANTITY' AND 'CATEGORY':

 

1 Before blocking.jpg

 

Second, I created the 'key-plant' block:

 

2 Blocking.jpg

 

3rd, I inserted a 'key-plant' block called 'GJA':

 

3 Inserting a block.jpg

 

and another one called 'ITE'

 

4 Inserting another block.jpg

 

Next, I executed the ATTSUM command with the 2 blocks selected:

 

5 Executing ATTSUM command.jpg

 

Then an excel file was created:

 

6 CSV created.jpg

 

I got the same excel file as before. Just the 'PLANT-TYPE' and 'QUANTITY'. No indication of the GJA and/or ITE and their details.

7 Excel result 2.jpg

 

I was hoping to have something like this:

 

Target output.jpg

 

There could be a lot of mistakes that I did and in fact, I don't know how to do the instruction you provided. Please bear with this newbie soul.

Link to comment
Share on other sites

The code looks at three tags: "CATEGORY", "SYMBOL" and "QUANTITY". Only blocks that have attributes with all these tags will be processed. So you must change "SYMBOL" to "PLANTTYPE" in the Lisp code.

Link to comment
Share on other sites

  • 1 month later...

Still no cigar. I renamed the attsum to a text file, changed the 'SYMBOL' to 'PLANTYPE' then convert back to lsp file:

 

Changed to planttype.jpg

 

Made the blocks as per previous steps:

 

As shown in CAD.jpg

 

Loaded the attsum, then generated the excel file:

 

Excel result.jpg

 

As you can see, this is still far from the desired output. The planttype codes (GJA and ITE) and quantities (150 and 500) still do not appear in the excel file. :(

Link to comment
Share on other sites

FYI - lisp routines that are not compiled do not have to be renamed as a text file in order to edit them. They are typically ASCII text files to begin with which means they can be opened with any ASCII text editor such as Notepad.

Link to comment
Share on other sites

The code from post #21 is faulty. Use the code from post #14, change the 'Attribute Tag Names' as before and things should work fine.

Link to comment
Share on other sites

  • 4 weeks later...

Worked! Also found out that the resulting excel file could not be overwritten correctly. A new list shows up on top of the previous one (in the same excel file), so it is best to do the attsum command when the drawing is absolutely finished. Or simply erase the old excel file to get a fresh new updated one. Thanks Roy_043 and LeeMax! See you in the other threads!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...