Nested dynamic block

Nested dynamic block

frankrains
Contributor Contributor
626 Views
6 Replies
Message 1 of 7

Nested dynamic block

frankrains
Contributor
Contributor

Hi Everyone,

I have a nested block within another block. The nested block is a dynamic block. I want to edit the visibility state of the nested block. I know that I can do it by going to BEDIT, selecting the nested block and changing the visibility state there. BUT, I want to do this purely through visual lisp. Does anyone have an application that will select and return the entity/object of a nested (dynamic) block?

Final result: When the nested block visibility state is changed, it will update the look of all of the parent blocks in the drawing. I can't seem to figure out how to change the visibility state through visual lisp.

Any help is appreciated!

0 Likes
Accepted solutions (2)
627 Views
6 Replies
Replies (6)
Message 2 of 7

_gile
Consultant
Consultant
Accepted solution

Hi,

Here's a little routine you can start from.

;;; EditNestedDynBlock
;;; Edits a dynamic property of an dynamic nested block.
;;; Returns T, if succeeded; nil, otherwise.
;;;
;;; Arguments
;;; parentName:    Name of the parent block.
;;; nestedName:    Name of the nested block.
;;; propertyName:  Name of the dynamic property to edit.
;;; propertyValue: New value of the dynamic property.

(defun EditNestedDynBlock (parentName nestedName propertyName propertyValue / parent ent nested)
  (if (setq parent (tblsearch "block" parentName))
    (progn
      (setq ent (cdr (assoc -2 parent)))
      (while ent
	(if
	  (and
	    (= (cdr (assoc 0 (entget ent))) "INSERT")
	    (not (wcmatch (getpropertyvalue ent "ClassName")
			  "AcDbAssociative*Array"
		 )
	    )
	    (= (strcase nestedName)
	       (strcase (getpropertyvalue ent "BlockTableRecord/Name"))
	    )
	  )
	   (setq nested	ent
		 ent nil
	   )
	   (setq ent (entnext ent))
	)
      )
      (if nested
	(not
	  (vl-catch-all-error-p
	    (vl-catch-all-apply
	      '(lambda ()
		 (setpropertyvalue
		   nested
		   (strcat "AcDbDynBlockProperty" propertyName)
		   propertyValue
		 )
		 (command-s "_regen")
	       )
	    )
	  )
	)
      )
    )
  )
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 7

paullimapa
Mentor
Mentor

Have you tried this to just change the main blocks visibility https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/changing-visibility-states-in-dynami...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 7

frankrains
Contributor
Contributor

Gilles,

Thanks a million. This does exactly what I wanted it to do.

MUCH appreciated!

Frank

0 Likes
Message 5 of 7

frankrains
Contributor
Contributor

Thank you for the reply. The reason that I am using a nested dynamic block is two fold.

1) I don't want the parent block name to become an anonymous name when a property changes.

2). I will have several different parent blocks with different names that will have the nested dynamic block. Each parent block with have linework and attributes that are specific to eachother, but will use the same "base" geometry set in the dynamic block.

0 Likes
Message 6 of 7

_gile
Consultant
Consultant
Accepted solution

The same thing as upper using 'Visual LISP' (COM/ActiveX).

;;; EditNesteddynBlock
;;; Edits a dynamic property of an dynamic nested block.
;;; Returns T, if succeeded; nil, otherwise.
;;;
;;; Arguments
;;; parentName:    Name of the parent block.
;;; nestedName:    Name of the nested block.
;;; propertyName:  Name of the dynamic property to edit.
;;; propertyValue: New value of the dynamic property.

(defun EditNesteddynBlock (parentName nestedName propertyName propertyValue / doc parent obj nested property)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if (setq parent (vla-item (vla-get-Blocks doc) parentName))
    (progn
      (vlax-for	obj parent
	(if
	  (and
	    (= (vla-get-ObjectName obj) "AcDbBlockReference")
	    (= (strcase nestedName)
	       (strcase (vla-get-EffectiveName obj))
	    )
	  )
	   (setq nested obj)
	)
      )
      (if nested
	(progn
	  (foreach p (vlax-invoke nested 'GetDynamicBlockProperties)
	    (if	(= (vla-get-PropertyName p) propertyName)
	      (setq property p)
	    )
	  )
	  (if property
	    (not
	      (vl-catch-all-error-p
		(vl-catch-all-apply
		  '(lambda ()
		     (vla-put-Value property propertyValue)
		     (vla-Regen doc acActiveViewport)
		   )
		)
	      )
	    )
	  )
	)
      )
    )
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 7

frankrains
Contributor
Contributor

This is extremely helpful.

Thank you so much for your help.

Frank

 

0 Likes