Author Topic: Change/Replace value, & color of selected normal blocks  (Read 2600 times)

0 Members and 1 Guest are viewing this topic.

paul_s

  • Guest
Change/Replace value, & color of selected normal blocks
« on: September 23, 2008, 12:04:29 PM »
Hello,

I've been trying to look for a 2 lisp routine to be able to replace text/mtext
of "selected normal blocks". And one that will change the color of text/mtext
of "selected normal blocks".

They are not "attribute blocks", and I dont want to change the block's
value globally. I want to able to select by window..I only need to change
the text/mtext value, & color of text/mtext of the selected blocks. Even though
they are the same block. I need these to clean drawings I receive for clients.

I hope this is simple...Thanks.

Paul

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change/Replace value, & color of selected normal blocks
« Reply #1 on: September 23, 2008, 12:07:09 PM »
When you change the text/mtext of a block, it will change all the blocks of the same name.  It can be done.  How much Lisp do you know?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

paul_s

  • Guest
Re: Change/Replace value, & color of selected normal blocks
« Reply #2 on: September 23, 2008, 12:13:08 PM »
Hi Tim,

I think I know enough to modify a lisp routine. In a scale
of 1 to 10, I'd say I am a 7.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change/Replace value, & color of selected normal blocks
« Reply #3 on: September 23, 2008, 12:20:06 PM »
So if I give you an outline you can code it?  And we can help you along the way.

Get you selection set
Step through the selection set
 - Check if the block name has been changed yet
    - If not, prompt for string to replace, and color to change it
    - Step through the block definition, and when you find a text/mtext entity, change it per user information

That is how I would do if it you want a selection set action.  You could switch the two options if it hasn't been changed yet if there are more than one text/mtext entity per block definition.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

paul_s

  • Guest
Re: Change/Replace value, & color of selected normal blocks
« Reply #4 on: September 23, 2008, 12:39:37 PM »
Tim,

To modify a lisp I think I am a 7. To write one, I'm a 5...But here's what I came
up with so far before I decided on getting help. (This routine does not work).

(defun C:ChgBlktxt ( / newstring ename)
(setq   sset (ssget '((0 . "INSERT") ))
   num  0
   len  (sslength sset)
)
(setq NewString (getstring"\nReplace block's text with: "))
(progn
(setq Count 0)
(setq blk (ssname sset Count))
(setq currentblk blk)
(setq currentblk (entnext currentbl))
(setq ent1 (entget currentblk))
(setq Ename (cdr (assoc 2 Ent1)))
(while EName (if (and (= "TEXT" (cdr (assoc 0 (setq EList (entget EName)))))
                      (= "MTEXT" (cdr (assoc 0 (setq EList (entget EName)))))
                  );and
                 (progn (entmod (list (assoc -1 Elist) (cons 1 NewString)))
                        (setq Count (1+ Count))
                 );progn
           );if
             (setq EName (entnext EName))
);while
);progn
Count
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change/Replace value, & color of selected normal blocks
« Reply #5 on: September 23, 2008, 12:58:41 PM »
See how this works for you Paul.  It seems to work here, so I hope you can learn from it.

Code: [Select]
(defun c:ChgBlkTxt (/ num NewString NewClr sset Ent EntData tempBlkName BlkNameList tempEnt)
   
    (setq num -1)
    (if
        (and
            (setq NewString (getstring "\n Replace block's text with: "))
            (setq NewClr (acad_colordlg 252))
            (setq sset (ssget '((0 . "INSERT"))))
        )
        (while (setq Ent (ssname sset (setq num (1+ num))))
            (setq EntData (entget Ent))
            (if (not (member (setq tempBlkName (cdr (assoc 2 EntData))) BlkNameList))
                (progn
                    (setq BlkNameList (cons tempBlkName BlkNameList))
                    (setq tempEnt (tblobjname "block" tempBlkName))
                    (while (setq tempEnt (entnext tempEnt))
                        (setq EntData (entget tempEnt))
                        (if (wcmatch (cdr (assoc 0 EntData)) "*TEXT")
                            (progn
                                (setq EntData (subst (cons 1 NewString) (assoc 1 EntData) EntData))
                                (if (setq tempList (assoc 62 EntData))
                                    (setq EntData (subst (cons 62 NewClr) tempList EntData))
                                    (setq EntData (append EntData (list (cons 62 NewClr))))
                                )
                                (entmod EntData)
                            )
                        )
                    )
                )
            )
        )
    )
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change/Replace value, & color of selected normal blocks
« Reply #6 on: September 23, 2008, 01:11:58 PM »
Forgot to say that you might have to do a regen after to see the changes.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

paul_s

  • Guest
Re: Change/Replace value, & color of selected normal blocks
« Reply #7 on: September 23, 2008, 01:13:53 PM »
Tim,

Wow!!!...Thank you very much! I'm sure I am going to learn from this.
Keep up the good work!

Paul,

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change/Replace value, & color of selected normal blocks
« Reply #8 on: September 23, 2008, 01:19:50 PM »
Tim,

Wow!!!...Thank you very much! I'm sure I am going to learn from this.
Keep up the good work!

Paul,

You're welcome Paul.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Change/Replace value, & color of selected normal blocks
« Reply #9 on: September 23, 2008, 01:39:10 PM »
Welcome to TheSwamp paul_s.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

paul_s

  • Guest
Re: Change/Replace value, & color of selected normal blocks
« Reply #10 on: September 23, 2008, 02:20:37 PM »
Thank you!