dnll Posted January 27, 2016 Posted January 27, 2016 (edited) Hello! I currently have a few lines of a lisp routine that explodes blocks and changes the colour of my selection just fine. What I would like to add Is for some additional pieces of code to convert my entire selection back into a block and inserted to it's original position again. What I've got thus far: (defun c:rensa (/ pt) (setvar "qaflags" 1) (Prompt "Explode") (command "._explode" (ssget) "") (Prompt "Colourchange") (command "change" (ssget) "" "properties" "color" "9" "") (setvar "qaflags" 0) (princ) ) Any help would be much appreciated as this is a daunting daily routine that would save me alot of time! Edited January 27, 2016 by dnll Insert Quote
Lee Mac Posted January 27, 2016 Posted January 27, 2016 Welcome to CADTutor. Rather than exploding & reconstructing the block, why not simply change the colour of the objects within the block definition so that such changes are automatically applied to all references of the block in the drawing? Quote
Lee Mac Posted January 27, 2016 Posted January 27, 2016 Here is a quick example of how to achieve this using AutoLISP: (defun c:test ( / i l s ) (if (setq s (ssget '((0 . "INSERT")))) (repeat (setq i (sslength s)) (setq l (processblock (cdr (assoc 2 (entget (ssname s (setq i (1- i)))))) l)) ) ) (command "_.regen") (princ) ) (defun processblock ( n l / e x ) (cond ( (member n l)) ( (setq e (tblobjname "block" n)) (setq l (cons n l)) (while (setq e (entnext e)) (entmod (append (setq x (entget e)) '((62 . 9)))) (if (= "INSERT" (cdr (assoc 0 x))) (setq l (processblock (cdr (assoc 2 x)) l)) ) ) ) ) l ) 1 Quote
pBe Posted January 27, 2016 Posted January 27, 2016 Welcome to CADTutor. Rather than exploding & reconstructing the block, why not simply change the colour of the objects within the block definition so that such changes are automatically applied to all references of the block in the drawing? U-huh.. u-huh... Quote
dnll Posted January 28, 2016 Author Posted January 28, 2016 Thank you for your time Lee Mac. It is much appreciated. Your code worked brilliantly and as much as I would love to say I understand how even half of it works I'm stuck at being baffled. In a vain attempt to create an additional lisp function that instead of changing to colour 9 I want it to change to colour 6, I duplicated your code and inserted the number 6 where there previously was a 9. This however turned out to somehow override previous colourselection of test1 (colour 9) and add colour 6 to both codes "test1" and "test2". Quote
Lee Mac Posted January 28, 2016 Posted January 28, 2016 U-huh.. u-huh... Thank you for your time Lee Mac. It is much appreciated.Your code worked brilliantly and as much as I would love to say I understand how even half of it works I'm stuck at being baffled. You're most welcome - if you have any specific questions about how the code operates, feel free to ask. In a vain attempt to create an additional lisp function that instead of changing to colour 9 I want it to change to colour 6, I duplicated your code and inserted the number 6 where there previously was a 9. This however turned out to somehow override previous colourselection of test1 (colour 9) and add colour 6 to both codes "test1" and "test2". Please try the following instead: (defun c:test1 nil (modifyselection 9)) (defun c:test2 nil (modifyselection 6)) (defun modifyselection ( c / i l s ) (if (setq s (ssget '((0 . "INSERT")))) (repeat (setq i (sslength s)) (setq l (processblock (cdr (assoc 2 (entget (ssname s (setq i (1- i)))))) l c)) ) ) (command "_.regen") (princ) ) (defun processblock ( n l c / e x ) (cond ( (member n l)) ( (setq e (tblobjname "block" n)) (setq l (cons n l)) (while (setq e (entnext e)) (entmod (append (setq x (entget e)) (list (cons 62 c)))) (if (= "INSERT" (cdr (assoc 0 x))) (setq l (processblock (cdr (assoc 2 x)) l c)) ) ) ) ) l ) Quote
BIGAL Posted January 29, 2016 Posted January 29, 2016 My $0.05 Saves adding lines for different colours (defun c:test1 nil (modifyselection (Getint "\nEnter colour number"))) Quote
Lee Mac Posted January 29, 2016 Posted January 29, 2016 My $0.05 Saves adding lines for different colours (defun c:test1 nil (modifyselection (Getint "\nEnter colour number"))) Or perhaps: (defun c:test ( / c ) (if (setq c (acad_colordlg 1)) (modifyselection c)) (princ) ) 1 Quote
Dayananda Posted February 19, 2020 Posted February 19, 2020 Mr Lee can you modify above code to select all texts inside the block and send to layer called "BlockTexts". Quote
BIGAL Posted February 19, 2020 Posted February 19, 2020 Dayananda what about all the other entities in the block ? Rather than having multiple code attempts, clarify Text=layer "Block Texts" Lines,arcs,circles layer = ? Linetype = ? Color = ? Attributes ? ? Quote
Recommended Posts
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.