Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a Icon that changes text strings???... 2

Status
Not open for further replies.

willb5150

Aerospace
Apr 14, 2005
6
US
What I am trying to do is make a vba script, lisp, or macro that will let me select a toolbar button then click a piece of text and it will add the text of the button...

Example: (Wire Diagram) ------ BLACK --------

1. Click the "GREEN" icon button...
2. Click the "BLACK" text string...
3. It will change to "GREEN"...

Ending up like this: ------- GREEN -------

Any ideas how to accomplish this????
 
Replies continue below

Recommended for you

This is kinda the path that I am currently on...

(Defun c:wirecolorgreen ()
(setq wirecolor (entsel "\n Select Text to make GREEN:"))
(setq wirecolorvalue "GREEN")
(command "ddedit" wirecolorvalue wirecolor "")
(princ)
)

But I can't get it to work...Please HELP...
 
I don't think you'll be able to work with "ddedit". Here's a version thant uses 'entmod' to change the text.

(Defun c:green ()
(setq textent (car (entsel "\n Select Text to make GREEN:")))
(setq edata (entget textent))
(setq wirecolorvalue "GREEN")
(setq Newdata (subst (cons 1 wirecolorvalue) (assoc 1 edata) edata))
(entmod NewData)
(princ)
)
 
Thanks SOOOO much. That worked perfect. Thanks.
You SOOO rock...thanks
 
willb5150,

You can also use the CHANGE command.

For example:

(defun c:wiregreen ()
(setq TEXTENT (entsel "\nSelect TEXT to make GREEN: "))
(command "CHANGE" TEXTENT "" "P" "C" GREEN "")
(princ)
)

Hope this helps,
Paul
 
You're Soooo welcome. :)

Next you may want to enhance it to loop while you do multiple picks, or select a group of text, or ???

You might also have just 1 "change color" button, but it has an option of a few colors, then go to selecting text. Saves on icon space.
 
thanks again to both of you...you guys really helped...
 
Hey Paul...your CHANGE approach changes the COLOR of the text to green, but willb50 wants to change the actual text to read "green". There may be a command line way to edit text but I couldn't come up with it.
 
This LISP changes text.
It is not mine but I forgot where I got it so I can't give proper credit.
Type CT or pick the button.
Pick all the text you want to change.
Type the old text string BLACK
Type the new text string GREEN
All text BLACK changes to GREEN

;
(DEFUN C:CT (/ p l n e os as ns st s nsl osl sl si chf chm olderr) ; Correct spelling errors
(setq olderr *error* ; Initialize variables
*error* chgterr
chm 0)
(setq p (ssget)) ; Select objects
(if p (progn ; If any objects selected
(while (= 0 (setq osl (strlen (setq os (getstring t "\nOld string: ")))))
(princ "Null input invalid")
)
(setq nsl (strlen (setq ns (getstring t "\nNew string: "))))
(setq l 0 n (sslength p))
(while (< l n) ; For each selected object...
(if (= "TEXT" ; Look for TEXT entity type (group 0)
(cdr (assoc 0 (setq e (entget (ssname p l))))))
(progn
(setq chf nil si 1)
(setq s (cdr (setq as (assoc 1 e))))
(while (= osl (setq sl (strlen
(setq st (substr s si osl)))))
(if (= st os)
(progn
(setq s (strcat (substr s 1 (1- si)) ns
(substr s (+ si osl))))
(setq chf t) ; Found old string
(setq si (+ si nsl))
)
(setq si (1+ si))
)
)
(if chf (progn ; Substitute new string for old
(setq e (subst (cons 1 s) as e))
(entmod e) ; Modify the TEXT entity
(setq chm (1+ chm))
))
)
)
(setq l (1+ l))
)
))
(princ "Changed ") ; Print total lines changed
(princ chm)
(princ " text lines.")
(terpri)
(setq *error* olderr) ; Restore old *error* handler
(princ)
)
;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top