Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Searching for dynamic blocks with visibility perimeter that is case sensitive

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
paduch_chris
1356 Views, 15 Replies

Searching for dynamic blocks with visibility perimeter that is case sensitive

This is a new thread to get a final solution instead of trolling another user's thread.

 

I've been getting help from @hmsilva who has helped create a routine to list all the dyanmic blocks in my drawing with a specific visibilty parameter name. The problem with the blocks that I'm trying to search for in my draiwng is that the visibility names are very similar with the only differences being CASE sensitivity (ie. OBJECT vs. Object). I'm very new to LISP so any help is greatly appreciated. Thanks in Advance.

 

Chris

 

(defun c:test (/ BNAME DATA E I PNAME SS VIS)
  (if (setq data nil
	    vis	 (getstring T "\nEnter the Visibility Parameter Name: ")
	    ss	 (ssget	"_X"
			(list (cons 0 "INSERT")
			      (cons 2 "`*U*")
			)
		 )
      )
    ;; setq
    (progn
      (repeat (setq i (sslength ss))
	(cond ((and (setq bname	(vla-get-EffectiveName
				  (setq	e (vlax-ename->vla-object
					    (ssname
					      ss
					      (setq i (1- i))
					    )
					  )
				  )
				)
		    )
		    (setq Pname	(car (vl-remove-if-not
				       '(lambda	(j)
					  (eq (strcase (vla-get-PropertyName j))
					      (strcase vis)
					  )
					)
				       (vlax-invoke e 'GetDynamicBlockProperties)
				     )
				)
		    )
		    (not (member bname data))
	       )
	       (setq data (cons bname data))
	       (foreach itm data (print itm))
	      )
	);; cond
      );; repeat
    );; progn
  );; if
  (if (null data) (princ "\nBlock/Parameter Name not found"))
  (princ)
)
15 REPLIES 15
Message 2 of 16
hmsilva
in reply to: paduch_chris

Chris,

 

in order to make this "demo" case sensitive, just change

(eq (strcase (vla-get-PropertyName j)) (strcase vis))

to

(eq  (vla-get-PropertyName j) vis)

 

Look at the strcase function...

 

HTH

Henrique

EESignature

Message 3 of 16
Lee_Mac
in reply to: paduch_chris

If I have understood the task correctly, I would suggest the following:

 

(defun c:test ( / bln idx lst obj par rtn sel )
    (cond
        (   (= "" (setq par (strcase (getstring t "\nEnter parameter name: ")))))
        (   (or (null (setq sel (ssget "_X" '((0 . "INSERT")))))
                (progn
                    (repeat (setq idx (sslength sel))
                        (if
                            (and
                                (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
                                (vlax-property-available-p obj 'isdynamicblock)
                                (= :vlax-true (vla-get-isdynamicblock obj))
                                (setq bln (vla-get-effectivename obj))
                                (not (member bln lst))
                            )
                            (progn
                                (if (vl-some
                                       '(lambda ( p ) (= par (strcase (vla-get-propertyname p))))
                                        (vlax-invoke obj 'getdynamicblockproperties)
                                    )
                                    (setq rtn (cons bln rtn))
                                )
                                (setq lst (cons bln lst))
                            )
                        )
                    )
                    (null rtn)
                )
            )
            (princ (strcat "\nNo dynamic blocks found with parameter \"" par "\""))
        )
        (   (foreach blk rtn (print blk)))
    )
    (princ)
)
(vl-load-com) (princ)
Message 4 of 16
pbejse
in reply to: paduch_chris


@paduch_chris wrote:

This is a new thread to get a final solution instead of trolling another user's thread.

 

@I've been getting help from @hmsilva who has helped create a routine to list all the dyanmic blocks in my drawing with a specific visibilty parameter name. The problem with the blocks that I'm trying to search for in my draiwng is that the visibility names are very similar with the only differences being CASE sensitivity (ie. OBJECT vs. Object). I'm very new to LISP so any help is greatly appreciated. Thanks in Advance.

 

Chris


Are you just after a "list" of DB's with target Visibility name? Or you need to process the blocks as well?

 

For the first option :

 

This approach searches the block table definiton rather than block entities

 

 

(defun c:DEmo  (/ blocks parname a blk Bnames dbp par)
;;; idea taken from  LMs' LM:getvisibilityparametername function      ;;;
;;	pBe Dec2013	;;;
      (setq blocks (vla-get-blocks
                         (vla-get-ActiveDocument
                               (vlax-get-acad-object))))
      (if
            (and
            (setq Bnames nil
                  parname
                       (strcase
                             (getstring
                                   t
                                   "\nEnter parameter name: ")))
            (while (setq a (tblnext "BLOCK" (null a)))
                  (setq blk (vla-item
                                  Blocks
                                  (setq bn (Cdr (assoc 2 a)))))
                  (if (and (setq dbp  (dictsearch
                                            (vlax-vla-object->ename
                                                  (vla-getextensiondictionary
                                                        blk))
                                            "ACAD_ENHANCEDBLOCK"
                                            ))
                           (setq dbp (assoc 360 dbp))
                           (= "BLOCKVISIBILITYPARAMETER"
                              (cdr (assoc 0
                                          (setq ent  (Entget
                                                           (Cdr dbp))))))
			(wcmatch
			      (Strcase
			            (setq par (cdr (assoc
			                                 301
			                                 ent))))
			      (strcase parname))
                           )
                        (setq Bnames (cons bn Bnames))
                      		Bnames));while
            )
            (foreach bnm  Bnames
                  (print bnm))
           (princ (strcat "\nNo dynamic blocks found with parameter \"" parname "\""))
            )
      (princ)
      )

 

Holler  If you need to process the blocks than just making list Chris

 

HTH

 

Message 5 of 16
Lee_Mac
in reply to: pbejse

Great idea pbejse! - and thank you for the attribution. Smiley Wink

 

The code could also be written without using ActiveX, e.g.:

 

;; Prints the names of dynamic blocks which contain a visibility parameter
;; with parameter name equal to that specified by the user.
;; Lee Mac  -  2013-12-21  -  www.lee-mac.com

(defun c:getblockswithvispar ( / def dic par rtn )
    (if (/= "" (setq par (strcase (getstring t "\nEnter parameter name: "))))
        (progn
            (while (setq def (tblnext "block" (null def)))
                (if
                    (and
                        (setq dic
                            (cdr
                                (assoc 360
                                    (entget
                                        (cdr
                                            (assoc 330
                                                (entget
                                                    (tblobjname "block"
                                                        (cdr
                                                            (assoc 2 def)
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                        (= par
                            (vl-some
                               '(lambda ( x )
                                    (if
                                        (and
                                            (= 360 (car x))
                                            (= "BLOCKVISIBILITYPARAMETER"
                                               (cdr (assoc 0 (entget (cdr x))))
                                            )
                                        )
                                        (strcase(cdr(assoc 301(entget(cdr x)))))
                                    )
                                )
                                (dictsearch dic "acad_enhancedblock")
                            )
                        )
                    )
                    (setq rtn (cons (cdr (assoc 2 def)) rtn))
                )
            )
            (if rtn
                (foreach blk rtn (print blk))
                (princ
                    (strcat
                        "\nNo dynamic blocks found with visibility parameter \""
                        par
                        "\""
                    )
                )
            )
        )
    )
    (princ)
)
Message 6 of 16
hmsilva
in reply to: Lee_Mac

@ Lee_Mac
Nicely coded, Lee! Smiley Happy

 

@pbejse
Nice approach, pBe!
don't we need to go through all dxf 360 until we find the "BLOCKVISIBILITYPARAMETER" one? Smiley Wink

 

Cheers
Henrique

EESignature

Message 7 of 16
paduch_chris
in reply to: paduch_chris

Hi All, Thanks so much for weighing in! I tried each of these solutions today and had mixed results. I'm going to reply to all in a single post so here it goes:

 

 

@HMSilva: Removing the strcase function worked in the original code, but it duplicated the listing of the blocks with the visibility parameter that I was searching. I'm wondering if it's searching for all blocks defined in the drawing including the "U" versions that occur when you adjust any dynamic block.  I tried your other version but it wasn't picking up the visability parameter. 

 

@Lee_Mac Your versions both worked but they weren't case sensitve. I tried removing the strcase function but it wasn't working for me. I'm very new to lisp so if somone could break down what exactly is going on in the code, it would be much appreciated from a learning standpoint!

 

Also, I'm trying to make it loud and clear when the block visabilities are incorrect so I was trying to add and alert function instead of foreach (print blk), but I can't get the alert to do anything but a single block at a time. Instead of foreach, what should the function be? And if I don't want it to be a getstring with user input but a preset visability parameter, how do I do that? Thanks again all. 

 

Chris

Message 8 of 16
hmsilva
in reply to: paduch_chris


@paduch_chris wrote:

..

 

@hmsilva: Removing the strcase function worked in the original code, but it duplicated the listing of the blocks with the visibility parameter that I was searching. I'm wondering if it's searching for all blocks defined in the drawing including the "U" versions that occur when you adjust any dynamic block.  I tried your other version but it wasn't picking up the visability parameter. 

 

..


Chris,

 

the code at the #1 post (made from a pbejse code ), shouldn't duplicate the blocks "EffectiveName" and I can't reproduce that behavior, if possible, attach a sample dwg with some blocks to be able to test...

 

"...I tried your other version..."

 

The other version, was not posted by me, it's from pbejse, is a very well designed code, just need a small adjustment, and I am sure that pbejse will do that.

 

Henrique

EESignature

Message 9 of 16
Lee_Mac
in reply to: paduch_chris


@hmsilva wrote:

@ Lee_Mac
Nicely coded, Lee! Smiley Happy


Thank you Henrique! Smiley Happy


@paduch_chris wrote:

@Lee_Mac Your versions both worked but they weren't case sensitve. I tried removing the strcase function but it wasn't working for me. I'm very new to lisp so if somone could break down what exactly is going on in the code, it would be much appreciated from a learning standpoint!

 

Also, I'm trying to make it loud and clear when the block visabilities are incorrect so I was trying to add and alert function instead of foreach (print blk), but I can't get the alert to do anything but a single block at a time. Instead of foreach, what should the function be? And if I don't want it to be a getstring with user input but a preset visability parameter, how do I do that? Thanks again all. 


Sorry Chris, since most programs of this nature are usually written to be case-insensitive, I had overlooked the fact that you wanted the Visibility Parameter to exactly match the string entered by the user.

 

Please try the following code instead:

 

;; Prints the names of dynamic blocks which contain a visibility parameter
;; with parameter name equal to that specified by the user.
;; Lee Mac  -  2013-12-21  -  www.lee-mac.com

(defun c:getblockswithvispar ( / def dic par rtn )
    (if (/= "" (setq par (getstring t "\nEnter parameter name: ")))
        (progn
            (while (setq def (tblnext "block" (null def)))
                (if
                    (and
                        (setq dic
                            (cdr
                                (assoc 360
                                    (entget
                                        (cdr
                                            (assoc 330
                                                (entget
                                                    (tblobjname "block"
                                                        (cdr
                                                            (assoc 2 def)
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                        (= par
                            (vl-some
                               '(lambda ( x )
                                    (if
                                        (and
                                            (= 360 (car x))
                                            (= "BLOCKVISIBILITYPARAMETER"
                                               (cdr (assoc 0 (entget (cdr x))))
                                            )
                                        )
                                        (cdr (assoc 301 (entget (cdr x))))
                                    )
                                )
                                (dictsearch dic "acad_enhancedblock")
                            )
                        )
                    )
                    (setq rtn (vl-list* "\n" (cdr (assoc 2 def)) rtn))
                )
            )
            (if rtn
                (alert
                    (apply 'strcat
                        (cons "The following blocks were found:\n" rtn)
                    )
                )
                (princ
                    (strcat
                        "\nNo dynamic blocks found with visibility parameter \""
                        par
                        "\""
                    )
                )
            )
        )
    )
    (princ)
)
Message 10 of 16
Lineabove
in reply to: Lee_Mac

Lee Mac,

 

Any chance this could be revised to Prompt for which parameter you wish to search for rather than only the BLOCKVISIBILITYPARAMETER ?

 

 

Message 11 of 16
hmsilva
in reply to: Lee_Mac

Lee_Mac wrote:

 

(setq rtn (vl-list* "\n" (cdr (assoc 2 def)) rtn))

 

Nice one, Lee! Smiley Happy

 

Henrique

EESignature

Message 12 of 16
bhull1985
in reply to: hmsilva


@hmsilva wrote:

@Lee_Mac wrote:

 

(setq rtn (vl-list* "\n" (cdr (assoc 2 def)) rtn))

 

Nice one, Lee! Smiley Happy

 

Henrique


Hello all,

what does that bit of code accomplish, i was intrigued but this is over my head---

still curious!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 13 of 16
hmsilva
in reply to: bhull1985

Hi Brandon,

with

(setq rtn (vl-list* "\n" (cdr (assoc 2 def)) rtn))

using the vl-list* function, Lee built the rtn list without having to use twice the cons function...

(setq rtn (cons "\n" (cons (cdr (assoc 2 def)) rtn)))

 

HTH

Henrique

 

 

EESignature

Message 14 of 16
Lee_Mac
in reply to: hmsilva


@hmsilva wrote:

@Lee_Mac wrote:

 

(setq rtn (vl-list* "\n" (cdr (assoc 2 def)) rtn))

 

Nice one, Lee! Smiley Happy

 

Henrique


Thank you Henrique! Smiley Happy

 


@Anonymous wrote:

Lee Mac,

 

Any chance this could be revised to Prompt for which parameter you wish to search for rather than only the BLOCKVISIBILITYPARAMETER ?


 

I have a few more ideas for this program - I'll look to work on it when I have some more time Smiley Wink

Message 15 of 16
paduch_chris
in reply to: Lee_Mac

This is perfect! Thanks so much! 🙂

Chris
Message 16 of 16
Lee_Mac
in reply to: paduch_chris


@paduch_chris wrote:
This is perfect! Thanks so much! 🙂

Chris

You're welcome Chris! Smiley Happy

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost