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

Edit "all" into "select block" lisp

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
sander.van.pelt
302 Views, 9 Replies

Edit "all" into "select block" lisp

Hello all,

Probably a very easy question for you, but not for me because of my lisp knowledge;

To clean up drawings I use 2 lisps to change blocks. One lisp makes all layers included in the block the same layer as the block itself and the other lisp makes the color of the block the same as the layer of the block.

Now I can select any block I want to change with the 1st lisp. However, if I use the 2nd lisp, all blocks in the drawing are automatically changed.

Now it says in this lisp
(COMMAND "change" "all" "" "p" "c" "bylayer" "") how should this be changed so that I first have to select 1 or more blocks to change the colors of only these blocks and not all blocks?

Thank you

Tags (3)
Labels (3)
9 REPLIES 9
Message 2 of 10

(if (setq ss (ssget '(( 0 . "Insert"))))
 (COMMAND "_.change" ss "" "_p" "_c" "bylayer" "") 
 (princ"\nNo Blocks Selected")
)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 10

Hello Paullimapa

If I change

(COMMAND "change" "all" "" "p" "c" "bylayer" "")

 into 

(if (setq ss (ssget '(( 0 . "Insert"))))
 (COMMAND "_.change" ss "" "_p" "_c" "bylayer" "") 
 (princ"\nNo Blocks Selected")
)

then I only have to select the blocks after all the blocks in the whole drawing have already changed to "color bylayer".

Message 4 of 10

Yes. That change will now let you select the blocks instead of automatically selecting all blocks. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 10

If I now enter the command, the colors of all blocks in the drawing are immediately changed. Only after the changes have been made do I have to select the blocks that I would like to modify
Message 6 of 10

Reviewing the contents of the lisp code you attached, this line of code you thought was the one that selected all blocks to process is not it. 

(COMMAND "change" "all" "" "p" "c" "bylayer" "")

Actually, towards the beginning of the code these are the lines that automatically selects all the blocks in the drawing:

(setq blk_list (ai_table "block" 12)) ; no Xrefs or
 ; Xref dependents.
 (if (>= (getvar "maxsort") (length blk_list)) ; Alphabetize if greater
 (if blk_list (setq blk_list (acad_strlsort blk_list))) ; than maxsort.
 )

To allow you to select the bocks you want to process replace the above with this:

; ss_blk returns a list of block names from selection
(defun ss_blk (/ en i lst nam obj ss tbl)
 (vl-load-com)
 (if(setq ss (ssget '(( 0 . "INSERT"))))
   (progn
     (repeat (setq i (sslength ss))
       (setq en (ssname ss (setq i (1- i))) ; get entity
             obj (vlax-ename->vla-object en) ; convert to obj
             nam (vla-get-effectivename obj) ; get blknam
             tbl (tblsearch"BLOCK" nam) ; get blktbl
       )
       (if (and
             (not(assoc 1 tbl)) ; chk if xrf
             (not(member nam lst)) ; chk if already in list
           )
         (setq lst (append (list nam) lst)) ; add to list
       ) ; if
     ) ; repeat
     (if(> (length lst) 1) ; if more than 1 item found
         (setq lst (vl-sort lst '(lambda (a b)(< (strcase a) (strcase b))))) ; sort 
     )     
   ) ; progn
   (princ"\nNothing selected.")
 )
 ; return list of selected blk names
 lst
) ; defun
(setq blk_list (ss_blk))

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 10

Hello Paullimapa,
First of all, thank you for your quick response.

However, after adjusting the lisp, I now encounter the following problem.
To make it clearer I added an image.

The top 3 circles represent the situation before I perform the lisp. The 1st of these is a block, the 2nd and 3rd a normal circle.
The circle in the block has a different color than the layer of the block itself. The 2nd is correct and the 3rd circle is not the color of the layer itself but a color that does not need to be adjusted / should remain that way.

If you look at the bottom row, this is the view after executing the lisp.
Here I first had to select the block that was not the color of the layer. The circle in the block now changes to the correct color. However, the color of the 3rd circle now also changes to its original color, while I only want to change the block that I have selected.

So the 3rd circle should remain magenta.
Knipsel.JPG

Message 8 of 10

Remember this 

(COMMAND "change" "all" "" "p" "c" "bylayer" "")

This changes everything like that Circle color which is not a Block to bylayer

Make sure that’s no longer in the code 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 10

Stupid..... 😁
I actually forgot to delete it during the last change.
Always make a copy of the original first if I am going to change something.
So this row was included again.

Thank you @paullimapa. The code now works as I want it to.

Message 10 of 10

Glad that finally worked out for you…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos

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

Post to forums  

Autodesk Design & Make Report

”Boost