Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: lisp table help

  1. #1
    Login to Give a bone
    0

    Default lisp table help

    hey there

    mij name is kevin and i'm having a littel troble whit a lisp i'm tring te create
    i want to create a table which uses extracted data from multiple blocks these bloks all have atributes addet to them whit diverent values

    more or les it needs to look like this

    name
    -------------------------
    block1/amount/value1/value2/value3
    block2/amount/value1/value2/value3
    block3/amount/value1/value2/value3


    includit are two sampels of the block that i use and a example
    sampel.dwg
    Last edited by kevinjorisjacques967722; 2012-01-19 at 02:47 PM.

  2. #2
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: lisp table help

    From the looks of it you used Dataextraction.
    So what wrong with it?

    if you already have the DXE file. you can use

    (defun Itable (path)
    (command "-dataextraction" path)
    )

    (Itable "c:\\path\\template.dxe")

    And you will be prompted for the insertion point.
    Last edited by pbejse; 2012-01-20 at 09:15 AM.

  3. #3
    Login to Give a bone
    0

    Default Re: lisp table help

    Quote Originally Posted by pbejse View Post
    From the looks of it you used Dataextraction.
    So what wrong with it?

    if you already have the DXE file. you can use

    (defun Itable (path)
    (command "-dataextraction" path)
    )

    (Itable "c:\\path\\template.dxe")

    And you will be prompted for the insertion point. Cannoscale variable will take care of the scaling for you
    maby but then i cant select wich blocks i wanto ad

    and it changes it it becomes likesampel.dwg
    Last edited by kevinjorisjacques967722; 2012-01-20 at 09:49 AM.

  4. #4
    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 this routine but I'm not sure if it will be work for your Acad release
    Mine is A2009, this lisp is working good in there
    Code:
    (defun C:Bomt(/  acsp adoc atable attdata attitem atts blkdata blkname blkobj col datalist
    		  en headers pt row sset tabledata tags total txtheight x)
      
      ;local defun
      (defun sum-and-groupby-all (lst / groups res sum tmp)
      (while lst
        (setq tmp	    (car lst)
    	  sum
    		    (apply '+
    			   (mapcar 'car 
    				   (setq res (vl-remove-if-not
    
    					       '(lambda (a) (vl-every 'eq a tmp))
    
    					       lst
    
    					     )
    				   )
    			   )
    		    )
    	  groups    (cons (subst (itoa sum) (car tmp) tmp) groups)
    	  lst
    		    (vl-remove-if
    		      '(lambda (a) (member a res))
    
    		      lst
    
    		    )
        )
      )
     
     (reverse groups)
    )
    
    ;main part
      (if (setq sset (ssget (list (cons 0 "INSERT") (cons 66 1))))
        (progn
          (setq tabledata nil
    	    attdata nil
    	    attitem nil
          )
          (setq headers (list "Count" "Name" "SCH" "PLEN" "INHEI" "AFHAK" "SLEN" "PWAP" "DRAAGF" "TREKF")
    	    tags    (cddr headers)
          )
          (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
    	  (if (member (vla-get-tagstring attobj) tags)
    	    (progn
    	      (setq attitem (cons (vla-get-tagstring attobj) (vla-get-textstring attobj)))
    	      (setq attdata (cons attitem attdata))
    	    )
    	  )
    	)
    	(setq blkdata (append (list 1 blkname) (reverse attdata)))
    	(setq tabledata (cons blkdata tabledata))
    	(setq attdata nil
    	      attitem nil
    	)
    	(ssdel en sset)
          )
    
          (setq tabledata (mapcar '(lambda (x)
    				 (append (list (car x) (cadr x))
    					 (mapcar 'cdr (cddr x))
    				 )
    			       )
    			      tabledata
    		      )
          )
    
    
          (setq tabledata (sum-and-groupby-all tabledata))
          
          ;; sort by "SCH" :
          (setq tabledata (vl-sort tabledata '(lambda (a b) (< (caddr a) (caddr b)))))
    
    
          (setq total 0)
          (foreach i datalist (setq total (+ total (cdr i))))
          (or (not (zerop
    		 (setq txtheight
    			(getvar "textsize")
    		 )
    	       )
    	  )
    	  (setq txtheight 54.0)
          ) ;<-- text height as for as in your drawing
    
          (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
          (or acsp (setq acsp (vla-get-block (vla-get-activelayout adoc))))
          (setq pt (getpoint "\nSpecify table location:"))
          (setq atable (vla-addtable
    		     acsp
    		     (vlax-3d-point pt)
    		     (+ 2 (length tabledata))
    		     (length headers)
    		     (* txtheight 2)
    		     (* txtheight 8)
    		   )
          )
          (vla-put-regeneratetablesuppressed atable :vlax-true)
          (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 "Bom")
          (vla-SetCellAlignment atable 0 0 acMiddleCenter)
          (setq col -1)
          (foreach descr headers
    	(vla-setText atable 1 (setq col (1+ col)) descr)
    	(vla-SetCellAlignment atable 1 col acMiddleCenter)
          )
          (setq row 2)
          (foreach record tabledata
    
    	(setq col 0)
    	(foreach item record
    	  (vla-setText atable row col item)
    	  (vla-SetCellAlignment atable row col acMiddleLeft)
    
    	  (setq col (1+ col))
    	)
    	(setq row (1+ row))
          )
    
          (vla-put-regeneratetablesuppressed atable :vlax-false)
    
        )
      )
    (princ)
    )
    (prompt "\n Styart command with BOMT...\n")
    (prin1)
     (or (vl-load-com))
    (princ)
    ~'J'~

  5. #5
    Active Member
    Join Date
    2015-08
    Posts
    59
    Login to Give a bone
    0

    Default Re: lisp table help

    Quote Originally Posted by fixo View Post
    Try this routine but I'm not sure if it will be work for your Acad release
    Mine is A2009, this lisp is working good in there
    Code:
    (defun C:Bomt(/  acsp adoc atable attdata attitem atts blkdata blkname blkobj col datalist
    		  en headers pt row sset tabledata tags total txtheight x)
      
      ;local defun
      (defun sum-and-groupby-all (lst / groups res sum tmp)
      (while lst
        (setq tmp	    (car lst)
    	  sum
    		    (apply '+
    			   (mapcar 'car 
    				   (setq res (vl-remove-if-not
    
    					       '(lambda (a) (vl-every 'eq a tmp))
    
    					       lst
    
    					     )
    				   )
    			   )
    		    )
    	  groups    (cons (subst (itoa sum) (car tmp) tmp) groups)
    	  lst
    		    (vl-remove-if
    		      '(lambda (a) (member a res))
    
    		      lst
    
    		    )
        )
      )
     
     (reverse groups)
    )
    
    ;main part
      (if (setq sset (ssget (list (cons 0 "INSERT") (cons 66 1))))
        (progn
          (setq tabledata nil
    	    attdata nil
    	    attitem nil
          )
          (setq headers (list "Count" "Name" "SCH" "PLEN" "INHEI" "AFHAK" "SLEN" "PWAP" "DRAAGF" "TREKF")
    	    tags    (cddr headers)
          )
          (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
    	  (if (member (vla-get-tagstring attobj) tags)
    	    (progn
    	      (setq attitem (cons (vla-get-tagstring attobj) (vla-get-textstring attobj)))
    	      (setq attdata (cons attitem attdata))
    	    )
    	  )
    	)
    	(setq blkdata (append (list 1 blkname) (reverse attdata)))
    	(setq tabledata (cons blkdata tabledata))
    	(setq attdata nil
    	      attitem nil
    	)
    	(ssdel en sset)
          )
    
          (setq tabledata (mapcar '(lambda (x)
    				 (append (list (car x) (cadr x))
    					 (mapcar 'cdr (cddr x))
    				 )
    			       )
    			      tabledata
    		      )
          )
    
    
          (setq tabledata (sum-and-groupby-all tabledata))
          
          ;; sort by "SCH" :
          (setq tabledata (vl-sort tabledata '(lambda (a b) (< (caddr a) (caddr b)))))
    
    
          (setq total 0)
          (foreach i datalist (setq total (+ total (cdr i))))
          (or (not (zerop
    		 (setq txtheight
    			(getvar "textsize")
    		 )
    	       )
    	  )
    	  (setq txtheight 54.0)
          ) ;<-- text height as for as in your drawing
    
          (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
          (or acsp (setq acsp (vla-get-block (vla-get-activelayout adoc))))
          (setq pt (getpoint "\nSpecify table location:"))
          (setq atable (vla-addtable
    		     acsp
    		     (vlax-3d-point pt)
    		     (+ 2 (length tabledata))
    		     (length headers)
    		     (* txtheight 2)
    		     (* txtheight 8)
    		   )
          )
          (vla-put-regeneratetablesuppressed atable :vlax-true)
          (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 "Bom")
          (vla-SetCellAlignment atable 0 0 acMiddleCenter)
          (setq col -1)
          (foreach descr headers
    	(vla-setText atable 1 (setq col (1+ col)) descr)
    	(vla-SetCellAlignment atable 1 col acMiddleCenter)
          )
          (setq row 2)
          (foreach record tabledata
    
    	(setq col 0)
    	(foreach item record
    	  (vla-setText atable row col item)
    	  (vla-SetCellAlignment atable row col acMiddleLeft)
    
    	  (setq col (1+ col))
    	)
    	(setq row (1+ row))
          )
    
          (vla-put-regeneratetablesuppressed atable :vlax-false)
    
        )
      )
    (princ)
    )
    (prompt "\n Styart command with BOMT...\n")
    (prin1)
     (or (vl-load-com))
    (princ)
    ~'J'~
    Fixo: where in the program does someone change the size or scale of the table ?
    regards and TIA, Steve

  6. #6
    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 Steve,
    Do you want to scale the whole table or
    just sparate rows/columns?
    If the first one then easy to apply (vla-scale... ) or
    command "scale" to do work or just change txtheight variable
    within the code accordingly to your standard text height
    Regards,

    Oleg

  7. #7
    Active Member
    Join Date
    2015-08
    Posts
    59
    Login to Give a bone
    0

    Smile Re: lisp table help

    Quote Originally Posted by fixo View Post
    Hi Steve,
    Do you want to scale the whole table or
    just sparate rows/columns?
    If the first one then easy to apply (vla-scale... ) or
    command "scale" to do work or just change txtheight variable
    within the code accordingly to your standard text height
    Regards,

    Oleg
    Thanks for help Oleg:
    I found that textsize setting in Acad was controlling the table size even though the setting for txtheight was set to what I wanted it to be. Setting them both the same did the trick.
    Steve

  8. #8
    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

    You're welcome, Steve
    Cheers

    Oleg

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

    Default Re: lisp table help

    Hi Oleg and others,

    I read this thread with interest because I have a requirement for something very similar.
    I have created a drawing (attached) with two "Tag to Table" requirements.

    I am wondering if this is something that would not take much time to solve.

    I tried altering your code myself, but had difficulties. (I am not so familiar with lisp), I do not need the tag name. I also notice that the first attribute is ignored in your code.

    Anyway, I would of course be grateful for any assistance in this.

    Additional queries......Is there a way of fixing the table column widths to match the length of text? Is it possible to do a direct export of a table to Excel with columns and rows being the same?

    Gosh! I am asking for a lot.

    Rgds from hopeful me.
    Attached Files Attached Files

  10. #10
    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
    Hi Oleg and others,

    I read this thread with interest because I have a requirement for something very similar.
    I have created a drawing (attached) with two "Tag to Table" requirements.

    I am wondering if this is something that would not take much time to solve.

    I tried altering your code myself, but had difficulties. (I am not so familiar with lisp), I do not need the tag name. I also notice that the first attribute is ignored in your code.

    Anyway, I would of course be grateful for any assistance in this.

    Additional queries......Is there a way of fixing the table column widths to match the length of text? Is it possible to do a direct export of a table to Excel with columns and rows being the same?

    Gosh! I am asking for a lot.

    Rgds from hopeful me.
    Hi Mark
    Welcome on board
    I can't do it right now by reason of we have here
    the holyday, but I will be back as soon as possible
    Have a great day

    Oleg

    ~'J'~

Page 1 of 3 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
  •