; PFA ; OP: ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/insert-dynamic-block-and-then-select-visibility-before-inserting/m-p/13101861#M473432 (defun c:PFA (/ get_dyn_property_by_name set_dyn_property blockName layerName blockDef ent visState) ; localize variables (vl-load-com) ; add the following two sub functions ; by komondormrex ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/swap-the-visibility-state-in-a-block-using-lisp/m-p/12786544/highlight/true#M466339 (defun get_dyn_property_by_name (dyn_property_name insert_object / dyn_property_found) (if (vl-some '(lambda (dyn_property) (= dyn_property_name (vla-get-propertyname (setq dyn_property_found dyn_property)))) (vlax-invoke insert_object 'getdynamicblockproperties) ) dyn_property_found nil ) ) ; modified version: (defun set_dyn_property (dyn_property_name value obj / stamp_property) (if (setq stamp_property (get_dyn_property_by_name dyn_property_name obj)) (vla-put-value stamp_property value) ) ) ; ; main function ; (setq blockName "_AVSF-UTL PAGEFLAG") (setq layerName "_AVSF-LN AUDIO") ;; Ensure the layer exists, if not, create it (if (not (tblsearch "layer" layerName)) (command "._LAYER" "M" layerName "C" "7" "" "") ) ;; Set the current layer to the desired layer (setvar "CLAYER" layerName) ;; Get the block definition (setq blockDef (tblsearch "block" blockName)) (if blockDef (progn ;; Insert block with drag functionality (command "._-INSERT" blockName pause "1" "1" "0") (princ "\nBlock inserted successfully.") ;; Select the inserted block (setq ent (entlast)) ;; Change the visibility state (if ent (progn ;; Prompt user for visibility state ; (initget "TO PAGE FROM PAGE") ; (setq visState (getkword "\nEnter visibility state [TO PAGE/FROM PAGE]: ")) (initget "TO-PAGE FROM-PAGE") ; use hyphen to preserve each choice as a single item - note underscore not supported (setq visState (getkword "\nEnter visibility state [TO-PAGE/FROM-PAGE]: ")) ; add this (if (equal visState "TO-PAGE") (setq visState "TO PAGE")(setq visState "FROM PAGE")) ; force to set to a correct vis state name ; ;; Set the visibility state (if (or (equal visState "TO PAGE") (equal visState "FROM PAGE")) (progn ;(vla-put-EffectiveName (vlax-ename->vla-object ent) visState) (set_dyn_property "Visibility1" visState (vlax-ename->vla-object ent)) ; set to the Visibility1 paramenter (princ (strcat "\nVisibility state set to " visState ".")) ) (princ "\nInvalid visibility state.") ) ) (princ "\nFailed to set visibility state.") ) ) (princ "\nBlock definition not found.") ) ;; Ensure the layer exists, if not, create it (if (not (tblsearch "layer" "DEFPOINTS")) (command "._LAYER" "M" "DEFPOINTS" "C" "7" "" "") ) ;; Reset the current layer to DEFPOINTS (setvar "CLAYER" "DEFPOINTS") (princ "\nCurrent layer reset to DEFPOINTS.") (princ) ) (princ "\nType PFA to run the command.")(princ) ; add princ at end to prevent double echo