Jump to content

Colourchange and convert to block


dnll

Recommended Posts

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 by dnll
Insert
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
)

  • Like 1
Link to comment
Share on other sites

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

 

:beer:

Link to comment
Share on other sites

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

Link to comment
Share on other sites

U-huh.. u-huh...

 

:beer:

 

:)

 

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
)

Link to comment
Share on other sites

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

  • Thanks 1
Link to comment
Share on other sites

  • 4 years later...

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

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