Visual LISP, AutoLISP and General Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi all,
Can some one help me a lisp to count dynamic block including total lenght.
Thanks
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi
The first block into your drawing is not considered as a Dynamic Block , so the following routine would would the trick on
the same dynamic blocks that you uploaded with you sample drawing .
(defun c:TesT (/ total selectionset count intger selectionsetname vl a b) (vl-load-com)
;;; Tharwat 02 . April . 2012 ;;;
;; Count number of selected Dynamic blocks and length of total selected dynamic blocks
(if (setq total 0
selectionset
(ssget '((0 . "INSERT") (2 . "`*U*")))
)
(progn
(setq count (sslength selectionset))
(repeat (setq intger (sslength selectionset))
(setq selectionsetname
(ssname selectionset
(setq intger (1- intger))
)
)
(setq vl (vlax-ename->vla-object selectionsetname))
(vla-getboundingbox vl 'a 'b)
(setq total (+ total
(distance (list (car (vlax-safearray->list b))
(cadr (vlax-safearray->list a))
)
(vlax-safearray->list a)
)
)
)
)
(print (strcat " Total number of Dynamic Blocks :"
"< "
(itoa count)
" >"
)
)
(print (strcat " Total lengths of Dynamic Blocks :"
"< "
(rtos total 2)
" >"
)
)
)
(princ)
)
(princ)
)
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
This one is a little bit better for the same block name and wth message box .
(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)
)
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi Tharwat, I know the OP show only the _p1000 "original" block.
But, what could be happen if there is another "original" block , and furthermore, what about if it have a inclination?.
I think the user shall pick the block to size and count, then using the EFFECTIVE NAME , select all them , or split them from the inserted blocks.
If they are not a 0 inclination or slope , there will be a issue to get the real distance.
Gabriel.
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Try this
(defun c:CDL ( / ss val ttl)
(setq bn "_P1000"
ttl 0 i 0)
(if (ssget "_X" (list '(0 . "INSERT")(cons 2 (strcat bn ",`*U*"))))
(progn
(vlax-for itm (setq ss (vla-get-activeselectionset
(vla-get-activedocument
(vlax-get-acad-object))))
(if (and (= :vlax-true
(vla-get-isdynamicblock itm))
(setq val (vl-remove-if-not
'(lambda (x)
(eq (vla-get-PropertyName
x)
"Distance"))
(vlax-invoke
itm
'getdynamicblockproperties))))
(setq ttl (+ ttl (vlax-get (car val) 'value)) i (1+ i))
)
)
(vla-delete ss)
(alert (strcat "Number of Blocks: " (itoa i)
"\nTotal Length: " (rtos ttl 2 2)))
)
(prompt "\n** Nothing selected ** "))
(princ))HTH
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
devitg wrote:
Hi PBEJSE , thanks again for it (vlax-invoke itm 'getdynamicblockproperties))))
Good for you Devtg
Cheers
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
devitg wrote:Hi Tharwat, I know the OP show only the _p1000 "original" block.
But, what could be happen if there is another "original" block , and furthermore, what about if it have a inclination?.I think the user shall pick the block to size and count, then using the EFFECTIVE NAME , select all them , or split them from the inserted blocks.
If they are not a 0 inclination or slope , there will be a issue to get the real distance.
Gabriel.
You're right devitg .
I knew that and I did not write the rotine before taking a look at the attached drawing . if all blocks are similar to the once in the drawing , the code would give correct lengths , otherwise there be a mistake in the total of lengths .
the routine that given by pBe is very accurate completely .
Thanks a lot.
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
_Tharwat wrote:You're right devitg .the routine that given by pBe is very accurate completely .Thanks a lot.Not at all Tharwat. it lacks error trapping besides i missed this part
....
(= :vlax-true (vla-get-isdynamicblock itm))
(eq (strcase (vla-get-effectivename itm)) bn)(setq val (vl-remove-if-not......
But thanks nonetheless tharwat.
Cheers
Re: COUNT DYNAMIC BLOCK INCLUDING TOTAL LENGTH
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for all, but what I mean is total of length for each piece including original block (_P1000) so I can able to cut them off.
Thanks



