Dorian Gray Posted May 8, 2014 Posted May 8, 2014 (edited) What I am looking for is a lisp that allows me to select the dynamic block and change the visibility by script. What I have is a number of Dynamic blocks in drawings that require the visibility states changed. I currently have a lsp that picks the block and changes the visibility state, however this is hard to manage because I have to change the selected visibility in the lsp, if i have a number of dynamic blocks I want to target then I have to change the lsp every time. It would be nice if there was a lsp that allowed me to select the dynamic block and change the visibility state via a command. for example the lsp would allow me via a script to select the dynamic block and change the visibility state. below is the a lsp that I found which works but not how I would like it to work. Can anyone help. I have come across a number of lsp but they don't seem to do what I need. hopefully there is already something out there (defun c:CHDYB ( / ss dynProps val) (vl-load-com) (if (setq ss (ssget "_x" '((0 . "INSERT") (8 . "*z_blocks*")))) (progn (vla-startundomark (cond (*activeDoc*) ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))) (vlax-for x (setq ss (vla-get-activeselectionset *activeDoc*)) (if (and (= :vlax-true (vla-get-isdynamicblock x)) (vl-string-search "z_blocks" (strcase (vla-get-effectivename x))) (setq dynProps (car (vlax-invoke x 'getdynamicblockproperties))) (vl-position (cond (val) ((setq val "M18"))) (vlax-get dynProps 'allowedvalues))) (vlax-put-property dynProps 'value val))) (vla-endundomark *activeDoc*) (vla-delete ss)) (prompt "\n** Nothing selected ** ")) (princ)) Edited March 28, 2016 by SLW210 Quote
Bhull1985 Posted May 8, 2014 Posted May 8, 2014 Try Lee Mac's insertwithvisstate lisp ;; Insert With Visibility State - Lee Mac ;; Provides an interface through which the user can insert a dynamic block ;; with a preselected visibility state. ;; blk - [str] Block name, filename or full filepath ;; vis - [str] Visibility State to set on insertion ;; Returns: [vla] Inserted VLA block reference object, else nil if unsuccessful (defun LM:insertwithstate ( blk vis / bse cmd def ent ext new obj pth rtn tmp ) (setq pth (vl-string-translate "/" "\\" (vl-filename-directory blk)) ext (cond ((vl-filename-extension blk)) (".dwg")) bse (vl-filename-base blk) ) (if (/= "" pth) (setq pth (strcat pth "\\")) ) (cond ( (not (or (and (tblsearch "block" bse) (setq blk bse) ) (setq blk (findfile (strcat pth bse ext))) ) ) (prompt (strcat "\nBlock \"" bse "\" not found.")) ) ( (progn (setq obj (vlax-invoke (vlax-get-property (LM:acdoc) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace ) ) 'insertblock '(0.0 0.0 0.0) blk 1.0 1.0 1.0 0.0 ) ) (vla-put-visible obj :vlax-false) (= :vlax-false (vla-get-isdynamicblock obj)) ) (vla-delete obj) (prompt (strcat "\nBlock \"" bse "\" is not dynamic.")) ) ( (null (LM:setvisibilitystate obj vis)) (vla-delete obj) (prompt (strcat "\nUnable to set visibility state of block \"" bse "\" to \"" vis "\"." ) ) ) ( (setq tmp 0) (while (tblsearch "block" (setq blk (strcat "tmp" (itoa (setq tmp (1+ tmp)))) ) ) ) (vla-put-visible (car (vlax-invoke (LM:acdoc) 'copyobjects (list obj) (setq def (vlax-invoke (vla-get-blocks (LM:acdoc)) 'add '(0.0 0.0 0.0) blk ) ) ) ) :vlax-true ) (vla-delete obj) (setq ent (entlast) cmd (getvar 'cmdecho) ) (setvar 'cmdecho 0) (princ "\nSpecify insertion point: ") (if (and (vl-cmdf "_.-insert" blk "_S" 1.0 "_R" 0.0 "\\") (not (eq ent (setq ent (entlast)))) (setq new (vlax-ename->vla-object ent)) (= "AcDbBlockReference" (vla-get-objectname new)) ) (progn (setq rtn (car (vlax-invoke new 'explode))) (vla-delete new) ) ) (setvar 'cmdecho cmd) (vl-catch-all-apply 'vla-delete (list def)) ) ) rtn ) ;; 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))) ) ) ;; Set Dynamic Block Visibility State - Lee Mac ;; Sets the Visibility Parameter of a Dynamic Block to a specific value ;; blk - [vla] VLA Dynamic Block Reference object ;; val - [str] Visibility State Parameter value ;; Returns: [str] New value of Visibility Parameter, else nil (defun LM:setvisibilitystate ( blk val / vis ) (if (and (setq vis (LM:getvisibilityparametername blk)) (member (strcase val) (mapcar 'strcase (LM:getdynpropallowedvalues blk vis)) ) ) (LM:setdynpropvalue blk vis val) ) ) ;; Get Dynamic Block Property Allowed Values - Lee Mac ;; Returns the allowed values for a specific Dynamic Block property. ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; Returns: [lst] List of allowed values for property, else nil if no restrictions (defun LM:getdynpropallowedvalues ( blk prp ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'allowedvalues))) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;; Set Dynamic Block Property Value - Lee Mac ;; Modifies the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; val - [any] New value for property ;; Returns: [any] New value if successful, else nil (defun LM:setdynpropvalue ( blk prp val ) (setq prp (strcase prp)) (vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (progn (vla-put-value x (vlax-make-variant val (vlax-variant-type (vla-get-value x)))) (cond (val) (t)) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) ;; Active Document - Lee Mac ;; Returns the VLA Active Document Object (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)) ) ) (LM:acdoc) ) (vl-load-com) (princ) If you're missing any of the helper functions then they are available to download off of his website. Cheers Quote
dbroada Posted May 8, 2014 Posted May 8, 2014 if I need to do this I select all the blocks I need, either individually or using QSELECT and change the visibility state in the properties palette. Quote
Bhull1985 Posted May 8, 2014 Posted May 8, 2014 In addition, you could try this routine which I just pieced together and is working pretty well on my end. User needs to know Blockname, and the dynamic parameter value they are changing to. (defun myModifyBk ( lstProp / ss index cnt oBkRef oProps i j oSBReferenceProperty) (vl-load-com) (SETQ ss (SSGET "L")) (setq index 0 cnt (sslength ss) ) (while (< index cnt) (setq e (ssname ss index)) (setq oBkRef (vlax-ename->vla-object e)) (setq oProps (vlax-variant-value (vla-GetDynamicBlockProperties oBkRef))) (setq i (vlax-safearray-get-l-bound oProps 1)) (while (<= i (vlax-safearray-get-u-bound oProps 1)) (setq oSBReferenceProperty (vlax-safearray-get-element oProps i)) (print (strcat (vla-get-PropertyName oSBReferenceProperty) "=")) (princ (vlax-variant-value (vla-get-value oSBReferenceProperty))) (setq i (1+ i)) ) (setq j 0) (while (< j (length lstProp)) (setq sProp (strcase (nth j lstProp))) (setPropValue oProps sProp (nth (+ 1 j) lstProp)) (setq j (+ 2 j)) ) ;while < j (length lstProp) (setq index (1+ index)) ) ;while < index cnt (princ) ) (defun setPropValue (oProps sProp Val / i oSBReferenceProperty sPName iFound) (setq i (vlax-safearray-get-l-bound oProps 1)) (setq iFound 0) (while (and (<= i (vlax-safearray-get-u-bound oProps 1)) (= iFound 0)) (setq oSBReferenceProperty (vlax-safearray-get-element oProps i)) (setq sPName (vla-get-PropertyName oSBReferenceProperty)) (if (= (strcase sPName) sProp) (progn (print (strcat "Old value of " sPName "=")) (princ (vlax-variant-value (vla-get-value oSBReferenceProperty))) (vla-put-value oSBReferenceProperty (vlax-make-variant Val (vlax-variant-type (vla-get-value oSBReferenceProperty)) ) ) (print "New value=") (princ (vlax-variant-value (vla-get-value oSBReferenceProperty))) (setq iFound 1) ) ) (setq i (1+ i)) ) (princ) ) ;;;;DTR converts degrees to radians. (defun dtr (a) (* pi (/ a 180.0)) ) ;;RTD converts radians to degrees. (defun rtd (a) (/ (* a 180.0) pi) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun dins ( blk / name osnapold dimsc props b1 oldec oldos pnt1 ) (vl-load-com) (setq osnapold (getvar "osmode")) (setq dimsc (getvar "dimscale")) (setq oldos (getvar "osmode")) (setvar "osmode" 0) (setq pth (vl-string-translate "/" "\\" (vl-filename-directory blk)) ext (cond ((vl-filename-extension blk)) (".dwg")) bse (vl-filename-base blk) ) (if (/= "" pth) (setq pth (strcat pth "\\")) ) (cond ( (not (or (and (tblsearch "block" bse) (setq blk bse) ) (setq blk (findfile (strcat pth bse ext))) ) ) (prompt (strcat "\nBlock \"" bse "\" not found.")) ) );cond (command "-insert" blk (setq inspt (getpoint)) dimsc "" "\\") (setq b1 (vlax-ename->vla-object (entlast))) (setq props (vlax-safearray->list (vlax-variant-value (vla-getdynamicblockproperties b1)))) (if (setq vis (getstring "Dynamic property state desired:")) (myModifyBk (list "Visibility1" Vis))) ;;;;change parameter list here based on visibility/action/etc, "vis" is variable obtained from line above (setvar "osmode" osnapold) (princ) ) HTH, let me know if any questions. Credits go to Mark Douglas and Lee Mac before me, as I just pieced together already existing routines in an effort to streamline insertion of dynamic blocks while changing their parameter values. Cheers Quote
Dorian Gray Posted May 9, 2014 Author Posted May 9, 2014 Thanks for the response guys but I’m not quite sure if that is what I'm after, Lets just say the blocks are inserted, I know the block name and I know the visibility states. But I would like the flexibility to change the visibility state of a number of dynamic blocks in 800 drawings - for example and this is only one example, the scale bar block. This block will sit in the drawings and if the powers to be want to change the scale then I have a script/lisp that will allow me to change the viewport scale and all associated information. The thing I don't have is a way to change the visibility scale of the scale bar block to match the new scale. How can i change the visibility to suit, if I have 3 dynamic blocks that have different visibility states how do I target all three in one script? Quote
3D Jack Posted March 26, 2020 Posted March 26, 2020 I know this was posted years ago but thought I would reply to it with what may be a simple solution. Using the scale block make it an attribute and in that attribute put a field. That field would be to pick the viewport and then choose the scale for the viewport. Anytime the viewport changes scale that scale will be in the attribute. The attribute may need a regen to update but a save or some other commands cause an Automatic regen. I do this on a bunch of detail sheets. I am still looking for a simple program that will change the visibility state in a block. I have the block name from lisp and the visibility state but I have spent hours looking for a program that works or I can modify and nothing. If anybody has one I would sure appreciate it. Thank you. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.