Jump to content

Recommended Posts

Posted

Hi All,

 

Was wondering if its possible via lisp to change selected text to a text style of my choosing? For example if i have a style called 'title' it would be good to be able to select the text, type title and then it be changed to the 'title' text style.

Had a bit of a browse but couldn't find anything that would let me change a text style to something else just using the command line.. thought it would/should be possible

Posted

Hi,

 

If you have the toolbar "Styles" appeared on the screen it would be easy just to select the desire text object then choose the desired text style from the drop-down menu of Text Styles.

 

Although it is easy to write a routine to what you are after but the bothering issue would be if the Text Style that you want to move a text to is with a long name.

Posted

Hi Tharwat,

 

not sure why long text style name makes a difference? wouldn't you just need to specify the name in the routine at the beginning and then never have to worry about the name again?

but anyway, i can make the text style name whatever i want. can make it 1 character if i need to.. haha

the main reason i'd like to set a shortcut to it as opposed to using dropdown is that it will allow me to assign it to one of my extra mouse buttons

i find i'm changing text styles pretty regularly so it would speed things up quite alot i think

Posted

So try this;

(defun c:2ts ( / ts ss sn)
 ;; Tharwat - 14.10.16 ;;
 (setq ts "title")
 (if (tblsearch "STYLE" ts)
   (if (and (princ (strcat "\nSelect texts to move to Text Style <" ts ">:"))
            (setq ss (ssget "_:L" (list '(0 . "TEXT,MTEXT") '(-4 . "<NOT") (cons 7 ts)
                                        '(-4 . "NOT>"))))
            )
     (while (setq sn (ssname ss 0))
       (entmod (append (entget sn) (list (cons 7 ts))))
       (ssdel sn ss)
       )
     )
   (princ (strcat "\nText Style <" ts "> is not found!"))
   )
 (princ)
 )

  • 7 years later...
Posted

;;;

;;; MATCH TEXTSTYLE

;;; FIRST PICK GETS TEXTSTYLE FROM FIRST TEXT OBJECT.

;;; SECOND PICK SETS TEXTSTYLE OF SECOND TEXT OBJECT.

;;; MULTIPLE OBJECTS CAN BE SELECTED ON SECOND PICK.

;;;

;;;

 

;;; Tharwat - 14.10.16 ;;

;;;

(defun c:2ts ( / ts ss sn)

  ;;; ADDED CODE BELOW

  (setq ss2 (ssget "_:S" (list '(0 . "TEXT,MTEXT"))))

  (setq sn2 (ssname ss2 0))

  (setq tsentget (cdr (assoc 7 (entget sn2))))

  (terpri)

  (princ (strcat "TextStyle will be updated to " tsentget))

  (terpri)

  ;;; ADDED CODE ABOVE

  ;;;

  ;;; MODIFIED

 ;; Tharwat - 14.10.16 ;;

 ;;;(setq ts "title") COMMENTED THIS LINE OUT

 (setq ts tsentget)

 (if (tblsearch "STYLE" ts)

   (if (and (princ (strcat "\nSelect texts to move to Text Style <" ts ">:"))

            (setq ss (ssget "_:L" (list '(0 . "TEXT,MTEXT") '(-4 . "<NOT") (cons 7 ts)

                                        '(-4 . "NOT>"))))

            )

     (while (setq sn (ssname ss 0))

       (entmod (append (entget sn) (list (cons 7 ts))))

       (ssdel sn ss)

       )

     )

   (princ (strcat "\nText Style <" ts "> is not found!"))

   )

 (princ)

 )

;;;

;;; ERROR TRAP

;;;

(defun *error* (errormsg)

  (VL-BT)

  (princ "error: ")

  (alert errormsg)

  (princ)

  (gc)

)

;;;

  • Dislike 1

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