Change text

Change text

Anonymous
Not applicable
5,305 Views
22 Replies
Message 1 of 23

Change text

Anonymous
Not applicable

Hi,

You should modify ct.lsp so that it writes a text replacement directly to the command line. Something like trc.lsp. Only this (txtfind "Ĺ" "Š") should be passed directly to the function when running lisp. So automatic text replacement should be done.

0 Likes
Accepted solutions (2)
5,306 Views
22 Replies
Replies (22)
Message 2 of 23

hak_vz
Advisor
Advisor

@Anonymous 

I know you have good knowledge of writting autolisp programs, so why don't you try to write it yourself and then ask for help if really needed. This is not complex stuff to do.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 23

pbejse
Mentor
Mentor

@Anonymous wrote:

Hi,

You should modify ct.lsp so that it writes a text replacement directly to the command line. Something like trc.lsp. Only this (txtfind "Ĺ" "Š") should be passed directly to the function when running lisp. So automatic text replacement should be done.


Explain yourself @Anonymous ,

You want to be prompted for "Enter the old text: " and "Enter the new text: " on the command prompt similar to the other lisp. 

(defun c:txtfind ( / OldTxt NewTxt)	
	(if (and
	      (setq OldTxt (getstring T "\nEnter the old text: "))
	      (setq NewTxt (getstring T "\nEnter the new text: "))
	      (vl-every '(lambda (v)
			   (/= v "")) (list OldTxt NewTxt))
	      )
	  (txtfind OldTxt NewTxt)
	  )
  )

is this all there is to your request? Are you wanting something else entirely? 

 

HTH

 

0 Likes
Message 4 of 23

Anonymous
Not applicable

I've been trying to do this, but I'm failing.

0 Likes
Message 5 of 23

Anonymous
Not applicable

That's ok, but it should make a replacement automatically. No need to type in the command line. So, by running the script, the text should change automatically.

0 Likes
Message 6 of 23

hak_vz
Advisor
Advisor

What you need to do is import text as it is, and after some text entity is creates instantly run a script that will test and make changes for characters to be changed. I know you are reading your GML file. So when element is created run a script. 

 

(defun mytest ()
(txtfind "Ĺ " "Š")
(txtfind "š" "š")
(txtfind "Ä" "Đ")
(txtfind "Ä‘" "đ")
(txtfind "ÄŚ" "Č")
(txtfind "ÄŤ" "č")
(txtfind "Ć" "Ć")
(txtfind "ć" "Ć")
(txtfind "Ĺ˝" "Ž")
(txtfind "Ĺľ" "ž")
)

this should be changed to work on last created test entity. And to do that you don't need complex script as one you have attached.

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 23

Sea-Haven
Mentor
Mentor

It is possible to do a reactor using a 1st character as a trigger to your change text, so if we looked at the simple newtext oldtext we would type something like.

 

"1NEWTEXT-OLDTEXT" on command line and it would ask select text. What happens is you will get an error

 

No command 1NEWTEXT-OLDTEXT

 

So trap the error check that its a 1 in front pull apprt the two strings then ask for pick.

 

I have this for Fillet Circle F100 C345 etc 

 

I have attached the code if you want to have  ago at doing something.

 

; Fillet rad uses Frad eg f100 pulls the 100 from the F and then runs fillet
; because its a error check use 123-45 where - is decimal point = 123.45
; BY Alan H 2019
; Thanks to Lee-mac for solving some problems

(   (lambda nil
        (vl-load-com)
        (foreach obj (cdar (vlr-reactors :vlr-command-reactor))
            (if (= "fillet-reactor" (vlr-data obj))
                (vlr-remove obj)
            )
        )
        (vlr-command-reactor "fillet-reactor" '((:vlr-unknowncommand . fillet-reactor-callback)))
    )
)

(defun filletrad ( / rad)
(setq rad (distof (substr com 2) 2))
            (if (<= 0.0 rad)
              (progn        
              (setvar 'filletrad rad)
              (vla-sendcommand fillet-reactor-acdoc "_.fillet ")
              )
              ) 
)

(defun fillet-reactor-callback ( obj com )
(setq com (vl-string-translate "-" "." (strcase (car com))))
    (cond   
        (   (and
            (wcmatch com "~*[~F.0-9]*")
            (wcmatch com "F*")
            (wcmatch com "~F*F*")
            (wcmatch com "~*.*.*")
            ) ; and
            (filletrad) 
         ) 
    ) ; master cond
) ; defun

(or fillet-reactor-acdoc
    (setq fillet-reactor-acdoc (vla-get-activedocument (vlax-get-acad-object)))
)

 

 

 

 

0 Likes
Message 8 of 23

pbejse
Mentor
Mentor

@Anonymous wrote:

That's ok, but it should make a replacement automatically. No need to type in the command line. So, by running the script, the text should change automatically.


I'm guessing you meant not typing the old and new pattern on the command prompt.

All calls to (txtfind ol nt) At the bottom end of  trc.lsp file will run when the file is loaded, now if you want to run the find and replace thing again on an already opened, you can either load the lisp again or add the code below at the end of the file, and type txtfind at the command prompt.

command: txtfind <-- [ "the text should change automatically."

(defun c:txtfind ()
  (foreach itm '(("Ĺ " "Š")
		 ("š" "š")
		 ("Ä" "Đ")
		 ("Ä‘" "đ")
		 ("ÄŚ" "Č")
		 ("ÄŤ" "č")
		 ("Ć" "Ć")
		 ("ć" "Ć")
		 ("Ĺ˝" "Ž")
		 ("Ĺľ" "ž")
		)
    (txtfind (Car itm) (cadr itm))
  )(princ)
)

 or as per @hak_vz  suggestion use an external source file for the pattern. That way you can add new patterns to find and replace

(defun c:txtfind ( / f opf a)
	(if (setq f (findfile "patterns.txt")) ;<-- you can hard code the location here
	  (progn
	    (setq opf (open f "r"))
	    (while (setq a (read-line opf))
		(eval (read a))
	      )
	    (close opf)
	    )
	  )
  (princ)
  )

and this as "patterns.txt" [ save this file within reach of SFSP or change the path on the code

(txtfind "Ĺ " "Š")
(txtfind "š" "š")
(txtfind "Ä" "Đ")
(txtfind "Ä‘" "đ")
(txtfind "ÄŚ" "Č")
(txtfind "ÄŤ" "č")
(txtfind "Ć" "Ć")
(txtfind "ć" "Ć")
(txtfind "Ĺ˝" "Ž")
(txtfind "Ĺľ" "ž")

 

Even better is @Sea-Haven  suggestion of using reactors, no typing of command, but its always lurking on the background. To get into that discussion would mean to open a can of worms and i'm not doing that 🙂

 

HTH

 

 

0 Likes
Message 9 of 23

Anonymous
Not applicable

The problem occurs when you try to use lispa (automatically) to change letters that are not letters of the English alphabet (diacritical marks). So, by typing in the command line (txtfind "Ĺ" "Š") the thing works, but automatically from lisp it doesn't work.

0 Likes
Message 10 of 23

Anonymous
Not applicable
Thanks, but this seems very complicated to me. Although a good idea.
0 Likes
Message 11 of 23

Anonymous
Not applicable
The same problem occurs as I explained in a previous post.
0 Likes
Message 12 of 23

pbejse
Mentor
Mentor

@Anonymous wrote:

The problem occurs when you try to use lispa (automatically) to change letters that are not letters of the English alphabet (diacritical marks). So, by typing in the command line (txtfind "Ĺ" "Š") the thing works, but automatically from lisp it doesn't work.


That doesn't sound right at all.

How can this

(txtfind "Ĺ" "Š") 

be different from this

(defun c:dothis ()(txtfind "Ĺ " "Š"))

Post a sample drawing showing at least two of the targeted pattern, and we will see what's the deal.

 

0 Likes
Message 13 of 23

hak_vz
Advisor
Advisor

@Anonymous wrote:

The problem occurs when you try to use lispa (automatically) to change letters that are not letters of the English alphabet (diacritical marks). So, by typing in the command line (txtfind "Ĺ" "Š") the thing works, but automatically from lisp it doesn't work.


@Anonymous  What is the difference ?

 

(defun c:func nil (func))
(defun func nil (princ "\nFunc do some work")(princ))
(func)
(c:func)

 

With defun we define a function. if we add c: in front of its name then this function becomes autocad command.

Sorry, but there is a lots of stuff to learn (and this are the basics) .

 

(setq txt "šašaŠAŠA PAPA MAŠA šaŠA")
(while (> (vl-string-position (ASCII "Š") txt) 0)(setq txt (vl-string-subst "*" "Š" txt)))

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 14 of 23

Anonymous
Not applicable

Here I am sending you the whole procedure shown in the image. I don't know what I'm doing wrong.

0 Likes
Message 15 of 23

Anonymous
Not applicable
It's all clear to me, but it doesn't seem to be a problem.
0 Likes
Message 16 of 23

hak_vz
Advisor
Advisor

@Anonymous 

It is as simple as putting (textfind ) functions at the end of your function that loads text form gml, but not inside a loop but before function end. It will create entites you want and then make replacements to whole drawing. There will not be a need to run each function separately

 

(
.....
(
loop to read from gml file and create text entities 

)
......
(txtfind "Ĺ " "Š")
(txtfind "š" "š")
(txtfind "Ä" "Đ")
(txtfind "Ä‘" "đ")
(txtfind "ÄŚ" "Č")
(txtfind "ÄŤ" "č")
(txtfind "Ć" "Ć")
(txtfind "ć" "Ć")
(txtfind "Ĺ˝" "Ž")
(txtfind "Ĺľ" "ž")
(princ)
)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 17 of 23

Anonymous
Not applicable
Unfortunately it doesn't work. I've tried this before, but I didn't succeed. As I explained in the previous post in the image.
0 Likes
Message 18 of 23

pbejse
Mentor
Mentor

@Anonymous wrote:

Here I am sending you the whole procedure shown in the image. I don't know what I'm doing wrong.


Is it too much to ask for a drawing file? thing is, we believe you when you say it doesnt work and you dont know what you are doing wrong. But we need to see it for ourselves. 

 

Because it does work when running the code with the same scenarion on my workstaion. maybe there's more to this and we are not seeing it.

 

 

0 Likes
Message 19 of 23

Anonymous
Not applicable

In the attachment I'm sending you drawing file. If you succeed please describe the procedure to me. I'm trying the way I described on image.png.

0 Likes
Message 20 of 23

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

In the attachment I'm sending you drawing file. If you succeed please describe the procedure to me. I'm trying the way I described on image.png.


You are right Daniel. 🙂

Short of writing a code that reads unicode and back. the best bet is to use toolpalette.

On the attached file "patterns.txt", copy the contents and pasted tool palette "command string"

 

You can do the whole thing [ toolpalette.png ]  or one per. [ single.png]

 

EDIT: If you are having issues with the attached text file, paste the patterns directly on the tool paltette.

 

HTH

 

 

 

 

0 Likes