Jump to content

Recommended Posts

Posted

Hello,

If some one can help me please, i have this block in autocad with different Visibility, and i have a lot of them on a draw. What i want is to select all block but with a specify visibility state, so i can count them. I tried some LISP code from internet but no succes so far, and i'm 0 with coding.

Untitled.jpg

Posted (edited)

If you just want to get a certain part of visibility states, here you have it:

 

(defun c:selvis ( / ss)
    (if (null (vl-catch-all-error-p (setq ss (vl-catch-all-apply 'selvis))))
	(sssetfirst nil ss)
	)
    (princ)
    )

(defun selvis ( / ent i props ss vscase your_visibility)	; <--- Returns the selection set with the desired visibility states
    (setq your_visibility
	     (mapcar
		 'strcase
		 '(	; Put list of visibility values below.
		   
		   "Enter list of visibility states here"
		   
		   ; Put list of visibility values above.
		   )
		 )
	  ss (ssget '((0 . "INSERT")))
	  )
    (repeat (setq i (sslength ss))
	(if
	    (or
		(eq (vla-get-IsDynamicBlock (vlax-ename->vla-object (setq ent (ssname ss (setq i (1- i)))))) :vlax-false)
		(and
		    (setq props
			     (vl-remove-if-not
				 '(lambda (x)
				      (wcmatch (strcase (vla-get-PropertyName x)) "VISIBILITY*")
				      )
				 (vlax-invoke (vlax-ename->vla-object ent) 'GetDynamicBlockProperties)
				 )
			  )
		    (vl-some
			'(lambda (x)
			     (if (null (vl-position (strcase (vlax-get x 'Value)) your_visibility))
				 (ssdel ent ss)
				 )
			     )
			props
			)
		    )
		)
	    (ssdel ent ss)
	    )
	)
    ss
    )

 

Otherwise, the link provided by Lee will be enough to count all your blocks.

 

If you don't want to mess the values in the counting routine, check my Block Overkill program to remove possible duplicates of blocks.

Edited by Jonathan Handojo
Posted

Thanks Lee Mac, that was helpful. Also where i can try to learn how to code in LISP, is any software that can help you to learn this type of language ?

Posted (edited)

@Jonathan Handojo Be aware that you cannot rely on the Dynamic Block Visibility Parameter being named "Visibility...", it can have an arbitrary property name, just as an attribute can have an arbitrary tag name (within the naming limitations).

 

@Sinucigasu I would suggest starting with the following resources:

 

Edited by Lee Mac
  • Like 1
Posted

@Lee Mac Hmm... You're right. I've never actually need to rename visibility states, so I thought that was the case. I'll have to revise that code

Posted

Have a look on Kindle for books very cheap and nice thing is can copy code from book.

 

  • 3 years later...
Posted
On 4/22/2020 at 3:29 PM, Jonathan Handojo said:

Hello, I was wondering if we can have an update to the dynamic counter block lisp. I'm am okish with programing, but can't exactly understand the behind of lisp code. I've tried different scenarios to change the code so that the total number of each block that have the same visibility state name can be summed, but can't figure out how. I've tried to memorize the final number onto a variable that can be summed in the end but with no success.
So what i want is if it can be possible to show me the sum of all blocks that have the same visibility name 
image.png.989d03994f15e6b7e58f1a9067b63c2e.png So in the end will show me 7 of "Ok" and 11 of "renuntat". Thanks a lot if someone could help!

Posted (edited)
6 hours ago, Midnight88 said:

Hello, I was wondering if we can have an update to the dynamic counter block lisp. I'm am okish with programing, but can't exactly understand the behind of lisp code. I've tried different scenarios to change the code so that the total number of each block that have the same visibility state name can be summed, but can't figure out how. I've tried to memorize the final number onto a variable that can be summed in the end but with no success.
So what i want is if it can be possible to show me the sum of all blocks that have the same visibility name 
image.png.989d03994f15e6b7e58f1a9067b63c2e.png So in the end will show me 7 of "Ok" and 11 of "renuntat". Thanks a lot if someone could help!

 

Hi, I have this in my library... It select blocks by visibility states... So, you have to select blocks and input visibility state you wish through dialog box and new selection will be created...

Then you can do (if (ssget "_I") (sslength (ssget "_I")) 0) to count blocks...

 

(defun selvis ( / ent i props ss your_visibility )
                                        ; <--- Returns the selection set with the desired visibility states

  (defun getvisstates ( ss / unique LM:getvisibilitystatesnames i blk lst )

    (defun unique ( lst )
      (if lst (cons (car lst) (unique (vl-remove-if '(lambda ( x ) (or (= (strcase x) (car lst)) (= x (car lst)))) (cdr lst)))))
    )

    ;; Get Visibility States Names  -  Lee Mac
    ;; Returns the names of the Visibility States of a Dynamic Block (if present)
    ;; blk - [vla] VLA Dynamic Block Reference object
    ;; Returns: [str] Names of Visibility States, else nil
     
    (defun LM:getvisibilitystatesnames ( 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)) to account for NUS dynamic blocks
          (= :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)))
        (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 303)) (entget vis)))
      )
    )

    (if ss
      (repeat (setq i (sslength ss))
        (setq blk (ssname ss (setq i (1- i))))
        (if (= (vla-get-isdynamicblock (vlax-ename->vla-object blk)) :vlax-true)
          (setq lst (append lst (LM:getvisibilitystatesnames (vlax-ename->vla-object blk))))
        )
      )
    )
    (unique (reverse lst))
  )

  (defun AT:ListSelect ( title label height width multi lst / fn fo d item f )
    ;; List Select Dialog (Temp DCL list box selection, based on provided list)
    ;; title - list box title
    ;; label - label for list box
    ;; height - height of box
    ;; width - width of box
    ;; multi - selection method ["true": multiple, "false": single]
    ;; lst - list of strings to place in list box
    ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
    (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
    (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                     (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                     (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                     (strcat "width = " (vl-princ-to-string width) ";")
                     (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
               )
      (write-line x fo)
    )
    (close fo)
    (new_dialog "list_select" (setq d (load_dialog fn)))
    (start_list "lst")
    (mapcar (function add_list) lst)
    (end_list)
    ;;;(setq item (set_tile "lst" "0"))
    (action_tile "lst" "(setq item $value)")
    (setq f (start_dialog))
    (unload_dialog d)
    (vl-file-delete fn)
    (if (= f 1)
      (mapcar '(lambda ( n ) (nth n lst)) (read (strcat "(" item ")")))
    )
  )

  (setq ss (ssget '((0 . "INSERT")))
    your_visibility
    (mapcar
      'strcase
      (AT:ListSelect "CHOOSE VISIBILITY STATES YOU WANT TO HIGHLIGHT" "VISIBILITY STATES" 40 30 "true" (getvisstates ss))
    )
  )
  (repeat (setq i (sslength ss))
    (if
      (or
        (eq (vla-get-IsDynamicBlock
              (vlax-ename->vla-object
                (setq ent (ssname ss (setq i (1- i))))
              )
            )
            :vlax-false
        )
        (and
          (setq props
                 (vl-remove-if-not
                   '(lambda ( x )
                      (wcmatch (strcase (vla-get-PropertyName x))
                               "VISIBILITY*"
                      )
                    )
                   (vlax-invoke
                     (vlax-ename->vla-object ent)
                     'GetDynamicBlockProperties
                   )
                 )
          )
          (vl-some
            '(lambda ( x )
               (if (null (vl-position
                           (strcase (vlax-get x 'Value))
                           your_visibility
                         )
                   )
                 (ssdel ent ss)
               )
             )
            props
          )
        )
      )
       (ssdel ent ss)
    )
  )
  ss
)

(defun c:selvis ( / ss )
  (if (null (vl-catch-all-error-p
              (setq ss (vl-catch-all-apply 'selvis))
            )
      )
    (sssetfirst nil ss)
  )
  (princ)
)

 

HTH.

M.R.

Edited by marko_ribar
  • Like 1
Posted (edited)

Like Ribarm you get all your blocks and retrieve Block name and current visibilty state putting result into a list, then do a count on the 2 items block name and visibility state. 

 

((blk1 Vis1)(blk1 vis2)(blk1 vis1) ............

Count list based on 2 items

((blk1 vis1 22)(blk1 vis2 12)...............

 

I have something but its part of another code solution will see if can put something together. I think got count part from PBE.

Edited by BIGAL
Posted
On 6/16/2023 at 9:22 PM, marko_ribar said:

 

Hi, I have this in my library... It select blocks by visibility states... So, you have to select blocks and input visibility state you wish through dialog box and new selection will be created...

Then you can do (if (ssget "_I") (sslength (ssget "_I")) 0) to count blocks...

 

(defun selvis ( / ent i props ss your_visibility )
                                        ; <--- Returns the selection set with the desired visibility states

  (defun getvisstates ( ss / unique LM:getvisibilitystatesnames i blk lst )

    (defun unique ( lst )
      (if lst (cons (car lst) (unique (vl-remove-if '(lambda ( x ) (or (= (strcase x) (car lst)) (= x (car lst)))) (cdr lst)))))
    )

    ;; Get Visibility States Names  -  Lee Mac
    ;; Returns the names of the Visibility States of a Dynamic Block (if present)
    ;; blk - [vla] VLA Dynamic Block Reference object
    ;; Returns: [str] Names of Visibility States, else nil
     
    (defun LM:getvisibilitystatesnames ( 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)) to account for NUS dynamic blocks
          (= :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)))
        (mapcar 'cdr (vl-remove-if '(lambda ( x ) (/= (car x) 303)) (entget vis)))
      )
    )

    (if ss
      (repeat (setq i (sslength ss))
        (setq blk (ssname ss (setq i (1- i))))
        (if (= (vla-get-isdynamicblock (vlax-ename->vla-object blk)) :vlax-true)
          (setq lst (append lst (LM:getvisibilitystatesnames (vlax-ename->vla-object blk))))
        )
      )
    )
    (unique (reverse lst))
  )

  (defun AT:ListSelect ( title label height width multi lst / fn fo d item f )
    ;; List Select Dialog (Temp DCL list box selection, based on provided list)
    ;; title - list box title
    ;; label - label for list box
    ;; height - height of box
    ;; width - width of box
    ;; multi - selection method ["true": multiple, "false": single]
    ;; lst - list of strings to place in list box
    ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
    (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
    (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                     (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                     (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                     (strcat "width = " (vl-princ-to-string width) ";")
                     (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
               )
      (write-line x fo)
    )
    (close fo)
    (new_dialog "list_select" (setq d (load_dialog fn)))
    (start_list "lst")
    (mapcar (function add_list) lst)
    (end_list)
    ;;;(setq item (set_tile "lst" "0"))
    (action_tile "lst" "(setq item $value)")
    (setq f (start_dialog))
    (unload_dialog d)
    (vl-file-delete fn)
    (if (= f 1)
      (mapcar '(lambda ( n ) (nth n lst)) (read (strcat "(" item ")")))
    )
  )

  (setq ss (ssget '((0 . "INSERT")))
    your_visibility
    (mapcar
      'strcase
      (AT:ListSelect "CHOOSE VISIBILITY STATES YOU WANT TO HIGHLIGHT" "VISIBILITY STATES" 40 30 "true" (getvisstates ss))
    )
  )
  (repeat (setq i (sslength ss))
    (if
      (or
        (eq (vla-get-IsDynamicBlock
              (vlax-ename->vla-object
                (setq ent (ssname ss (setq i (1- i))))
              )
            )
            :vlax-false
        )
        (and
          (setq props
                 (vl-remove-if-not
                   '(lambda ( x )
                      (wcmatch (strcase (vla-get-PropertyName x))
                               "VISIBILITY*"
                      )
                    )
                   (vlax-invoke
                     (vlax-ename->vla-object ent)
                     'GetDynamicBlockProperties
                   )
                 )
          )
          (vl-some
            '(lambda ( x )
               (if (null (vl-position
                           (strcase (vlax-get x 'Value))
                           your_visibility
                         )
                   )
                 (ssdel ent ss)
               )
             )
            props
          )
        )
      )
       (ssdel ent ss)
    )
  )
  ss
)

(defun c:selvis ( / ss )
  (if (null (vl-catch-all-error-p
              (setq ss (vl-catch-all-apply 'selvis))
            )
      )
    (sssetfirst nil ss)
  )
  (princ)
)

 

HTH.

M.R.

It worked verry well. Thank you a lot!

image.thumb.png.7185565361bd8ab3ef47dd864cc0f2b0.png

  • 1 year later...
Posted

I thought a part of this might be the solution to my problem, but this does not see attributes that are nested/wblocks; within the inserted block.

My existing routine reads the blocks and created a simple text file listing the nested atribute names for each inserted block.

However does but does not diferentiate between visible and invisible.

I need it to only see the visible nested blocks.

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...