LISP - ACADE Loop Explode All Blocks unless Electrical Symbol

LISP - ACADE Loop Explode All Blocks unless Electrical Symbol

david.faunce
Enthusiast Enthusiast
1,505 Views
5 Replies
Message 1 of 6

LISP - ACADE Loop Explode All Blocks unless Electrical Symbol

david.faunce
Enthusiast
Enthusiast

I have the following function that's a work in progress...

It is supposed to loop through a drawing and gather all "INSERT" type objects. If the TYPE is a an Electrical Symbol,  it moves on - if the object is NOT a symbol it explodes the block. The loop repeats for nested blocks and symbols. 

 

 

Ultimately I want the code to explode all blocks (including nested blocks) but leave all electrical symbols alone. What am i doing wrong?

 

(defun m:explodeAllButSymbols (/ a )
(setvar "qaflags" 1)

;Get the list of blocks in the drawing
(setq a (ssget "X" (list (cons 0 "INSERT"))))

;while the list is not null
 (while (/= a nil)
(progn ;if the object type is NOT "SYM" or a Symbol then explode it if (!= (type a) "SYM" (command "_.explode" a "") )

;next (setq a (ssget "X" (list (cons 0 "INSERT"))))
);end progn );end while
(setvar "qaflags" 0) (princ)
);end

 

0 Likes
Accepted solutions (1)
1,506 Views
5 Replies
Replies (5)
Message 2 of 6

CodeDing
Advisor
Advisor

@david.faunce ,

 

The type of "Symbol" you are trying to retrieve is not exactly how you are perceiving it to be...

In programming, a "Symbol" is a "primitive data type whose instances have a unique human-readable form".

- in your instance, the "symbol" you have chosen for your selection set is "a".

- this may become more evident when we paste the following into our command line:

 

(progn
(setq x 1.23)
(prompt "\nFirst TYPE is: ") (princ (type x))
(prompt "\nSecond TYPE is: ") (princ (type 'x))
(princ))
Command Line Returns:
First TYPE is: REAL
Second TYPE is: SYM

...you should take not that I added the " ' " operator to my second TYPE call. This helps the command to differentiate that I am asking what type "x" IS rather than the type "x" REPRESENTS... Thus we can see that "x" itself, is a symbol much similar to your "a".

 

Now, the "Electrical Symbols" you are trying to differentiate in your code lead me to believe that you have some specific BLOCKS that you use to represent Electrical Symbols... If this is the case, you will not be using the (type ...) method to try to find your electrical symbols, but rather you will need a different approach to SIFT through your blocks... Since all blocks are, well, blocks.. you will need to further define your SIFTING criteria..

- If your Electrical Symbols are BLOCKS with the name "ELECTRICAL SYMBOL" then you can search for them that way...

- If your Electrical Symbols are BLOCKS on the layer "ELEC-SYM" then you can search for them that way...

...but until you, or someone helping you, knows how AutoCAD can DETERMINE which blocks are "Electrical Symbols", then you will need to provide more information.

 

Hope this helps.

 

 Best,

~DD

Message 3 of 6

david.faunce
Enthusiast
Enthusiast

So I found an ACADE Lisp Command in the API help:

 

(c:wd_is_it_schem_or_pnl  *entity*)

 

If in the command line I enter:

(setq a (car (entsel)))

(c:wd_is_it_schem_or_pnl a)

If the item is a schematic symbol the value returned is "4". If it is a regular block, the value returned is "nil".

 

How do I use this in the script above?

The following does not work: It returns the error "Bad Argument Type: lentityp <Selection Set: 315e3>"

 

(defun m:explodeAllButSymbols (/ a )
(setvar "qaflags" 1)
(setq a (ssget "X" (list (cons 0 "INSERT"))))
 (while (/= a nil)
  (progn
    if (= (c:wd_is_it_schem_or_pnl a) nil
   	(command "_.explode"  a "")
    )
   (setq a (ssget "X" (list (cons 0 "INSERT"))))
  );progn
 );while
(setvar "qaflags" 0)
(princ)
);

 

 

0 Likes
Message 4 of 6

dlanorh
Advisor
Advisor
Accepted solution

This should get you started.

 

(defun m:explodeAllButSymbols (/ ss cnt ent)
(setvar "qaflags" 1)
(setq ss (ssget "X" '((0 . "INSERT"))))
(cond (ss
        (repeat (setq cnt (sslength ss))
          (setq ent (ssname ss (setq cnt (1- cnt))))
          (if (not (c:wd_is_it_schem_or_pnl ent))
            (command "_.explode"  ent "")
          )
        );end_repeat  
      )
 );end_cond
(setvar "qaflags" 0)
(princ)
);end_defun
 

You were not going through the selection set properly, hence the error. i have shown you one method, other ways of doing it are shown here  http://lee-mac.com/selsetprocessing.html

 

I can't vouch for the (c:wd_is_it_schem_or_pnl ent) bit as i have no knowledge of the code therein.

 

 

I am not one of the robots you're looking for

Message 5 of 6

david.faunce
Enthusiast
Enthusiast

Actually this did everything I needed it to do. Thank you!

0 Likes
Message 6 of 6

CodeDing
Advisor
Advisor

@david.faunce ,

 

I noticed in your original question that you mentioned nested blocks. This will account for that..

(defun m:explodeAllButSymbols (/ ss cnt ent)
(setvar "qaflags" 1)
(while (setq ss (ssget "X" '((0 . "INSERT"))))
  (repeat (setq cnt (sslength ss))
    (setq ent (ssname ss (setq cnt (1- cnt))))
    (if (not (c:wd_is_it_schem_or_pnl ent))
      (command "_.explode" ent "")
    );if
  );repeat
);while
(setvar "qaflags" 0)
(princ)
);defun

Best,

~DD

0 Likes