How to get total length of multiple dynamic blocks with different width?

How to get total length of multiple dynamic blocks with different width?

georg_holter
Contributor Contributor
1,156 Views
3 Replies
Message 1 of 4

How to get total length of multiple dynamic blocks with different width?

georg_holter
Contributor
Contributor

Hello,

If i have many ident dynamic blocks (with different dynamic length (=Distance1) and width (=Distance2)) - is there any possibility to get this result:
" -> 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....

 

see also the attached pic!

 

This Lisp is nearly there i have to get to (BIG THANKS TO @ВeekeeCZ) :

(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)
)

 

The PERFECTNESS would be to choose optional output results in CSV.


please help me!

 

that would be awesome!

THANK YOU VERY MUCH!!!!!

0 Likes
Accepted solutions (1)
1,157 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

The code is not really mine, so just quickly.

If you need a csv, just a search for it, plenty of examples. I'm sure you'll figure.

Good luck.

 

(vl-load-com)

(defun c:ListP1000 ( / s i e d w l a)

  (if (setq s (ssget '((0 . "INSERT") (2 . "`*U*,_P1000"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (if (and (not (vl-catch-all-error-p (setq d (vl-catch-all-apply 'getpropertyvalue (list e "AcDbDynBlockPropertyDistance1")))))
	       (not (vl-catch-all-error-p (setq w (vl-catch-all-apply 'getpropertyvalue (list e "AcDbDynBlockPropertyDistance2")))))
	       (setq w (rtos w))
	       )
	(setq l (if (setq a (assoc w l))
		  (subst (cons w (+ d (cdr a))) a l)
		  (cons (cons w d) l))))))
  (alert (princ (apply 'strcat (mapcar '(lambda (x) (strcat "\nTotal length of w" (car x) ": " (rtos (cdr x)))) l))))
  (princ)
  )

 

0 Likes
Message 3 of 4

georg_holter
Contributor
Contributor
Thank you (AGAIN) !!! You`re THE MAN!!!!!! my head is spinning again.... 😄
AND: you're right! i'm sorry...i think the Original code is from @Anonymous ! THANK YOU!!

0 Likes
Message 4 of 4

aaron_gonzalez
Contributor
Contributor
here is a little modificaction, you can drop the length of the dynamic block in the block
 
 
(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")
       )))
 
(setq lon-total (apply '+ ld-list))
(setq nombre (getstring T "\nIngrese un nombre: "))
(setq xyz (getpoint "Press the mouse button: ")) ;obtiene posicion del puntero-raton
(command "_.color" "bylayer") 
(command "_.text" "ML" xyz 1 0 (strcat "L :" (rtos total 2 0 ) " m, " nombre " , " (itoa count) " tramos " ) ) ;; Formato y prescicion
(command "_.color" "BYLAYER")
 
      )
    (princ)
    )
  (princ)
)
0 Likes