Jump to content

add if not in list


mhupp

Recommended Posts

Is their a better way to filter unique block names? 

 

  (if (setq SS (ssget '((0 . "INSERT"))))
    (progn
      (setq Path (getvar "DWGPREFIX"))
      (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
        (if (not (vl-position (setq blkname (cdr (assoc 2 (entget e)))) blklst))
          (setq blklst (cons blkname blklst))
        )
      )
      (foreach blkname blklst

 

Link to comment
Share on other sites

Not that I can think of... I think that's the most efficient. I don't know if this is better:

 

(if (setq pth (getvar 'dwgprefix) ss (ssget '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
	(if (not (vl-position (setq i (1- i) nm (cdr (assoc 2 (entget (ssname ss i))))) lst))
	    (progn
	        ;; do your thing
	        (setq lst (cons nm lst))
	    )
	)
    )
)

 

Edited by Jonathan Handojo
  • Thanks 1
Link to comment
Share on other sites

Another approach. It is not tested if the blocks are referred in the drawing, but only if they are defined!

(vlax-for el (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
 (setq $name (vla-get-name el))
 (if (/= (substr $name 1 1) "*") ;;Filter out anonymous blocks
  (setq LS_BLOCK_NAMES (cons $name LS_BLOCK_NAMES))
 ) 
)

 

  • Like 1
Link to comment
Share on other sites

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