See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Modify LISP For DB?

  1. #1
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Question Modify LISP For DB?

    Hey All,

    Fixo, in his mastery, had helped a fellow user create a table of attributes here. This is EXACTLY what I'm looking for, but... it doesn't seem to work with dynamic blocks. Is there something that can easily be done to modify code to work with DBs?

    Code by Fixo:
    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)
    
    ;;-------------------------------------------------------------------------------;;
    Thanks for taking a look,

    -stu
    Last edited by stusic; 2012-11-26 at 09:22 PM. Reason: The formatting was horrible.

  2. #2
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: Modify LISP For DB?

    Dynamic blocks dont have the same name as a regular block, they get renamed as an unnamed block. I use a lisp routine called Dynamic Block Functions to select dynamic blocks, I think I found it here on AUGI.

  3. #3
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Modify LISP For DB?

    Quote Originally Posted by ccowgill View Post
    Dynamic blocks dont have the same name as a regular block, they get renamed as an unnamed block. I use a lisp routine called Dynamic Block Functions to select dynamic blocks, I think I found it here on AUGI.
    I believe you're talking about Lee Mac's functions, but it only seems to cover dynamic functions. Are attribute functions different as well? I didn't see anything hinting at that...

    This might be over my head. I was hoping there was an easy fix since this is just like what I need.

    Thanks tho'

  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: Modify LISP For DB?

    Hello Phillip,
    upload please a sample drawing with blocks I didn't understand what is your aim
    I'm using A2010 btw

  5. #5
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Modify LISP For DB?

    Hey Fixo!

    I've gotta say I love this routine. It's super-fast and does the counts like the DATAEXTRACTION command does. I've used dataextraction for years, but ti's really slow and tedious. Your lisp is fast!

    From the thread I was reading, this does exactly what I need it to do. I was just hoping there was an easy way to make it work with DBs (but, alas, Autodesk doesn't make anything easy).

    I've uploaded a drawing exactly like one I use and kept the data extraction table that I create. There's two blocks - I use *Balloon* in all the other lisps to grab them both.

    Thanks for taking a look, I really appreciate it.
    Attached Files Attached Files

  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: Modify LISP For DB?

    Okay, I've got them
    But now is a nap time for me, Phillip
    so I will be back later
    See you

  7. #7
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Modify LISP For DB?

    Quote Originally Posted by fixo View Post
    Okay, I've got them
    But now is a nap time for me, Phillip
    so I will be back later
    See you
    Thanks Fixo!

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Modify LISP For DB?

    Anyone know what the hell is going on at ADesk? They seem to be losing the plot. I was trying to see if there was any improvement to DataExtraction ... but on ACA 2013 I cannot find that command anywhere. And since ACA ONLY HAS THE RIBBON I can't even try to find it anywhere else.

    The help shows it "should" be in the Annotation tab under the Tables panel. But ACA has no Tables panel in the Anno tab.
    Capture.PNG

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

    Default Re: Modify LISP For DB?

    I need few day to solve it, there is too difficult to solve this quickly
    Where I can get values for COUNT column?
    And one more qurestion
    I need to select just Balon_* blocks and not Cooper_* blocks,
    tell me about
    Oleg

  10. #10
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Modify LISP For DB?

    Quote Originally Posted by fixo View Post
    I need few day to solve it, there is too difficult to solve this quickly
    Where I can get values for COUNT column?
    And one more qurestion
    I need to select just Balon_* blocks and not Cooper_* blocks,
    tell me about
    Oleg
    Yes, I extract the information from both *Balloon* and *Copper* blocks. The count is the number of times that each unique PART_NUM appears in the drawing. This has been the main stumbling block - the DATAEXTRACTION command has that ability, but most other ways to extract that info don't. That's why I liked your code in the original thread.

    I realized that the example I sent was really confusing, so I've attached a simpler version. Hope this helps. Thanks so much Fixo, I really appreciate your help.
    Attached Files Attached Files

Page 1 of 2 12 LastLast

Similar Threads

  1. Help to modify this lisp
    By hasancad in forum AutoLISP
    Replies: 0
    Last Post: 2013-09-03, 09:14 AM
  2. Modify this lisp
    By gbailey403067 in forum AutoLISP
    Replies: 2
    Last Post: 2013-08-07, 05:23 PM
  3. HELP ME TO MODIFY SUM LISP
    By BILLYJOW in forum AutoLISP
    Replies: 5
    Last Post: 2012-09-14, 11:47 AM
  4. Modify CUI via LISP
    By ccowgill in forum AutoLISP
    Replies: 4
    Last Post: 2011-02-08, 07:26 AM
  5. Help Me (Hatch lisp Modify)
    By samtom123 in forum AutoLISP
    Replies: 3
    Last Post: 2009-09-09, 10:10 AM

Tags for this Thread

Posting Permissions

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