Jump to content

Auto Selecting Text


caltes75

Recommended Posts

Hey all. I am new to writing .lisp routines and this is my first post. I am having an issue with a version of txt2mtxt routine. I want to be able to run the below listed routine without manually selecting the text. I want it all to be automated. Is this even possible or am I completely out there.:? Here is the code that I have so far.

 

 

(defun Merge()

(if (and (setq ss (ssget '((0 . "MTEXT,TEXT")))) ;Select both MText & DText

(> (sslength ss) 1) ;Check if more than one selected

) ;_ end of and

(progn

(setq n 1 ;Initialize counter

en (ssname ss 0) ;Get 1st selected

ed (entget en) ;Get its DXF data

txt (cdr (assoc 1 ed)) ;Get its textvalue

) ;_ end of setq

(if (= (cdr (assoc 0 ed)) "TEXT") ;If the 1st is a DText

(progn

(command "txt2mtxt" en "") ;Convert it to a MText

(setq obj (vlax-ename->vla-object (entlast)))

(vlax-put-property obj 'LineSpacingFactor 1)

(vlax-put-property obj 'LineSpacingDistance 0.25)

(vlax-put-property obj 'LineSpacingStyle 2)

(setq en (entlast)) ;Get the new MText

) ;_ end of progn

) ;_ end of if

(setq eo (vlax-ename->vla-object en)) ;Get the ActiveX object of the 1st text

(while (

(setq en (ssname ss n) ;Get the nth text

ed (entget en) ;Get its DXF data

) ;_ end of set

(setq txt (strcat txt "\\P" (cdr (assoc 1 ed)))) ;Append its string to add to the 1st text

(entdel en) ;Delete the nth text

(setq n (1+ n)) ;Increment the counter

) ;_ end of while

(vla-put-TextString eo txt) ;Modify the 1st text to the concatenated string

(command "_.justifytext" pause "" "ML")

) ;_ end of progn

) ;_ end of if

)

Link to comment
Share on other sites

You might also consider these:

  • foreach, if not vlax-for
  • vla-delete
  • vla-get-textstring
  • vla-put-attachmentpoint
  • vla-put-linespacingfactor
  • vla-put-linespacingdistance
  • vla-put-linespacingstyle

Also, be sure to delete your selection set toward the end of your routine:

 

(vla-delete ss)

Link to comment
Share on other sites

you'll need (setq ss (ssget "_x" '((0 . "mtext,text"))))

 

EXAMPLE will return T

(wcmatch (strcase "hi old text!") "*OLD TEXT*")

use entmod

Link to comment
Share on other sites

what is the purpose of using entmod? :unsure:

 

Modifies the definition data of an object (entity)

...

 

See VLIDE Help for more information.

Link to comment
Share on other sites

create a few texts with the word old in it.

 

 

;;method by Alanj
;;modified by reid b.
(defun c:test (/ ss id ent a b)
 (setq ss (ssget "_x" '((0 . "text,mtext")))
         id 0)
      (while (setq ent (ssname ss id))
        (if (wcmatch (strcase (cdr (setq a (assoc 1 (setq b (entget ent)))))) "*[color=red]OLD[/color]*")
[u];;[color=red]OLD[/color] must be uppercase[/u]
[color=dimgray][color=black][u];;will only modify text with the word [color=red]old[/color] in it[/u][/color]
[/color]           (entmod (subst (cons 1 "[color=red]NEW[/color]") a b))
        )
      (setq id (1+ id))
      )
 (princ)
)

Edited by Lt Dan's legs
Link to comment
Share on other sites

:)

 

(defun c:test ( / old new )
 ;; © Lee Mac 2010

 (setq old "Lee" new "Mac")

 (
   (lambda ( s i / e )
     (if s
       (while (setq e (ssname s (setq i (1+ i))))
         (entupd
           (cdr
             (assoc -1
               (entmod
                 (subst
                   (cons 1 new) (assoc 1 (entget e)) (entget e)
                 )
               )
             )
           )
         )
       )
     )
   )
   (ssget "_X" (list (cons 0 "TEXT,MTEXT") (cons 1 old))) -1
 )

 (princ)
)
                  

 

^^ Much easier :)

Link to comment
Share on other sites

(defun c:Test (/ new old ss)
 (setq new "WoO"
       old "Hoo"
 )

 (if (setq ss (ssget "_X" '((0 . "MTEXT,TEXT"))))
   ((lambda (i / e s l)
      (while (setq e (ssname ss (setq i (1+ i))))
        (if (wcmatch (strcase (cdr (setq s (assoc 1 (setq l (entget e)))))) (strcase old))
          (entmod (subst (cons 1 new) s l))
        )
      )
    )
     -1
   )
 )
 (princ)
)

Link to comment
Share on other sites

to Lee,

Seems your code will only change Lee as it's writen. If it's all caps or lower case the text will not change. Wouldn't this be the same as using

(ssget "_x" '((1 . "Lee"))) then entmod?

Link to comment
Share on other sites

to Lee' date='

Seems your code will only change Lee as it's writen. If it's all caps or lower case the text will not change. Wouldn't this be the same as using

(ssget "_x" '((1 . "Lee"))) then entmod?

 

Yeah, I'll confess I didn't read the whole thread and didn't know that case sensitivity was an issue...

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