caltes75 Posted August 31, 2010 Share Posted August 31, 2010 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 ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 31, 2010 Share Posted August 31, 2010 Welcome to the forum. here it goes . correct it in your codes . (if (and (setq ss (ssget [b][color="red"]"_x"[/color][/b] '((0 . "MTEXT,TEXT")))) Tharwat Quote Link to comment Share on other sites More sharing options...
caltes75 Posted August 31, 2010 Author Share Posted August 31, 2010 Thanx. What if I don't want all of the text in the drawing, but just specific ones. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 31, 2010 Share Posted August 31, 2010 so you will go back to your first code, because it is single selection. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 31, 2010 Share Posted August 31, 2010 Read this ( how to post codes) http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 31, 2010 Share Posted August 31, 2010 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) Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted August 31, 2010 Share Posted August 31, 2010 you'll need (setq ss (ssget "_x" '((0 . "mtext,text")))) EXAMPLE will return T (wcmatch (strcase "hi old text!") "*OLD TEXT*") use entmod Quote Link to comment Share on other sites More sharing options...
caltes75 Posted August 31, 2010 Author Share Posted August 31, 2010 what is the purpose of using entmod? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 31, 2010 Share Posted August 31, 2010 what is the purpose of using entmod? Modifies the definition data of an object (entity) ... See VLIDE Help for more information. Quote Link to comment Share on other sites More sharing options...
caltes75 Posted August 31, 2010 Author Share Posted August 31, 2010 I know i am being really dumb now, but how would i go about writing in the wcmatch and entmod into my code? Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted August 31, 2010 Share Posted August 31, 2010 (edited) 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 September 1, 2010 by Lt Dan's legs Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 1, 2010 Share Posted September 1, 2010 (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 Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 1, 2010 Share Posted September 1, 2010 ^^ Much easier And case sensitive. Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 1, 2010 Share Posted September 1, 2010 (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) ) Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted September 1, 2010 Share Posted September 1, 2010 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? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 1, 2010 Share Posted September 1, 2010 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... Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted September 1, 2010 Share Posted September 1, 2010 No worries, I'm just wanting to learn Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.