Jump to content

Change all Text


migs

Recommended Posts

Hi

 

im new around here and looking for some help with a routine i found on here. The problem i have is that im looking for the lisp routine to select all text and convert it to my standards (verdana). i had the routine running fine last friday and it was converting the text properly but for some reason today i cannot get it working.

 

any help would be much appreciated

 

(defun C:ALLTEXT (/ entities len count ent ent_data ent_name new_style_name)

(command "STYLE" "verdana" "verdana.ttf" "" "" "" "" "")

(setq entities (ssget "X" '((0 . "TEXT")))

len (sslength entities)

count 0

);setq

(while (

(setq ent (ssname entities count)

ent_data (entget ent)

ent_name (cdr (assoc 7 ent_data))

);setq

(setq new_style_name (cons 7 "verdana"))

(setq ent_data (subst new_style_name (assoc 7 ent_data) ent_data))

(entmod ent_data)

(setq count (+ count 1))

);while

;;;runs same routine again, picking up Mtext this time.

(setq entities (ssget "X" '((0 . "MTEXT")))

len (sslength entities)

count 0

);setq

(while (

(setq ent (ssname entities count)

ent_data (entget ent)

ent_name (cdr (assoc 7 ent_data))

);setq

(setq new_style_name (cons 7 "verdana"))

(setq ent_data (subst new_style_name (assoc 7 ent_data) ent_data))

(entmod ent_data)

(command "explode" ent)

(setq count (+ count 1))

);while

(princ)

);defun

 

Error appears: error: bad argument type: lselsetp nil

 

any ideas?

Link to comment
Share on other sites

  • Replies 30
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    13

  • migs

    5

  • CAB

    4

  • ReMark

    3

Top Posters In This Topic

You made no changes to the Lisp routine itself right? Could the problem be the drawing itself? Can you test the routine on another drawing?

 

if you changed the routine did you run it through the Visual Lisp editor to verify functionality?

Link to comment
Share on other sites

no changes were made to this routine itself

 

i changed my .mnu file by mistake a amended it accordingly, i tried to use this routine and just had problems with it since which has me very confused now.

 

ive tried running the routine both through my .mnu self made toolbar and just straight through lisp (bypassing) the .mnu

 

ive tried running it in a few different drawings all with the same outcome

Link to comment
Share on other sites

error: bad argument type: lselsetp nil

 

normally means that the selection set that you are dealing with is nil.

 

Make you sure include an IF command in the LISP to allow for no text being present in the drawing.

 

Also, if you are using MTEXT instead of single-line text, then the filter list for the ssget function will need to be something like:

 

(list (cons 0 "TEXT,MTEXT"))

 

Hope this helps

 

 

PS - please enclose your code in

 [/ code] tags in future posts :)

 

Lee

Link to comment
Share on other sites

error: bad argument type: lselsetp nil

 

normally means that the selection set that you are dealing with is nil.

 

Make you sure include an IF command in the LISP to allow for no text being present in the drawing.

 

Also, if you are using MTEXT instead of single-line text, then the filter list for the ssget function will need to be something like:

 

(list (cons 0 "TEXT,MTEXT"))

 

Hope this helps

 

 

PS - please enclose your code in

 [/ code] tags in future posts :)

 

Lee

 

 

thanks alot Lee

 

ive just started learning LISP and apart from making very simple amendments to routines ive already found it pretty much clear as much to me.

 

if its not too much trouble to someone is it possible to write a quick fix for me as im not sure what the IF command should be

 

although any help is very much appreciated

Link to comment
Share on other sites

Thanks for the help but managed to work it out

added in this part instead of running the routine twice

and made a few alterations, although still not sure how the problem occurred

 

(list (cons 0 "TEXT,MTEXT")) [/ code]
Link to comment
Share on other sites

This should work although it is written quickly and is untested. :unsure:

 

(defun c:txtchng (/ ss)
 (vl-load-com)
 (if (and (tblsearch "STYLE" "VERDANA")
      (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")
            (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
               (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq ss (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
     (foreach e ss
   (entmod (subst (cons 7 "VERDANA") (assoc 7 e) e))))
   (princ "\n<!> No Text Found or Verdana Style Doesn't Exist <!>"))
 (princ))

 

Accounts for a nil selection set, no text style and Mtext and text options.

Link to comment
Share on other sites

I suppose you could make the txtchanger into a sub-function and call it with the text style argument, so that multiple style changes could be made:

 

(defun txtchng (sNme / ss)
 (vl-load-com)
 (if (and (tblsearch "STYLE" sNme)
      (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")
            (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
               (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq ss (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
     (foreach e ss
   (entmod (subst (cons 7 sNme) (assoc 7 e) e))))
   (princ "\n<!> No Text Found or Verdana Style Doesn't Exist <!>")))

(defun c:test ()
 (txtchng "VERDANA")
 (princ))

 

Hope this helps... :P

Link to comment
Share on other sites

 (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")

Beat me to it.

 

OP, that's how you would filter all text and Mtext at once, so that you only do the process once.

 

Nicely coded as usual, Lee. You need to teach me how to properly use mapcar one day.:shock:

Link to comment
Share on other sites

Thanks Udffl... mapcar isn't too hard to grasp - as long as you remember that it applies the function to every element in a provided list and will return the result of doing so as a list of the returns...

 

I used to struggle with the difference between mapcar and apply... but this is overcome by realising that "apply" performs the function to the whole list and returns one result as opposed to a list of results...

 

Thanks for your compliments as always - I try to keep things as concise as possible at all times.. :P

 

Nice sig btw. :) made me laugh :)

 

Cheers

 

Lee

Link to comment
Share on other sites

This should work although it is written quickly and is untested. :unsure:

 

(defun c:txtchng (/ ss)
 (vl-load-com)
 (if (and (tblsearch "STYLE" "VERDANA")
      (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")
            (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
               (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq ss (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
     (foreach e ss
   (entmod (subst (cons 7 "VERDANA") (assoc 7 e) e))))
   (princ "\n<!> No Text Found or Verdana Style Doesn't Exist <!>"))
 (princ))

 

Accounts for a nil selection set, no text style and Mtext and text options.

 

I ran this routine and it worked great as far as getting to the correct style goes, but it doesnt change heights and/or widths. Anyone know of the correct way to include those in this routine?

Link to comment
Share on other sites

For instance to change all text and mtext to Verdana with height 4.5:

 

(defun txtchng (sNme Ht / ss)
 (vl-load-com)
 (if (and (tblsearch "STYLE" sNme)
      (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")
            (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
               (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq ss (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
     (foreach e ss    
       (entmod (subst (cons 7 sNme) (assoc 7 e) (subst (cons 40 Ht) (assoc 40 e) e)))))
   (princ "\n<!> No Text Found or Verdana Style Doesn't Exist <!>"))
 (princ))

(defun c:test ()
 (txtchng "VERDANA" 4.5)
 (princ))

Link to comment
Share on other sites

Lee: What would have caused the routine to not work after having worked previously?

 

when writing and testing the code, he could have defined a variable as global, and it wasn't setting it properly in the routine. when he restarted autocad, the global variable wouldn't be set anymore, thus, when the routine arrived at that point, it couldn't continue.

Link to comment
Share on other sites

Lee: What would have caused the routine to not work after having worked previously?

 

If you ran the routine once then all the MTEXT objects are exploded and there are no more MTEXT objects in the drawing.

So when you run it again, this code

(setq entities (ssget "X" '((0 . "MTEXT")))
       len     (sslength entities)  ; <---<<  fails here 
       count 0
);setq 

 

As Lee pointed out the selection set is now nil and

(sslength nil) causes an error.

Link to comment
Share on other sites

I modified you code but did not test it.

(defun C:ALLTEXT (/ entities len count ent ent_data new_style_name)
 (command "STYLE" "verdana" "verdana.ttf" "" "" "" "" "")
 (if (setq entities (ssget "X" '((0 . "TEXT,MTEXT"))))
   (progn
     (setq len            (sslength entities)
           count          0
           new_style_name (cons 7 "verdana")
     )   ;setq 
     (while (< count len)
       (setq ent      (ssname entities count)
             ent_data (entget ent)
       ) ;setq
       (entmod (subst new_style_name (assoc 7 ent_data) ent_data))
       (if (= (cdr (assoc 0 ent_data)) "MTEXT")
         (command "explode" ent "")
       )
       (setq count (+ count 1))
     )   ;while
   )
 )
 (princ)
)         ;defun

Link to comment
Share on other sites

CAB,

 

Is there any better way to phrase the following line, so that more can be added in one step?

 

(defun txtchng    (sNme Ht / ss)
 (vl-load-com)
 (if (and (tblsearch "STYLE" sNme)
      (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")
        (if (getvar "CTAB") (cons 410 (getvar "CTAB"))
       (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq ss (mapcar 'entget (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
     (foreach e  ss
  [b][color=Red] (entmod (subst (cons 7 sNme) (assoc 7 e) (subst (cons 40 Ht) (assoc 40 e) e)))[/color][/b]))
   (princ "\n<!> No Text Found or Verdana Style Doesn't Exist <!>"))
 (princ))

(defun c:test  ()
 (txtchng "VERDANA" 4.5)
 (princ))

I have tried using mapcar, but to no avail - but not sure why :(

 

[b][color=Red]    (mapcar 'entmod
                 (mapcar 'subst
                              '((cons 7 sNme) (cons 40 Ht))
                              '((assoc 7 e)   (assoc 40 e))
                                (list e)))[/color][/b]

Thanks

 

Lee

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