Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select all same visibility

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
JCprog
1056 Views, 3 Replies

Select all same visibility

Hello EveryoneSmiley Happy

 

Found this code that selects similar dynamic blocks and works great. Need someones expertise to help modify to select all dynamic blocks with same visibility only. Please help!!!! 

 

(defun c:qsdb ( / SSET HND LAY OBJ)
  (if (/= (setq sset (ssget "_I")) nil)
    (setq hnd (ssname sset 0))
    (setq hnd (car (entsel "\nDS> Select Object Type: ")))
    )
  (if (/= hnd nil)
    (progn
      (setq obj (cdr (assoc 0 (entget hnd)))
        lay (cdr (assoc 8 (entget hnd))))
      (setq sset (ssget "_X" (list (cons 0 obj)(cons 8 lay))))
      (if (> (sslength sset) 0)
    (sssetfirst sset sset)
    )
      )
    )
  (princ)
  )

 Thanks in advanceSmiley Happy

3 REPLIES 3
Message 2 of 4
hmsilva
in reply to: JCprog

Quick and dirty, and only as a demo...
For this I used three Lee Mac's functions LM:getdynpropvalue LM:getvisibilityparametername and LM:getvisibilitystate Thank you Lee.

 

(defun c:demo ( / EFNAM HND1 I OBJ OBJ1 PROPVAL SEL SS SS1)
  (vl-load-com)

;; 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 )
    (LM:getdynpropvalue blk (LM:getvisibilityparametername blk))
)
;; 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)))
    )
)
;; 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)
    )
)


  (if (and (setq sel (car (entsel)))
	   (setq obj (vlax-ename->vla-object sel))
	   (vlax-property-available-p obj 'isdynamicblock)
	   (= (vla-get-isdynamicblock obj) :vlax-true)
	   (setq efnam (vla-get-effectivename obj))
	   (setq propval (LM:getvisibilitystate obj))
	   (setq ss
		  (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat efnam ",`*U*")) (cons 410 (getvar 'CTAB))))
	   )
      )
    (progn
      (setq ss1 (ssadd))
      (repeat (setq i (sslength ss))
	(setq hnd1 (ssname ss (setq i (1- i)))
	      obj1 (vlax-ename->vla-object hnd1)
	)
	(if (= propval (LM:getvisibilitystate obj1))
	  (ssadd hnd1 ss1)
	)
      )
      (if (> (sslength ss1) 0)
	(sssetfirst nil ss1)
      )
    )
  )
  (princ)
)

 

hope that helps
Henrique

 

EESignature

Message 3 of 4
JCprog
in reply to: hmsilva

Wow! Thanks Henrique for putting it together, really appreciate itSmiley Happy

and Thanks Lee for very useful functionsSmiley Happy

Message 4 of 4
hmsilva
in reply to: JCprog

You're welcome, JCprog.

 

Please pay attention that, for the blocks stay selected and griped, PICKFIRST System Variable must be 1.

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost