jmerch Posted February 24, 2011 Share Posted February 24, 2011 I've searched high and low for a LISP to edit Mtext via LISP and have only found one (thanks Mike Weaver) that is almost what I want. It is posted below but I want it to autoselect a piece of MTEXT that I designate (via ssget). I have modified this code but don't understand Visual LISP enough to know why it's erroring...any help? Original: (defun c:mtval( / ent objmtext stroldval strnewval) (setq ent (car (entsel)) objMText (vlax-ename->vla-object ent) strOldval (vlax-get-property objMText "TEXTSTRING") strnewval (getstring T (strcat "\nNew text value<" stroldval ">: ")) ) (if strnewval (vlax-put-property objmtext "TEXTSTRING" strnewval) ) (vlax-release-object objmtext) ) My modified code: (defun c:mtval( / getmtext objMText strnewval) (setq getmtext (ssget "_X" '((0 . "MTEXT")(1 . "TEST"))) objMText (vlax-ename->vla-object (entlast)) strnewval (getstring T "Enter New Text: ") ) (if strnewval (vlax-put-property objmtext "TEXTSTRING" strnewval) ) (vlax-release-object objmtext) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 24, 2011 Share Posted February 24, 2011 Be careful that the text string is case sensitive . So here it goes buddy. (defun c:test (/ new ss) ; Tharwat 24.02. 2010 (if (and (setq new (getstring T "Enter New Text: ")) (setq ss (ssget "_X" '((0 . "MTEXT") (1 . "test")))) ) ((lambda (i / ss1 e) (while (setq ss1 (ssname ss (setq i (1+ i)))) (entupd (cdr (assoc -1 (entmod (subst (cons 1 new) (assoc 1 (setq e (entget ss1))) e) ) ) ) ) ) ) -1 ) (Alert "\n Your replaced text is not found in the drawing....." ) ) (princ) ) Tharwat Quote Link to comment Share on other sites More sharing options...
jmerch Posted February 24, 2011 Author Share Posted February 24, 2011 that doesn't work... it asks me to select an object then just isolates it.... Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 24, 2011 Share Posted February 24, 2011 (setq getmtext (ssget "_X" '((0 . "MTEXT")(1 . "TEST"))) [color=red]<-Select [u]all[/u] MText with "TEST" value[/color] objMText (vlax-ename->vla-object (entlast)) [color=red]<- converts the last created object to a vla-object (not what you want to do here)[/color] Quote Link to comment Share on other sites More sharing options...
jmerch Posted February 24, 2011 Author Share Posted February 24, 2011 (setq getmtext (ssget "_X" '((0 . "MTEXT")(1 . "TEST"))) [color=red]<-Select [u]all[/u] MText with "TEST" value[/color] objMText (vlax-ename->vla-object (entlast)) [color=red]<- converts the last created object to a vla-object (not what you want to do here)[/color] I know I'm selecting all Mtext with "Test" value, I understand the ssget function. But on the entlast, i thought that just grabbed the entity data from the last object, I didn't realize it converts the last created object. In order to edit the Mtext, from what I can tell it has to be a vla-object which is why it's getting converted, right? Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 24, 2011 Share Posted February 24, 2011 I know I'm selecting all Mtext with "Test" value, I understand the ssget function. But on the entlast, i thought that just grabbed the entity data from the last object, I didn't realize it converts the last created object. In order to edit the Mtext, from what I can tell it has to be a vla-object which is why it's getting converted, right? Your selection with ssget has no bearing on (entlast). You need to step through the selectionset with repeat/while or vla-get-activeselectinset. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 24, 2011 Share Posted February 24, 2011 Check this out in VL . (defun c:test (/ new ss)(vl-load-com) ; Tharwat 24.02. 2010 (if (and (setq new (getstring T "Enter New Text: ")) (setq ss (ssget "_X" '((0 . "MTEXT") (1 . "test")))) ) ((lambda (i / ss1) (while (setq ss1 (ssname ss (setq i (1+ i)))) (vla-put-textstring (vlax-ename->vla-object ss1) new) ) ) -1 ) (Alert "\n Your replaced text is not found in the drawing....." ) ) (princ) ) Tharwat Quote Link to comment Share on other sites More sharing options...
jmerch Posted February 24, 2011 Author Share Posted February 24, 2011 @alan: Maybe I'm not understanding you. I was doing the ssget to "grab" the mtext on my drawing, and thought I needed to convert this to vla-obect. What contains the properties (text string) of mtext? vla-get-activeselectionset isn't a function. @Tharwat: Same result, it asks 'Select Objects in Current Drawing or Xref'...then isolates it. Why is it doing that? it's not asking me to enter any text or anything... I appreciate the help from both of you. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 24, 2011 Share Posted February 24, 2011 The two routines that I already posted for you are working normally in Arch. Autocad , but I do not have MEP cad to check these codes for it . Anyway , can you please copy your command line after fails of the routine with your version ? Tharwat Quote Link to comment Share on other sites More sharing options...
jmerch Posted February 24, 2011 Author Share Posted February 24, 2011 it's not really "failing", just not doing what I want...I wonder what in your code has dependency on the ACAD version... Command: test Select Objects in Current Drawing or Xref: Select Objects in Current Drawing or Xref: Regenerating model. Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 24, 2011 Share Posted February 24, 2011 it's not really "failing", just not doing what I want...I wonder what in your code has dependency on the ACAD version... Command: test Select Objects in Current Drawing or Xref: Select Objects in Current Drawing or Xref: Regenerating model. LoL, that's a different program all together. Make sure you are actually loading the routine. Quote Link to comment Share on other sites More sharing options...
jmerch Posted February 24, 2011 Author Share Posted February 24, 2011 LMAO....WTF...I've been loading it correctly and am pretty sure I don't have any commands called TEST....but I changed this command to something else and it seems to be working now....so thank you very much Tharwat!!! And I'm still curious about my questions to you alan, just so I can understand it better. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 24, 2011 Share Posted February 24, 2011 ....but I changed this command to something else and it seems to be working now....so thank you very much Tharwat!!! Could you please post what you have changed to let routines working with your MEP cad ? Just curious about other cad versions. Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 24, 2011 Share Posted February 24, 2011 LMAO....WTF...I've been loading it correctly and am pretty sure I don't have any commands called TEST....but I changed this command to something else and it seems to be working now....so thank you very much Tharwat!!! And I'm still curious about my questions to you alan, just so I can understand it better. (defun c:Test (/ ss str) (if (and (setq ss (ssget "_X" '((0 . "MTEXT") (1 . "TEST")))) ; select mtext (/= "" (setq str (getstring T "\nSpecify string: "))) ; specify string & /= "" ) (progn ;; below steps through active selectionset (vlax-for obj (setq ss (vla-get-activeselectionset ; active selectionset (vla-get-activedocument (vlax-get-acad-object)) ) ) (vla-put-textstring obj str) ) (vla-delete ss) ; delete selection set (not acutal objects, just the selection set) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
jmerch Posted February 24, 2011 Author Share Posted February 24, 2011 Could you please post what you have changed to let routines working with your MEP cad ? Just curious about other cad versions. I was just saying I changed your C:test to something like C:test1 and it worked....so somewhere I must have a routine loaded that uses TEST for the command...other than that the last code you posted works as is. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 24, 2011 Share Posted February 24, 2011 I was just saying I changed your C:test to something like C:test1 and it worked....so somewhere I must have a routine loaded that uses TEST for the command...other than that the last code you posted works as is. Yeah.... that's it .... . Tharwat Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 24, 2011 Share Posted February 24, 2011 Please note jmerch that if your intended to use any of my routines that I have already posted for you, you should modify the first line of routines to ...... which is . ([color=red][b]/=[/b][/color] (setq new (getstring T "Enter New Text: ")) [b][color=red]""[/color][/b]) Because if a user used the routines and pressed enter instead of supporting a string , the routine would replace the found Mtexts to nil string (invisible). Tharwat Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 24, 2011 Share Posted February 24, 2011 Please note jmerch that if your intended to use any of my routines that I have already posted for you, you should modify the first line of routines to ...... which is . ([color=red][b]/=[/b][/color] (setq new (getstring T "Enter New Text: ")) [b][color=red]""[/color][/b]) Because if a user used the routines and pressed enter instead of supporting a string , the routine would replace the found Mtexts to nil string (invisible). Tharwat Look who's learning. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted February 24, 2011 Share Posted February 24, 2011 Look who's learning. Everyday I am getting odd things with Lisp. Regards Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 24, 2011 Share Posted February 24, 2011 To add: In these situations, I would stay clear of using the 1 dxf code for finding text. It's case sensitive and only searches the first 250 characters. I would avoid the use of vla-get-textstring since there is a huge bug in that it will not return a symbol properly, and instead give you a "?". 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.