Jump to content
ILoveMadoka

Getstring & Pasteclip Question

Recommended Posts

ILoveMadoka

I need to be able to <CTRL> V a text string from my clipboard in response to a Getstring prompt.

 

(Setq X (Getstring T "\nEnter Name:"))

Currently, if I <CTRL> C, it pastes the text and executes a carriage return. <unwanted>

 

If i first pick in the Command line and then press <CTRL> C, it pastes the text but leaves me on the command line (Which is what I need)

 

Is there a way to paste a text string (from the clipboard) i response to the prompt without the return??

 

Share this post


Link to post
Share on other sites
Lee Mac

I'm not sure that I fully understand your requirements, or why you wouldn't read the clipboard content directly, but perhaps issuing (textscr) to switch focus to the command-line prior to issuing the getstring prompt may offer the solution you are after.

Edited by Lee Mac

Share this post


Link to post
Share on other sites
Grrr

Lee, I understand that OP wants to prompt for a string (as default) and also including the option to paste the content from clipboard.

So I find this one suitable for the task.

Share this post


Link to post
Share on other sites
ILoveMadoka

I have a text string that I am selecting which has a backslash (every time).

I use this text to create a view which will have the same text but I have to remove the \ since it is an invalid character.

U replace the "\" with a space.

This is crude and simple but it works. I am doing these steps hundreds of times and I am simply trying to streamline the process.

 

I have to select the text string in advance. I highlight the text and press <CTRL> C before running this.

 

(defun C:VC ()
 (prompt "\nCreate View Window")
	(Setq VName (Getstring T "\nEnter View Name:")) ; I paste the preselected text here, on the command line [picking in the command line first]
	(Setq PT1 (getpoint "\nPick First Point of Window:"))
	(Setq PT2 (getpoint "\nPick Second Point of Window:"))
(command "-View" "Window" VName PT1 PT2)
(princ))

 

I had to change my DYNMODE to 0 due to the CopyClip issue...

 

Now, it would be awesome to simply select the the text string (entsel), remove the "\" in lisp

and have lisp generate the valid view name and use that in the view creation step.

I will probably do that in time but this will work for my immediate and urgent need.

 

There is almost always a %%u as a prefix in the text but the <CTRL> C ignores that.

 

Hope that clears up what I'm trying to do...

Share this post


Link to post
Share on other sites
Lee Mac

Try the following:

(defun c:vc ( / cmd ent pt1 pt2 str )
    (while
        (not
            (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect text containing view name: ")))
                (cond
                    (   (= 7 (getvar 'errno))
                        (prompt "\nMissed, try again.")
                    )
                    (   (null ent))
                    (   (/= "TEXT" (cdr (assoc 0 (entget ent))))
                        (prompt "\nThe selected object is not single-line text.")
                    )
                    (   (= "" (setq str (cleanstring (cdr (assoc 1 (entget ent))))))
                        (prompt "\nThe text content is not valid for use as a view name.")
                    )
                    (   (and (setq pt1 (getpoint "\nSpecify first point of window: "))
                             (setq pt2 (getcorner pt1 "\nSpecify opposite point of window: "))
                        )
                        (setq cmd (getvar 'cmdecho))
                        (setvar 'cmdecho 0)
                        (vl-cmdf "_.-view" "_w" str "_non" pt1 "_non" pt2)
                        (setvar 'cmdecho cmd)
                    )
                )
            )
        )
    )
    (princ)
)
(defun cleanstring ( str )
    (while (wcmatch str "*%%[OoUu]*")
        (foreach c '("O""o""U""u") (setq str (vl-string-subst "" (strcat "%%" c) str)))
    )
    (vl-string-trim " " (vl-string-translate "\\<>/?\":;*|,=`" "               " str))
)
(princ)

 

Edited by Lee Mac

Share this post


Link to post
Share on other sites
ILoveMadoka

Lee,

 

That works perfectly!

Once again you are Totally Awesome!!

 

Thank you so very much Sir!!

 

ps: I really do appreciate it!

Share this post


Link to post
Share on other sites
Lee Mac

You're welcome! 🍺

Share this post


Link to post
Share on other sites
BIGAL

Perhaps another way and like Lee read the value out of the clipboard then I would use my getvals3.lsp  DCL with  a 1 line "Please enter string", the clipboard value would appear as a default value in the dcl or just type in a new string. Both options covered. I have posted getvals3.lsp many time you should be able to find it. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×