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

Changing Visibility States for All Blocks in Drawing

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
ALPERTOLGAPERCINEL
435 Views, 6 Replies

Changing Visibility States for All Blocks in Drawing

Hi to everyone. I want to use this routine for all blocks in the drawing:

 

(defun CHGDYNPROP (Ename propname newval / lo obj v vval sal tot i)
(setq obj (if (= (type Ename) 'vla-object)
Ename
(vlax-ename->vla-object Ename))
v (vla-getdynamicblockproperties obj)
vval (vlax-variant-value v)
sal (vlax-safearray->list vval)
tot (length sal)
i 0)
(while (< i tot)
(if (= (vlax-get-property (nth i sal) "PropertyName") propname)
(progn
(vlax-put-property (nth i sal) "Value" newval)
(setq i tot)
)
(setq i (1+ i))
)
)
)
(CHGDYNPROP (entlast) "Scale" "1")
(princ)

 

 

but because of (entlast) function, it affects only last object in the drawing. what can i do to this lisp routine for affecting to all blocks?

6 REPLIES 6
Message 2 of 7
pbejse
in reply to: ALPERTOLGAPERCINEL


@ALPERTOLGAPERCINEL4333 wrote:

Hi to everyone. I want to use this routine for all blocks in the drawing:

   

but because of (entlast) function, it affects only last object in the drawing. what can i do to this lisp routine for affecting to all blocks?


You know what, i think it would be loads easier if you use _properties <CTRL 1> , But if you want a lisp code then

 

(defun c:SelectDB ( / ss i)
  (if (setq ss (ssget "_:L" '((2 . "SCALE BARS,`*U*"))));<-- whatever the block name is
    (repeat (setq i (sslength ss))

      (CHGDYNPROP (ssname ss (setq i (1- i))) "Scale" "1");<-- whatever the property name is
    )
  )
  (princ)
)

 

 

HTH

 

 

 

 

Message 3 of 7
ALPERTOLGAPERCINEL
in reply to: pbejse

Thanks for the script but i want to use this routine for different blocks but same visibility names in drawing. Yes, we can do it from the Properties panel with similiar selection but i need to run in lisp. Because this will be a part of another routine.

Message 4 of 7

Untested (I don't have AutoCAD in this laptop), but perhaps something like this

;;Usaqe
;;(dyn_prop "Width" 1200.0)
;; Width >> the property name
;; 1200.0 >> a valid value
(vl-load-com)
(defun dyn_prop (property newvalue / adoc allval)
  (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
  (vlax-for layt (vla-get-layouts adoc)
    (vlax-for blk (vla-get-block layt)
      (if
        (and (= (vla-get-objectname blk) "AcDbBlockReference")
             (= (vlax-get-property blk 'isdynamicblock) :vlax-true)
        )
         (foreach p (vlax-safearray->list
                      (vlax-variant-value (vla-getdynamicblockproperties blk))
                    )
           (if (and (= (vlax-get p 'PropertyName) property)
                    (vlax-property-available-p p 'Value)
                    (or (not (setq allval (vlax-get p 'allowedvalues)))
                        (member newvalue allval)
                    )
               )
             (progn (vlax-put-property p 'Value newvalue) (vla-update blk))
           )
         )
      )
    )
  )
  (princ)
)

 

I hope this helps

Henrique

 

EESignature

Message 5 of 7
pbejse
in reply to: ALPERTOLGAPERCINEL


@ALPERTOLGAPERCINEL4333 wrote:

Thanks for the script but i want to use this routine for different blocks but same visibility names in drawing. Yes, we can do it from the Properties panel with similiar selection but i need to run in lisp. Because this will be a part of another routine.


I see, Anyhoo Hmsilva provided a code that will do just that.

 

Cheers

Message 6 of 7

Thank you. It did the job well. 🙂

Message 7 of 7

You're welcome, ALPERTOLGAPERCINEL4333
Glad I could help

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