Results 1 to 7 of 7

Thread: Sum of Dynamic Block Properties

  1. #1

    Default Sum of Dynamic Block Properties

    Hi guys,

    im new here so dont be to hard on me my lisp skills are minimal so.
    Currently im working with a routine that returns the amount and property value of a certain block.

    This is the situation:

    Im having 1 block called "Mesh panels H1900"
    This block has an dynamic property called "Width" and at the moment this is what the routine returns:

    Code:
    There are 1 instances of "Mesh panels H1900" with property "Width" set to 1198.
    There are 2 instances of "Mesh panels H1900" with property "Width" set to 1298.
    There are 59 instances of "Mesh panels H1900" with property "Width" set to 1498.
    There are 8 instances of "Mesh panels H1900" with property "Width" set to 398.
    There are 1 instances of "Mesh panels H1900" with property "Width" set to 498.
    There are 1 instances of "Mesh panels H1900" with property "Width" set to 698.
    There are 1 instances of "Mesh panels H1900" with property "Width" set to 798.
    There are 1 instances of "Mesh panels H1900" with property "Width" set to 898.
    Now the thing i want is the Total width of All the mesh panels, could you guys help me with that ?

    Code:
    ;;;effname = name of block to count
    ;;;property = name of dynamic property to count
    (vl-load-com)
    (defun db_counts(effname property / sset proplist cnt en props old
    		)
      
      (setq sset(ssdblk effname))
      (if(not sset)
        (alert(strcat "No Dynamic Blocks with effective name:  " effname))
        (progn;else
          (setq proplist(list)
    	    cnt 0
          )
          (repeat(sslength sset)
    	(setq en(ssname sset cnt)
    	      cnt(1+ cnt)
    	)
    	(setq props(vlax-safearray->list(variant-value
    		(vla-getdynamicblockproperties(vlax-ename->vla-object en))))
    	)
    	(foreach n props
    	  (if(= (strcase(vla-get-propertyname n)) (strcase property))
    	    (cond
                  ((=(variant-type(vla-get-value n))2)
    		(setq proplist(cons(itoa(variant-value(vla-get-value n)))proplist))
    	      )
    	      ((<(variant-type(vla-get-value n))8)
    	        (setq proplist(cons(rtos(variant-value(vla-get-value n)))proplist))
    	      )
    	      (T (setq proplist(cons(variant-value(vla-get-value n))proplist)))
    	    );cond
    	  );if
    	);foreach
    	(setq proplist(vl-sort proplist '<))
          );repeat
          (setq cnt 0)
          (setq old nil)
          (foreach n proplist
    	(setq cnt(-(length proplist)(length(setq proplist(vl-remove n proplist)))))
    	(if(/= old n)
    	  (princ(strcat"\nThere are " (itoa cnt) " instances of \"" effname
    	 	       "\" with property \"" property "\" set to " n "."
    	        )
    	  )
    	)
    	(setq old n)
          );foreach
        );progn
      );if
      (setq sset nil)
      (princ)
    );defun
    (princ "\n(DB_COUNTS \"EFFNAME\" \"PROPERTY\")")

  2. #2
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    395

    Default Re: Sum of Dynamic Block Properties

    Quote Originally Posted by peter_zwiers350396 View Post

    Now the thing i want is the Total width of All the mesh panels, could you guys help me with that ?
    BTW. Welcome peter zwiers

    Code:
    ;;;effname = name of block to count
    ;;;property = name of dynamic property to count
    (vl-load-com)
    (defun db_counts(effname property / tw sset proplist cnt en props old
    		)
      
      (setq sset(ssdblk effname))
      (if(not sset)
        (alert(strcat "No Dynamic Blocks with effective name:  " effname))
        (progn;else
          (setq proplist(list)
    	    cnt 0
          )
          (repeat(sslength sset)
    	(setq en(ssname sset cnt)
    	      cnt(1+ cnt)
    	)
    	(setq props(vlax-safearray->list(variant-value
    		(vla-getdynamicblockproperties(vlax-ename->vla-object en))))
    	)
    	(foreach n props
    	  (if(= (strcase(vla-get-propertyname n)) (strcase property))
    	    (cond
                  ((=(variant-type(vla-get-value n))2)
    		(setq proplist(cons(itoa(variant-value(vla-get-value n)))proplist))
    	      )
    	      ((<(variant-type(vla-get-value n))8)
    	        (setq proplist(cons(rtos(variant-value(vla-get-value n)))proplist))
    	      )
    	      (T (setq proplist(cons(variant-value(vla-get-value n))proplist)))
    	    );cond
    	  );if
    	);foreach
    	(setq proplist(vl-sort proplist '<))
          );repeat
          (setq cnt 0)
          (setq old nil)
    ;;;;			      
          (Setq tw (mapcar 'distof proplist))
    ;;;;			      
          (foreach n proplist
    	(setq cnt(-(length proplist)(length(setq proplist(vl-remove n proplist)))))
    	(if(/= old n)
    	  (princ(strcat"\nThere are " (itoa cnt) " instances of \"" effname
    	 	       "\" with property \"" property "\" set to " n "."
    	        )
    	  )
    	)
    	(setq old n)
          );foreach
    ;;;;			
         (if tw (princ (Strcat "\nTotal Width: " (rtos (apply '+ tw)))))
    ;;;;			
        );progn
      );if
      ;;; (setq sset nil)
      (princ)
    );defun
    
    (princ "\n(DB_COUNTS \"EFFNAME\" \"PROPERTY\")")
    HTH
    Last edited by pbejse; 2013-01-05 at 11:00 AM.

  3. #3
    I could stop if I wanted to Norton_cad's Avatar
    Join Date
    2007-05
    Location
    Bardwell Valley, Sydney, Australia
    Posts
    433

    Default Re: Sum of Dynamic Block Properties

    A non-lisp routine solution, would be to use tables to extract the dynamic block properties. Also the table would automatically update, as changes are made in the drawing.
    Ohm's Law - Electricity follows the path of least resistance.

    Regards,

    Mark Norton,

  4. #4
    Past Vice President peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu Hawaii
    Posts
    574

    Default Re: Sum of Dynamic Block Properties

    I just tried to see if I could cut the amount of code

    Code:
    (defun C:SumWidth (/ intCount objSelection ssSelections sngTotal sngWidth)
     (vl-load-com)
     (setq sngTotal 0.0)
     (if (setq ssSelections (ssget (list (cons 0 "insert"))))
      (repeat (setq intCount (sslength ssSelections))
       (setq intCount     (1- intCount)
             objSelection (vlax-ename->vla-object 
                           (ssname ssSelections intCount))
       
       )
       (and (setq sngWidth (cadr (assoc "Width" (getdynamics objSelection))))
            (setq sngTotal (+ sngTotal sngWidth)) 
       )
      )
     )
     sngTotal
    )
    
    (defun GetDynamics (objSelection )                
     (mapcar '(lambda (x)(list (vla-get-propertyname X)
                               (variant-value (vla-get-value X)))) 
              (vlax-invoke objSelection "GetDynamicBlockProperties"))
    )
    AUGI Volunteer

  5. #5
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    395

    Default Re: Sum of Dynamic Block Properties

    Another

    Code:
    (Defun c:sumw ( / ss e d db lst)
      	(if (setq ss (ssget (list (cons 0 "insert"))))
    	(repeat (sslength ss)
            		(setq e (vlax-ename->vla-object (ssname ss 0)))
    			(if (and  (eq (vla-get-IsDynamicBlock e) :vlax-true)
                    (setq db (Car (vl-remove-if-not (function (lambda (x)
    								(eq "Width" (vla-get-propertyname X))))                                                    
            				(vlax-invoke e "GetDynamicBlockProperties")))))
                	  		(if (Setq d (assoc (setq bn (vla-get-effectivename e)) lst))
                              (setq lst (subst (list bn (+ (vlax-get db 'Value)(cadr d))) d lst))
                              (setq lst (cons (list bn (vlax-get db 'Value)) lst))
                            ))
            	(ssdel (ssname ss 0) ss)
            )
            )
      (foreach itm lst
            (print itm))
      (princ)
      )

  6. #6

    Default Re: Sum of Dynamic Block Properties

    Awesome! it works like a charm, Thanks for the support

  7. #7
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    395

    Default Re: Sum of Dynamic Block Properties

    Quote Originally Posted by peter_zwiers350396 View Post
    Awesome! it works like a charm, Thanks for the support
    We are glad to be of service peter_zwiers. Hope you learn something from the snippets.

    Keep on coding.

Similar Threads

  1. Dynamic Block Table Properties
    By stusic in forum AutoLISP
    Replies: 19
    Last Post: 2012-12-04, 08:06 PM
  2. Table for updating dynamic block properties
    By parkerfeldman in forum AutoLISP
    Replies: 0
    Last Post: 2009-02-03, 06:34 PM
  3. Modify Dynamic Block Properties within a Table Cell
    By ccowgill in forum AutoCAD Tables
    Replies: 2
    Last Post: 2008-05-22, 05:15 PM
  4. Using Lookup properties to control appearance of Dynamic Block
    By r424andy in forum Dynamic Blocks - Technical
    Replies: 10
    Last Post: 2006-08-01, 10:04 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
  •