Jump to content

Get INSERT names for ssget function


ziele_o2k

Recommended Posts

My goal is function that will return list with names of blocks for ssget function:

Example:

"block1,block2,xref1,xref2,dynblock1,*A1dynblock1,*A2dynblock1"

Could someone verify my lisp routine?

Main function:

;bit
;0 - all
;1 - without "blocks"
;2 - without dynamic blocks
;4 - without xrefs
;(PZ:GetInsertNames (ssget '((0 . "INSERT"))) (+ 2 4))
(defun PZ:GetInsertNames ( ss bit / sl enl res)
 ;remove objs from ss that are not insert - just in case 
 (setq 
   sl
   (vl-remove-if-not 
     '(lambda (_1)
       (eq (cdr (assoc 0 (entget (vlax-vla-object->ename _1)))) "INSERT")
     )
     (cd:SSX_Convert ss 1)
   )
 )
 ;remove blocks
 (if (= 1 (logand bit 1))
   (setq 
     sl
     (vl-remove-if
       '(lambda (_1)
         (and 
           (= (vlax-property-available-p _1 'Path) nil)
           (= (vlax-get-property _1 'IsDynamicBlock) :vlax-false)
         )
       )
       sl
     )
   )
 )
 ;remove dynamic blocks
 (if (= 2 (logand bit 2))
   (setq 
     sl
     (vl-remove-if
       '(lambda (_1)
         (= (vla-get-IsDynamicBlock _1) :vlax-true)
       )
       sl
     )
   )
 )
 ;remove xrefs
 (if (= 4 (logand bit 4))
   (setq 
     sl
     (vl-remove-if
       '(lambda (_1)
         (= (vlax-property-available-p _1 'Path) T)
       )
       sl
     )
   )
 )
 (setq sl (mapcar 'vlax-vla-object->ename sl))
 (setq enl (mapcar 'LM:al-effectivename sl))
 (if (= 0 (logand bit 2))
   (foreach _n sl
     (if (= (vla-get-IsDynamicBlock (vlax-ename->vla-object _n)) :vlax-true)
       (setq enl(LM:ListUnion (cd:BLK_GetDynBlockNames (LM:al-effectivename _n)) enl))
     )
   )
 )
 (setq res (cd:STR_ReParse (LM:Unique enl)","))
 res
)

Subroutines

(defun LM:al-effectivename ( ent / blk rep )
   (if (wcmatch (setq blk (cdr (assoc 2 (entget ent)))) "`**")
       (if
           (and
               (setq rep
                   (cdadr
                       (assoc -3
                           (entget
                               (cdr
                                   (assoc 330
                                       (entget
                                           (tblobjname "block" blk)
                                       )
                                   )
                               )
                              '("AcDbBlockRepBTag")
                           )
                       )
                   )
               )
               (setq rep (handent (cdr (assoc 1005 rep))))
           )
           (setq blk (cdr (assoc 2 (entget rep))))
       )
   )
   blk
)
; =========================================================================================== ;
; Lista nazw blokow (*U) zaleznych od bloku dynamicznego /                                    ;
; List of the blocks name (*U) which depends on a dynamic block                               ;
;  Name [sTR] - nazwa bloku / block name                                                      ;
; ------------------------------------------------------------------------------------------- ;
; (cd:BLK_GetDynBlockNames "NazwaBloku")                                                      ;
; =========================================================================================== ;
(defun cd:BLK_GetDynBlockNames (Name / res n xd)
 (setq res (list Name))
 (vlax-for % (cd:ACX_Blocks)
   (if (wcmatch (setq n (vla-get-name %)) "`*U*")
     (if
       (setq xd
         (cd:XDT_GetXData
           (vlax-vla-object->ename %)
           "AcDbBlockRepBTag"
         )
       )
       (if
         (=
           (strcase Name)
           (strcase
             (cdr
               (assoc 2
                 (entget
                   (handent
                     (cdr (assoc 1005 (cdr xd)))
                   )
                 )
               )
             )
           )
         )
         (setq res (cons n res))
       )
     )
   )
 )
 (reverse res)
)
; =========================================================================================== ;
; Lista odnosnikow zewnetrznych / List of external references                                 ;
; =========================================================================================== ;
(defun cd:BLK_GetXrefs (/ res)
 (vlax-for % (cd:ACX_Blocks)
   (if (= (vla-get-IsXref %) :vlax-true)
     (setq res (cons (vla-get-name %) res))
   )
 )
 res
)
; =========================================================================================== ;
; Czyta dane dodatkowe XDATA / Reads additional data XDATA                                    ;
;  Ename [ENAME]   - nazwa entycji / entity name                                              ;
;  App   [sTR/nil] - nil = dla wszystkich aplikacji / for all applications                    ;
;                    STR = dla aplikacji App / for App application                            ;
; ------------------------------------------------------------------------------------------- ;
; (cd:XDT_GetXData (car (entsel)) "CADPL")                                                    ;
; =========================================================================================== ;
(defun cd:XDT_GetXData (Ename App)
 (if App
   (cadr (assoc -3 (entget Ename (list App))))
   (cdr (assoc -3 (entget Ename (list "*"))))
 )
)
;;---------------------=={ List Union }==---------------------;;
;;                                                            ;;
;;  Returns a list expressing the union of two lists          ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  l1,l2 - Lists for which to return the union               ;;
;;------------------------------------------------------------;;
;;  Returns:  A list of all distinct items in the two lists   ;;
;;------------------------------------------------------------;;
;_$ (LM:ListUnion '(1 2 3 4 5) '(2 4 6 )
;(1 2 3 4 5 6 
(defun LM:ListUnion ( l1 l2 / x l )
 (setq l1 (append l1 l2))
 (while (setq x (car l1)) (setq l (cons x l) l1 (vl-remove x l1)))
 (reverse l)
)
; =========================================================================================== ;
; Zmienia PICKSET na liste obiektow / Convert PICKSET to list of objects                      ;
;  Ss   [PICKSET] - zbior wskazan / selection sets                                            ;
;  Mode [iNT]     - typ zwracanych obiektow / type of returned objects                        ;
;                   0 = ENAME, 1 = VLA-OBJECT, 2 = SAFEARRAY                                  ;
; ------------------------------------------------------------------------------------------- ;
; (cd:SSX_Convert (ssget) 1)                                                                  ;
; =========================================================================================== ;
(defun cd:SSX_Convert (Ss Mode / n res)
 (if
   (and
     (member Mode (list 0 1 2))
     (not
       (minusp
         (setq n
           (if Ss (1- (sslength Ss)) -1)
         )
       )
     )
   )
   (progn
     (while (>= n 0)
       (setq res
         (cons
           (if (zerop Mode)
             (ssname Ss n)
             (vlax-ename->vla-object (ssname Ss n))
           )
           res
         )
             n (1- n)
       )
     )
     (if (= Mode 2)
       (vlax-safearray-fill
         (vlax-make-safearray 9
           (cons 0 (1- (length res)))
         ) res
       )
       res
     )
   )
 )
)
; =========================================================================================== ;
; Laczy liste lancuchow w lancuch z separatorem /                                             ;
; Combines a list of strings in the string with the separator                                 ;
;  Lst [list] - lista lancuchow / list of strings                                             ;
;  Sep [sTR]  - separator / separator                                                         ;
; ------------------------------------------------------------------------------------------- ;
; (cd:STR_ReParse '("OLE2FRAME" "IMAGE" "HATCH") ",")                                         ;
; =========================================================================================== ;
(defun cd:STR_ReParse (Lst Sep / res)
 (setq res (car Lst))
 (foreach % (cdr Lst)
   (setq res (strcat res Sep %))
 )
 res
)
;; Unique  -  Lee Mac
;; Returns a list with duplicate elements removed.
;; (LM:Unique '("A" "B" "B" "B" "C" "C" "D" "E" "E" "E" "E"))
;;  =>  ("A" "B" "C" "D" "E")
(defun LM:Unique ( l / x r )
   (while l
       (setq x (car l)
             l (vl-remove x (cdr l))
             r (cons x r)
       )
   )
   (reverse r)
)

Edited by ziele_o2k
Added LM:Unique subrutine in subroutines code
Link to comment
Share on other sites

?? Try this

 

(setq lst (list "block1,block2,xref1,xref2,dynblock1,*A1dynblock1,*A2dynblock1"))
(setq ss (ssget '((0 . "INSERT")(cons 2 lst)) ))

Link to comment
Share on other sites

?? Try this

 

(setq lst (list "block1,block2,xref1,xref2,dynblock1,*A1dynblock1,*A2dynblock1"))
(setq ss (ssget '((0 . "INSERT")(cons 2 lst)) ))

Before your post i added ` to escape wildcard * for ssget, but why you whant mu to try with lst?

Result of my function is string:

"block1,block2,xref1,xref2,dynblock1,`*A1dynblock1,`*A2dynblock1"

 

 

 

EDIT.

I know why :) in first post i wrote list, but I should write string :)

Anyway, string is result of my function :D

Link to comment
Share on other sites

Are you looking to achieve something like this?

 

This is part of my goal :) if you will look at my subroutines, you will find this functions :)

My goal are names of simple blocks / dynamic blocks with anonymous references / xref inserts.

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