How to count Blocks with different visibility status?

How to count Blocks with different visibility status?

smallƑish
Advocate Advocate
1,087 Views
5 Replies
Message 1 of 6

How to count Blocks with different visibility status?

smallƑish
Advocate
Advocate

I have same blocks with different visibility status, When I make quantities, how can I count those…?

 

 

***THE POST TITLE HAS BEEN EDITED FOR CLARITY***

0 Likes
Accepted solutions (1)
1,088 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Use THIS Lee's library...

 

(vl-load-com)

(defun c:CountDynStates ( / LM:getvisibilitystate LM:getdynpropvalue LM:getvisibilityparametername s i e v l a)


  ;; Get Dynamic Block Visibility State  -  Lee Mac
;; Returns the value of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Value of Visibility Parameter, else nil

(defun LM:getvisibilitystate ( blk / vis )
    (if (setq vis (LM:getvisibilityparametername blk))
        (LM:getdynpropvalue blk vis)
    )
)


  ;; Get Dynamic Block Property Value  -  Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)

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

  ;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Name of Visibility Parameter, else nil

(defun LM:getvisibilityparametername ( blk / vis )  
    (if
        (and
            (vlax-property-available-p blk 'effectivename)
            (setq blk
                (vla-item
                    (vla-get-blocks (vla-get-document blk))
                    (vla-get-effectivename blk)
                )
            )
            (= :vlax-true (vla-get-isdynamicblock blk))
            (= :vlax-true (vla-get-hasextensiondictionary blk))
            (setq vis
                (vl-some
                   '(lambda ( pair )
                        (if
                            (and
                                (= 360 (car pair))
                                (= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
                            )
                            (cdr pair)
                        )
                    )
                    (dictsearch
                        (vlax-vla-object->ename (vla-getextensiondictionary blk))
                        "ACAD_ENHANCEDBLOCK"
                    )
                )
            )
        )
        (cdr (assoc 301 (entget vis)))
    )
)


  (if (setq s (ssget '((0 . "INSERT"))))
    (repeat (setq i (sslength s))
      (if (setq v (LM:getvisibilitystate (vlax-ename->vla-object (ssname s (setq i (1- i))))))
	(setq l (if (setq a (assoc v l))
		  (subst (cons v (1+ (cdr a))) a l)
		  (cons (cons v 1) l))))))
  (print l)
  (princ)
  )

 

0 Likes
Message 3 of 6

smallƑish
Advocate
Advocate
Thank you so much for sharing this with me.

Can we combine the same with bcount program, (Lee's library...)
http://www.lee-mac.com/blockcounter.html

instead of coming in CMD line, it could appear in a table
0 Likes
Message 4 of 6

ВeekeeCZ
Consultant
Consultant

No.

0 Likes
Message 5 of 6

smallƑish
Advocate
Advocate

OK

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

When doing quantities it always ends up as a custom routine, there is so many different variables and user requirements that creep in, you have asked for 1,  a solution is offered and the final working version can be like 8 attempts later taking a lot of time and effort.

 

I know I have a count blocks but up to 5 levels deep in terms of the block details. The visibility and block name has used 2. 

 

In saying so if your happy to be patient and provide all details up front a solution can be offered maybe a donation required. As mentioned people offering solution hate, I want extra, I want extra, I want extra.

0 Likes