Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

Thread: lisp table help

  1. #11
    Member
    Join Date
    2009-10
    Posts
    10
    Login to Give a bone
    0

    Default Re: lisp table help

    Thank you Oleg.

    By the way, with regard to my additional query "Is it possible to do a direct export of a table to Excel with columns and rows being the same?"

    I am using AutoCAD 2009 and I found an in built "tableexport" command that exports a table to a .csv file.
    I didn't know it existed.
    With AutoCAD I learn something new every day.

    Have a good holiday.

    Best Regards.

  2. #12
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: lisp table help

    Quote Originally Posted by mark.232312 View Post
    Thank you Oleg.

    By the way, with regard to my additional query "Is it possible to do a direct export of a table to Excel with columns and rows being the same?"

    I am using AutoCAD 2009 and I found an in built "tableexport" command that exports a table to a .csv file.
    I didn't know it existed.
    With AutoCAD I learn something new every day.

    Have a good holiday.

    Best Regards.
    Haha
    Please do not hurry I'm working too slowly
    The attached code is for the first case
    The second part of the program will follow later
    Think it's enough on today

    ~'J'~
    Attached Files Attached Files

  3. #13
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: lisp table help

    Here is a lisp for the second case

    By the way, with regard to my additional query "Is it possible to do a direct export of a table to Excel with columns and rows being the same?"
    I have one, but I will send you this later, maybe near to the night
    or tomorrow...

    ~'J'~
    Attached Files Attached Files

  4. #14
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,104
    Login to Give a bone
    0

    Default Re: lisp table help

    This code shows various example of manipulating tables using lisp from an AU class I taught a few years ago. Maybe you could find it useful

    Peter
    Attached Files Attached Files
    AutomateCAD

  5. #15
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: lisp table help

    Quote Originally Posted by mark.232312 View Post
    Thank you Oleg.

    By the way, with regard to my additional query "Is it possible to do a direct export of a table to Excel with columns and rows being the same?"
    Try this lisp for export the plain table

    ~'J'~
    Attached Files Attached Files

  6. #16
    Member
    Join Date
    2009-10
    Posts
    10
    Login to Give a bone
    0

    Smile Re: lisp table help

    Oleg,

    What can I say! I am lost for words all three PARTREF, PARTREF2 and TableXport all work extremely well and without fault.
    I am now like a kid with a new toy.

    Sincere thanks for your valuable time and effort to help a stranger like me.
    You are indeed a very smart and very helpful guy.

    FIXO FIXED IT FOR ME.


    Peter,

    Thank you for sharing your Tablemagic.lsp.
    It is really impressive. I am already dreaming up ideas as to how I can use this.
    Many Thanks indeed.

  7. #17
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: lisp table help

    Mark,
    Glad I could help
    Happy computing
    Chreers

    ~'J'~

  8. #18
    Member
    Join Date
    2009-10
    Posts
    10
    Login to Give a bone
    0

    Smile Re: lisp table help

    Hi Oleg,

    If you don't mind, I have a further question.

    Please see attached drawing TagSample1.dwg

    I have been constantly using your excellent "partref2.lsp", and I am very happy with it.
    I was wondering if the code could be manipulated by grouping parts as one that have the same part name and length.
    Bit difficult to explain, but if you look at the drawing I think my question will become clear.

    But Oleg, if this involves a lot of time consuming re-coding, please do not spend time on this. I am very happy with the code as it is.
    Of course if it is a simple update, then the code would be much better.
    Not being a guy who fully understands lisp, I do not have the ability to judge whether I am asking too much or not.

    As I said, I am constantly using your partref2 code, and I am soooooooooooo happy with it.

    My best Regards.

    Mark.TagSample1.dwg

  9. #19
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: lisp table help

    Hi Mark
    I was in hospital so let me a time to relax a little, then
    I will be back later

    Oleg

  10. #20
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: lisp table help

    Try it again

    Code:
    (defun C:PARTREF3(/ acapp acol acsp adoc atable attdata attitem atts blkdata blkname blkobj col
    		column colwidth  datalist en headers pt row sset swap  tabledata tags total txtheight widths x)
      
      ;private function
     
      (defun sum-and-groupby-three (lst / groups res sum tmp)
      (while lst
        (setq tmp	    (car lst)
    	  sum
    		    (apply '+
    			   (mapcar 'atoi (mapcar 'cdadr 
    				   (setq res (vl-remove-if-not
    
    					       '(lambda (a) (and
    							      (eq (cdr (nth 0 a)) (cdr (nth 0 tmp)))
    							      (eq (cdr (nth 1 a)) (cdr (nth 1 tmp)))
    							      (eq (cdr (nth 2 a)) (cdr (nth 2 tmp)))))
    
    					       lst
    
    					     )
    				   )
    			   ))
    		    )
    	  groups    (cons (subst (cons "QTY" (itoa sum))(cadr tmp) tmp) groups)
    	  lst
    		    (vl-remove-if
    		      '(lambda (a) (member a res))
    
    		      lst
    
    		    )
        )
      )
     
     (reverse groups)
    )
    
    ;private function  
    (defun sum-and-groupby (lst / count countdata elem match tmp)
      
    (while lst
      
    (setq tmp (car lst))
    
    (setq match (vl-remove-if-not '(lambda(x)(and (eq (cdr (nth 0 x))(cdr (nth 0 tmp) ))
    					  (eq (cdr (nth 2 x))(cdr (nth 2 tmp) ))
    					  (eq (cdr (nth 3 x))(cdr (nth 3 tmp) ))))
    					  lst))
    
    (setq count (apply '+ (mapcar 'atoi (mapcar 'cdr (mapcar 'cadr match)))))
    (setq elem (list (cdr (nth 0 tmp))
    		 (itoa count)
    		(cdr (nth 2 tmp))
    		(cdr (nth 3 tmp))
    		 (cdr (nth 4 tmp))))
    (setq countdata (cons elem countdata))
    
    (setq lst (vl-remove-if '(lambda(x)(and (eq (cdr (nth 0 x))(cdr (nth 0 tmp) ))
    					  (eq (cdr (nth 2 x))(cdr (nth 2 tmp) ))
    					  (eq (cdr (nth 3 x))(cdr (nth 3 tmp) ))))
    					  lst))
      )
    (vl-sort countdata '(lambda(a b)(< (car a)(car b))))
      
      )
    
      
    ;			main part			;
    
      
      (if (setq sset (ssget (list (cons 0 "INSERT") (cons 66 1))))
        (progn
          (setq tabledata nil
    	    attdata nil
    	    attitem nil
          )
          
          (while (setq en (ssname sset 0))
    	(setq blkobj  (vlax-ename->vla-object en)
    	      blkname (vla-get-effectivename blkobj)
    	)
    	(setq atts (vlax-invoke blkobj 'getattributes))
    	(foreach attobj	atts
    
    	      (setq attitem (cons (vla-get-tagstring attobj) (vla-get-textstring attobj)))
    	      (setq attdata (cons attitem attdata))
    
    	)
    
    	(setq tabledata (cons (reverse attdata) tabledata))
    	(setq attdata nil
    	      attitem nil
    	)
    	(ssdel en sset)
          )
    (setq headers (mapcar 'car (car tabledata))
    	    tags    headers 
          )
    (setq tabledata (sum-and-groupby-three tabledata))
    
    (setq tabledata (sum-and-groupby tabledata))
    
          ;; sort by "PART-REF" :
    
          (setq total 0)
          (foreach i datalist (setq total (+ total (cdr i))))
        (initget 6)
      (setq txtheight (getreal "\nSpecify Text height for the table <50>:"))
      (cond ((not txtheight)(setq txtheight 50))) ;<-- text height as for as in your drawing
    
           (or adoc (setq adoc (vla-get-activedocument (setq acapp (vlax-get-acad-object)))))
          (or acsp (setq acsp (vla-get-block (vla-get-activelayout adoc))))
    (setq acCol (vla-GetInterfaceObject acapp(strcat "AutoCAD.AcCmColor." (itoa(atoi(getvar "acadver"))))))
          (setq pt (getpoint "\nSpecify table location:"))
          (setq atable (vla-addtable
    		     acsp
    		     (vlax-3d-point pt)
    		     (+ 2 (length tabledata))
    		     (length headers)
    		     (* txtheight 1.2)
    		     (* txtheight 20)
    		   )
          )
          (vla-put-regeneratetablesuppressed atable :vlax-true)
           ;; calculate column widths : 
          (setq swap (append (list headers) tabledata)
    	    widths nil)
          (while (car swap)
    	(setq column (mapcar 'car swap))
    	(setq colwidth (* 1.2 (apply 'max (mapcar 'strlen column))txtheight))
    	(setq widths (cons colwidth widths))
    	(setq swap (mapcar 'cdr swap)))
    
          (setq widths (reverse widths))
           ;; set column widths
    	   (setq col 0)
    	   (foreach wid widths
    	     (vla-setcolumnwidth atable col wid)
    	     (setq col (1+ col))
    	     )
          (vla-put-horzcellmargin atable (* txtheight 0.5))
          (vla-put-vertcellmargin atable (* txtheight 0.3))
          (vla-setTextheight atable 1 txtheight)
          (vla-setTextheight atable 2 txtheight)
          (vla-setTextheight atable 4 txtheight)
          (vla-setText atable 0 0 "PART SUMMARY")
          (vla-SetCellAlignment atable 0 0 acMiddleCenter)
                (vla-put-colorindex accol 2)
    (vla-setcellcontentcolor atable 0 0 accol)
          (setq col -1)
          (foreach descr headers
    	(vla-setText atable 1 (setq col (1+ col)) descr)
    	(vla-SetCellAlignment atable 1 col acMiddleCenter)
    	(vla-setcellcontentcolor atable 1 col accol)
          )
          
            (vla-put-colorindex accol 4)
          
           (setq row 2)
          
          (foreach record tabledata
    
    	(setq col 0)
    	(foreach item record
    	  (vla-setText atable row col item)
    	  (if (= 1 col)
    	  (vla-SetCellAlignment atable row col acMiddleCenter)
    	  (vla-SetCellAlignment atable row col acMiddleLeft)
               )
    	  (vla-setcellcontentcolor atable row col accol)
    	  (setq col (1+ col))
    	)
    	(setq row (1+ row))
          )
    (vla-put-width atable (apply '+ widths))
          (vla-put-height atable (* 1.2 (vla-get-rows atable)txtheight))
          (vla-put-regeneratetablesuppressed atable :vlax-false)
    
        )
      )
     (if  accol (vlax-release-object accol))
     (if  acapp (vlax-release-object acapp))
    (princ)
    )
    (prompt "\n\t---\tStart command with PARTREF3\t---\n")
    (prin1)
     (or (vl-load-com))
    (princ)
    
    ;;-------------------------------------------------------------------------------;;
    ~'J'~

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. AU2006 LISP Table Magic
    By peter in forum AutoLISP
    Replies: 6
    Last Post: 2019-04-18, 12:50 PM
  2. Curve Table Lisp Routine
    By julie.206712 in forum AutoLISP
    Replies: 7
    Last Post: 2013-08-20, 02:40 PM
  3. CP34-3: LISP Table Magic
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2013-04-17, 04:49 AM
  4. block and table lisp
    By john.237249 in forum AutoLISP
    Replies: 20
    Last Post: 2012-01-20, 04:35 AM
  5. Setting Plot Style Table in Lisp
    By fletch97 in forum AutoLISP
    Replies: 11
    Last Post: 2007-01-30, 09:43 PM

Posting Permissions

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