Dynamic Block Visibility States

Dynamic Block Visibility States

chris_lee_3
Enthusiast Enthusiast
1,468 Views
12 Replies
Message 1 of 13

Dynamic Block Visibility States

chris_lee_3
Enthusiast
Enthusiast

 

Cordial greetings all,

 

I am reluctant to ask about using a lisp to change the visibility state of a dynamic block since there are so many posts about this topic. However, I am not seeing any that do the straightforward task of changing a specific block’s visibility state. Perhaps I have stumbled across one, but I am not knowledgeable enough to recognize it.  Any help with this is appreciated.

 

The scenario I am after is to change the visibility state of block 1 from visibility state “on” to visibility state “off”.

0 Likes
Accepted solutions (1)
1,469 Views
12 Replies
Replies (12)
Message 2 of 13

_gile
Consultant
Consultant

Hi,

One way (the simplest one, IMO) is to use the setpropertyvalue function.

For dynamic properties, the syntax is:

(setpropertyvalue ename "AcDbDynBlockProperty<propertyName>" value)

Assuming the property name is: "Visibility1", you could use this:

 

(setpropertyvalue (car (entsel)) "AcDbDynBlockPropertyVisibility1" "Off")

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 13

chris_lee_3
Enthusiast
Enthusiast

Thank you, in the morning I will Jetez un coup d’œil and see if I can understand it.

0 Likes
Message 4 of 13

Sea-Haven
Mentor
Mentor

This is a dcl solution uses Multi radio buttons.lsp a library function that can be used in any code.

 

 

; Change dynamic block properties when inserting look at properties available.
; By Alan H June 2022

;; Get Dynamic Block Property Allowed Values  -  Lee Mac
;; Returns the allowed values for a specific Dynamic Block property.
;; Set Dynamic Block Visibility State  -  Lee Mac
;; Sets the Visibility Parameter of a Dynamic Block (if present) to a specific value (if allowed)
;; Get Visibility Parameter Name  -  Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)

(defun insdynv (blkname / pt obj lst ans)
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(setq pt (getpoint "\nPick a pt for block "))
(command "-insert" blkname "s" 1  pt 1  0)
(setq obj (vlax-ename->vla-object (entlast)))
(setq visval (LM:getvisibilityparametername obj))
(setq lst (LM:getdynpropallowedvalues obj visval))
(setq lst (cons "Please choose" lst))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans (ah:butts 1 "v"  lst))
(LM:SetVisibilityState obj ans)
(princ)
)

; set existing block visibilty

(defun insdyne (blkname / pt obj lst ans)
(if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(setq obj (vlax-ename->vla-object (car (entsel "\nPick a dynamic block "))))
(setq visval (LM:getvisibilityparametername obj))
(setq lst (LM:getdynpropallowedvalues obj visval))
(setq lst (cons "Please choose" lst))
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHbut)(setq AHbut 1))
(setq ans (ah:butts 1 "v"  lst))
(LM:SetVisibilityState obj ans)
(princ)
)

 

 

SeaHaven_0-1674346439535.png

 

 

Message 5 of 13

chris_lee_3
Enthusiast
Enthusiast

This worked well thank you.

Is there a way to make this work without the drafter needing to select the block? 

0 Likes
Message 6 of 13

_gile
Consultant
Consultant

This will select all blocks named "block 1" and set their "Visibility1" dynamic property to "Off".

(if (ssget "_X" '((0 . "INSERT") (2 . "block 1")))
  (repeat (setq i (sslength ss))
    (setq block (ssname ss (setq i (1- i))))
    (setpropertyvalue
      bloc
      "AcDbDynBlockPropertyVisibility1"
      "Off"
    )
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 13

Sea-Haven
Mentor
Mentor

If it is a dynamic block when inserted wont its name be like "*U23" ? You could look at say current space and use a ssget then check through the selection for "effective name" = "Block 1"

0 Likes
Message 8 of 13

chris_lee_3
Enthusiast
Enthusiast

Hey Gilles, I’m trying but I cannot get this one to work. I am pasting them into the command line and I have double check the spelling and capitalization (within the block). The first one works beautifully but second one doesn’t. Do you have a suggestion?

0 Likes
Message 9 of 13

chris_lee_3
Enthusiast
Enthusiast

Sea Haven,

That looks impressive.

But it is so over my head it makes me feel like I'm drowning.

Thank You though.    

0 Likes
Message 10 of 13

_gile
Consultant
Consultant
Accepted solution

Oops!... My mistake.

(if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "block 1,`*U*"))))
  (repeat (setq i (sslength ss))
    (setq block (ssname ss (setq i (1- i))))
    (if	(= (getpropertyvalue
	     (getpropertyvalue block "BlockTableRecord")
	     "Name"
	   )
	   "block 1"
	)
      (setpropertyvalue
	block
	"AcDbDynBlockPropertyVisibility1"
	"Off"
      )
    )
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 13

chris_lee_3
Enthusiast
Enthusiast

Perfect, thank you very much.

0 Likes
Message 12 of 13

scot-65
Advisor
Advisor

Gile,

This looks good, and it works, but will not work as a block nested inside a table cell.

Any thoughts?

I have tried fields in the cell, and that works, but would rather use the dynamic block method instead.

Scot-65

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 13 of 13

mmitchellH6TRW
Enthusiast
Enthusiast

Thank you. This could be what I am looking for.

 

0 Likes