LSP for Find and replace

LSP for Find and replace

burniksapwet
Enthusiast Enthusiast
2,495 Views
12 Replies
Message 1 of 13

LSP for Find and replace

burniksapwet
Enthusiast
Enthusiast

I was wondering if someone can create a find and replace lsp for us that does this steps. Thank you so much in advance once again.

Want to replace the spaces on the currently selected mtext to an enter command.

If I do and find and replace it will have to be something like this

 

Under "Find What" it will just be a single spacebar

Under "Replace  With" will be \u+000A. This is the code for replicating the enter function.

Find and Replace.gif

 

So once that hit "Relace "All" it should turn this currently selected mtext from this

Find and Replace2.gif

 

To this

Find and Replace3.gif

0 Likes
Accepted solutions (1)
2,496 Views
12 Replies
Replies (12)
Message 2 of 13

john.uhden
Mentor
Mentor

(vl-string-translate "\\P" " " str)

John F. Uhden

0 Likes
Message 3 of 13

burniksapwet
Enthusiast
Enthusiast

I'm sorry but how do I run this?

0 Likes
Message 4 of 13

john.uhden
Mentor
Mentor

My apologies.  My answer was very terse because I thought you knew a bit about AutoLisp / Visual Lisp and were looking for a find and replace function to use in your own code.  My response simply indicated that there is a Visual Lisp function that does exactly what (I think) you need.

 

Perhaps you can post the code you have so far and one of us here can show you how/where to implement the function.

John F. Uhden

0 Likes
Message 5 of 13

burniksapwet
Enthusiast
Enthusiast
That's the thing sir. I have nothing because I am not well versed with creating a .lsp. All I have is what I want the command to do. Which is to add all those "enter" command to the currently selected mtext. Sorry for the confusion. I should have mentioned that to begin with.
0 Likes
Message 6 of 13

pbejse
Mentor
Mentor
Try the attached Q&D lisp. command: mtalign
0 Likes
Message 7 of 13

m_badran
Advocate
Advocate

Try this.

 

(defun c:changespace (/ ss)
  (vl-load-com)
  (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
    ((lambda (i / e v s)
       (while (setq e (ssname ss (setq i (1+ i))))
	 (setq
	   s (vla-get-textstring (setq v (vlax-ename->vla-object e)))
	 )
	 (while	(vl-string-search " " s)
	   (setq s (vl-string-subst "\\P" " " s))
	 )
	 (vla-put-textstring v s)
       )
     )
      -1
    )
  )
  (princ)
)
0 Likes
Message 8 of 13

pbejse
Mentor
Mentor

@burniksapwet wrote:

I was wondering if someone can create a find and replace lsp for us that does this steps. Thank you so much in advance once again.

Want to replace the spaces on the currently selected mtext to an enter command.

If I do and find and replace it will have to be something like this

 

 

 


burniksapwet

 

Obviously this topic and two recent posts  are related

 

Block Attribute Text Extraction.

Text to Mtext then line up mtext in a column.

 

Hows about picked one and stick with it until its resolved, take a deep breath and describe the goal in its entirety so everybody here can provide a workable solution and not just bits & pieces.

 

Take your time.....

 

* one of fellow member informed me that what i submitted as an attachment was nowhere to be found, its just one of those days Smiley Very Happy

 

 

0 Likes
Message 9 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@burniksapwet wrote:

....

Want to replace the spaces on the currently selected mtext to an enter command.

....


Try this [lightly tested]:

 

(defun C:S2EP (/ ss n obj); = Space(s) [to] Enter(s) with Pre-selection
  (if (setq ss (ssget "_I" '((0 . "MTEXT"))))
    (repeat (setq n (sslength ss))
      (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
      (vla-put-textstring obj (vl-string-translate " " "\n" (vla-get-textstring obj)))
    ); repeat
  ); if
  (princ)
); defun

 

[By the way, @john.uhden had the (vl-string-translate) arguments reversed.  But that function does all of them, eliminating @m_badran's (while) function needed if using (vl-string-subst).]

Kent Cooper, AIA
Message 10 of 13

john.uhden
Mentor
Mentor

My apologies.

Apparently vl-string-translate can replace only an equal number of characters for another.

For example:

(vl-string-translate "123" "ABC" "lj;lABC  lkjlp329ABCs';lsdf")  will work, but

(vl-string-translate "A" "123" etc.)  will replace all "A"s with just "1"

John F. Uhden

0 Likes
Message 11 of 13

dbroad
Mentor
Mentor

@burniksapwet,

Before you post, do you do an internet search and find out if any solution similar to your needs already exists?

 

Try this from Lee-Mac to see if it meets your needs.  It appears to batch process.

 

http://www.lee-mac.com/bfind.html

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 12 of 13

burniksapwet
Enthusiast
Enthusiast

Yes I do search first. This will not work for what I need it the lsp for.

0 Likes
Message 13 of 13

burniksapwet
Enthusiast
Enthusiast

Thank you so much for the code. This is exactly what we are looking for. I appreciate the time and effort for this code. Thank you so much.

0 Likes