How to get total length of multiple dynamic blocks?

How to get total length of multiple dynamic blocks?

Anonymous
Not applicable
4,658 Views
13 Replies
Message 1 of 14

How to get total length of multiple dynamic blocks?

Anonymous
Not applicable

I got a lisp for counting total length of dynamic block (Distance1). But it is working only in horizontal type blocks not for vertical type. I want to quantify total length of the pipes in a drawing, all pipes are stretchable type dynamic block. Any body know how to get total Distance1 value of multiple dynamic blocks (stretchable type block) which is any rotation.

 

 

 

Here is the lisp..

 

(defun c:Test
              (/ total selectionset count intger selectionsetname a b)
  (vl-load-com)
;;; Tharwat 02 . April . 2012 ;;;
  ;; Count number of selected Dynamic blocks and length of selected dynamic blocks
  (if (setq total 0
            selectionset
             (ssget '((0 . "INSERT")
                      (-4 . "<or")
                      (2 . "`*U*")
                      (2 . "_P1000")
                      (-4 . "or>")
                     )
             )
      )
    (progn
      (setq count (sslength selectionset))
      (repeat (setq intger (sslength selectionset))
        (setq selectionsetname
               (ssname selectionset
                       (setq intger (1- intger))
               )
        )
        (vla-getboundingbox
          (vlax-ename->vla-object selectionsetname)
          'a
          'b
        )
        (setq total (+ total
                       (distance (list (car (vlax-safearray->list b))
                                       (cadr (vlax-safearray->list a))
                                 )
                                 (vlax-safearray->list a)
                       )
                    )
        )
      )
      (alert (strcat " Total number of Dynamic Blocks :"
                     "< "
                     (itoa count)
                     " >"
                     "\n"
                     " Total lengths of Dynamic Blocks :"
                     "< "
                     (rtos total 2)
                     " >"
             )
      )
    )
    (princ)
  )
  (princ)
)

 

0 Likes
Accepted solutions (1)
4,659 Views
13 Replies
Replies (13)
Message 2 of 14

ojuris
Advisor
Advisor

hi!

 

may be try DATAEXTRACTION

0 Likes
Message 3 of 14

ВeekeeCZ
Consultant
Consultant

Ok, try this modification.

 

Spoiler
(defun c:Test
              (/ totalh totalv selectionset count intger selectionsetname a b)
  (vl-load-com)
;;; Tharwat 02 . April . 2012 ;;;
  ;; Count number of selected Dynamic blocks and length of selected dynamic blocks
  (if (setq totalh 0
	    totalv 0
            selectionset
             (ssget '((0 . "INSERT")
                      (-4 . "<or")
                      (2 . "`*U*")
                      (2 . "_P1000")
                      (-4 . "or>")
                     )
             )
      )
    (progn
      (setq count (sslength selectionset))
      (repeat (setq intger (sslength selectionset))
        (setq selectionsetname
               (ssname selectionset
                       (setq intger (1- intger))
               )
        )
        (vla-getboundingbox
          (vlax-ename->vla-object selectionsetname)
          'a
          'b
        )
        (setq totalh (+ totalh
                       (distance (list (car (vlax-safearray->list b))
                                       (cadr (vlax-safearray->list a))
                                 )
                                 (vlax-safearray->list a)
                       )
                    )
	      totalv (+ totalv
                       (distance (list (car (vlax-safearray->list a))
                                       (cadr (vlax-safearray->list b))
                                 )
                                 (vlax-safearray->list a)
                       )
                    )
        )
      )
      (alert (strcat " Total number of Dynamic Blocks: "
                     "< "
                     (itoa count)
                     " >"
                     "\n"
                     " Total horizonatal lengths: "
                     "< "
                     (rtos totalh 2)
                     " >"
		     "\n"
                     " Total vertical lengths: "
                     "< "
                     (rtos totalv 2)
                     " >"
             )
      )
    )
    (princ)
  )
  (princ)
)
0 Likes
Message 4 of 14

Anonymous
Not applicable

Actually i don't need horizontal and vertical length separately. I need total length of the pipes at any rotation. When i run this lisp in one horizontal pipe block it shows horizontal and vertical length. I have a totlen.isp that calculate total length of the selected lines, polylines, arc, spline etc. That doesn't work in dynamic blocks. (Sorry for my poor English)...

 

Please see attached drawing.

0 Likes
Message 5 of 14

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, maybe like this... using Lee Mac's dynamic block functions available here... Thanks Lee.

 

Spoiler
(vl-load-com)

(defun c:Test
       (/ total selectionset count intger selectionsetname obj)
  
  (defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
	     (vlax-invoke blk 'getdynamicblockproperties)
	     )
    )
  
  (if (setq total 0
	    selectionset
	     (ssget '((0 . "INSERT")
		      (-4 . "<or")
		      (2 . "`*U*")
		      (2 . "_P1000")
		      (-4 . "or>")
		      )
		    )
	    )
    (progn
      (setq count (sslength selectionset))
      (repeat (setq intger (sslength selectionset))
	(setq selectionsetname
	       (ssname selectionset
		       (setq intger (1- intger))
		       )
	      obj (vlax-ename->vla-object selectionsetname)
	      total (+ total
		       (LM:getdynpropvalue obj "Distance1")
		       )))
      (alert (strcat " Total number of Dynamic Blocks :"
		     "< "
		     (itoa count)
		     " >"
		     "\n"
		     " Total lengths of Dynamic Blocks :"
		     "< "
		     (rtos total 2)
		     " >"
		     )
	     )
      )
    (princ)
    )
  (princ)
)
Message 6 of 14

Anonymous
Not applicable

This is what i am looking for. Thank you very much..Man Very Happy

0 Likes
Message 7 of 14

Anonymous
Not applicable

Thank you @ВeekeeCZ , you have salvaged my dreams of a dynamic wireway calculator!

;;;This code was originally created by Z9E3zK5E. 04-25-2016
;;;Altered and commented by user BW for personal use. 11-08-2021

(vl-load-com) ;load the good stuff
(defun c:PanCalc
       (/ width total selectionset count intger selectionsetname obj)
  (setq width (getreal "\n***___Please enter the width of the wireway you plan to select. (example: for 2x4 panduit, please enter '2'): "))
  (princ ( strcat "\nPlease select all of the " (rtos width 2)  " inch wide wireway in the drawing: "))

  ; ❤️ Lee Mac the Man, the Myth, the Legend <3
  (defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
	     (vlax-invoke blk 'getdynamicblockproperties)
	     )
    ) ; Lee Mac never ends. ;)
  
  (if (setq total 0
	    selectionset
	     (ssget '((0 . "INSERT")
		      (-4 . "<or")
		      (2 . "`*U*")
		      (2 . "_P1000")
		      (-4 . "or>")
		      )
		    ) ;end creating the selection set
	    )
    (progn
      (setq count (sslength selectionset))
      (repeat (setq intger (sslength selectionset))
	(setq selectionsetname
	       (ssname selectionset
		       (setq intger (1- intger))
		       )
	      obj (vlax-ename->vla-object selectionsetname)
	      total (+ total
		       (LM:getdynpropvalue obj "Length")
		       )) ;end adding up the lengths
	) ;end repeat
      (setq units (1+ (fix (* 1.25 (/ (/ total 12) 6)))))
      	(princ ( strcat "\nYou'll want to order the following number of 6 foot long by " (rtos width 2)  " units of wireway: ---> "))
        (princ (rtos units 2))
	  (alert (strcat "PLEASE ORDER ***___" (rtos units 2) "___*** UNIT(S) OF 6 FOOT LONG BY " (rtos width 2) " INCH WIDE PANDUIT/WIREWAY."))
      ) ;end progn
    (princ)
    ) ;end if
  (princ)
) ;end function

 

Message 8 of 14

Sea-Haven
Mentor
Mentor

Just a dumb question do the 6' units overlap ? If so is then the total length true ? I know with pipes it may be 6' long but has a 3" socket so is actually 5' 9"

0 Likes
Message 9 of 14

Anonymous
Not applicable

@Sea-Haven I suppose that could be an issue for piping. I'm an electrical panel guy, so my lisp only cares that I purchase the wireway in the correct number of 6 foot units that can all be cut to size.

I do add in an arbitrary 1.25 factor to account for wasted end-cuts that can't be reused.
That said, I have updated my code!
Now you do not need to select all the applicable blocks, just type the width in the command bar and presto! Order the number if units it spits out. 🙂
Big thanks to @ВeekeeCZ for the line of code that made my 2.0 version possible! (should be attached)

;;;WirewayCalc_2.2 by BW
(vl-load-com)
(defun c:PanCalc
       (/ realwidth width total selectionset intger selectionsetname obj)
  (setq width (getreal "\n***___Please enter the width of the wireway you plan to select. (example: for 2x4 panduit, please enter '2'): "))
  (setq realwidth (+ width 0.25))

  ; ❤️ Lee Mac the Man, the Myth, the Legend <3
  (defun LM:getdynpropvalue ( blk prp )
    (setq prp (strcase prp))
    (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
	     (vlax-invoke blk 'getdynamicblockproperties)
	     )
    ) ; Lee Mac never ends. ;)
  
  (if (setq total 0
	    selectionset
	     (ssget "x" '((2 . "`*U*"))
		    ) ;end creating the selection set
	    )
    (progn
      (repeat (setq intger (sslength selectionset))
	(setq selectionsetname
	       (ssname selectionset
		       (setq intger (1- intger))
		       )
	      obj (vlax-ename->vla-object selectionsetname)
	      total (+ total
		       (cond
			 (
			  (= (LM:getdynpropvalue obj "Width") realwidth)
			  (LM:getdynpropvalue obj "Length")
			 )
			 (0)
			) ;end conditional (thanks @Z9E3zK5E for the hint!) 	
	      ) ;end totaling the lengths
	  );end setqs    
       ) ;end repeat


      
      (setq units (1+ (fix (* 1.25 (/ (/ total 12) 6)))))
      	(princ ( strcat "\nYou'll want to order the following number of 6 foot long by " (rtos width 2)  " units of wireway: ---> "))
        (princ (rtos units 2))
	  (alert (strcat "PLEASE ORDER ***___" (rtos units 2) "___*** UNIT(S) OF 6 FOOT LONG BY " (rtos width 2) " INCH WIDE PANDUIT/WIREWAY."))
      ) ;end progn
    (princ)
    ) ;end if
  (princ)
) ;end function

Panel LayoutPanel Layout

0 Likes
Message 10 of 14

georg_holter
Contributor
Contributor

I have a question:
If i have many ident dynamic blocks (with different length and width) - is there any possibility to get this:
" -> Total length of dynamic Blocks with width *width (f.example 0.3)* :
-> Total length of dynamic Blocks with width *width (f.example 0.1)* :
-> Total length of dynamic Blocks with width *width (f.example 0.4)* : " and so forth....

that would be awesome!! 🙂
THANKS!!!

0 Likes
Message 12 of 14

youssef_264U854W
Observer
Observer

my regards
Thank you very much for this wonderful lisp, because I benefited a lot from it
Is it possible to put the result in a table so that it is the sum of the lengths of each individual block?
I wish you more success

0 Likes
Message 13 of 14

ВeekeeCZ
Consultant
Consultant

Make a new thread, post a sample file with a number of blocks and the desired shape of the table.

Message 14 of 14

youssef_264U854W
Observer
Observer

Thank you very much for your response and interest This is a file containing a network of pipes like the ones we want to limit for each project I limited it to the code that you kindly created But I added DESTANC2 to it because it only measures DESTANC1. I also added it to write the result on the screen, and I may have to choose one block at a time. I want it to calculate all the blocks at once and place each block individually with the sum of its lengths in front of it in a table like the one in this file. Many thanks and regards

0 Likes