Jump to content

Recommended Posts

Posted

I have found the attached codes to select blocks based on matching visibity state. which i have slightly modified so that it always assumes the visibility paramter is called the default "Visibility1"

 

the first and main command VSDB asks to select a block - however it still requires command line entering of the desired visibility state (variable "visstat"). which i want it to read that of the selected block.

 

the following command TDB will return the name of the blocks visibility state

 

my question is how to combine them so it is simply a matter of typing vsdb and selecting the block and done - all blocks with matching visibility state name are selected.

Visibility select.lsp

Posted

(defun c:demo (/ LM:getvisibilityparametername _curvis curvis e en ess ssvis)

 ;; 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)))
   )
 )
 (defun _curvis (_e _vn)
   (vlax-get
     (vl-some '(lambda	(l)
	  (if (eq _vn (vla-get-propertyname l))
	    l
	  )
	)
       (vlax-invoke _e 'GetDynamicBlockProperties)
     )
     'Value
   )
 )
 (if
   (and (setq e (ssget "_:S:E" '((0 . "INSERT"))))
 (setq
   en (vla-item	(vla-get-blocks
		  (vla-get-ActiveDocument (vlax-get-acad-object))
		)
		(setq effname
		       (vla-get-EffectiveName
			 (setq e (vlax-ename->vla-object (ssname e 0)))
		       )
		)
      )
 )
 (minusp (vlax-get en 'IsDynamicBlock))
 (setq visname (LM:getvisibilityparametername e))
 (setq curvis (_curvis e visname))
 (setq ssvis (ssadd)
       ssx   (ssget "X" (list (cons 2 (strcat effname ",`*U*"))))
 )
   )

    (repeat (setq i (sslength ssx))
      (if (and	(eq (vla-get-EffectiveName
	      (setq es (vlax-ename->vla-object
			 (setq ess (ssname ssx (setq i (1- i))))
		       )
	      )
	    )
	    effname
	)
	(eq (_curvis es visname) curvis)
   )
 (ssadd ess ssvis)
      )
    )
 )
 (if curvis
   (sssetfirst nil ssvis)
 )
 (princ)
)

 

Kudos to LM for this --> getvisibilityparametername

 

HTH

Posted

Awesome - that is the business! thankyou very much

  • 1 year later...
Posted

Would you mind uploading your final lisp? This is exactly what I'm looking for, but I'm not adept with lisp creation.

  • 8 years later...
Posted
On 13/12/2013 at 12:03, pBe said:

 

(defun c:demo (/ LM:getvisibilityparametername _curvis curvis e en ess ssvis)

 ;; 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)))
   )
 )
 (defun _curvis (_e _vn)
   (vlax-get
     (vl-some '(lambda	(l)
	  (if (eq _vn (vla-get-propertyname l))
	    l
	  )
	)
       (vlax-invoke _e 'GetDynamicBlockProperties)
     )
     'Value
   )
 )
 (if
   (and (setq e (ssget "_:S:E" '((0 . "INSERT"))))
 (setq
   en (vla-item	(vla-get-blocks
		  (vla-get-ActiveDocument (vlax-get-acad-object))
		)
		(setq effname
		       (vla-get-EffectiveName
			 (setq e (vlax-ename->vla-object (ssname e 0)))
		       )
		)
      )
 )
 (minusp (vlax-get en 'IsDynamicBlock))
 (setq visname (LM:getvisibilityparametername e))
 (setq curvis (_curvis e visname))
 (setq ssvis (ssadd)
       ssx   (ssget "X" (list (cons 2 (strcat effname ",`*U*"))))
 )
   )

    (repeat (setq i (sslength ssx))
      (if (and	(eq (vla-get-EffectiveName
	      (setq es (vlax-ename->vla-object
			 (setq ess (ssname ssx (setq i (1- i))))
		       )
	      )
	    )
	    effname
	)
	(eq (_curvis es visname) curvis)
   )
 (ssadd ess ssvis)
      )
    )
 )
 (if curvis
   (sssetfirst nil ssvis)
 )
 (princ)
)
 

 

 

Kudos to LM for this --> getvisibilityparametername

 

HTH

 

Hi. I am sorry to necro an almost 10 years thread. Thank you as this is working very well for the purposes! However, can the lisp be further enhanced so that the routine would works in similar way like SELECTSIMILAR? What I meant is:

 

- able to select block first before invoke command

- able to select multiple block

- able to add new block into current selection

 

Many thanks!

Posted

You need the Lee-mac dynamic properties lisp as well, should have added that also.

 

Added to post above.

 

 

Posted

Oh thanks. but I'm still not sure how to invoke this lisp. I tried to make the INSDYNE as C:INSDYNE but nothing happened. 

 

Also, looking from the code, i guess its something to do with inserting dynamic block?

Posted

Maybe I am misunderstanding what your asking for the code allows you to pick a block and pick a visibilty state v's say the current displayed state, the multi radio buttons can be set so current visibilty state is pre selected. Rather than change just use that state. 

 

Look at the pbe code again. 

Posted

I see. What pBe code do is able to select a block with similar visibility state. but it only allow to do just that. 

 

For example, if a dynamic block have 3 states, say state A, B and C. I want to count total block with state B & C to count total block quantities. pBe code cannot do that. It allow only selection of single state. I need to invoke command twice to do that. I works with hundreds of block with many visibility states so its more efficient if there is such a way.

 

 

Posted

pBe wrote the program typically based on the OP's needs and on his volunteering time and what you are after is a custom program so I can write it for you but not for free, and if you are interested then you can send a private message to move forward.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...