Jump to content

Getstring & Pasteclip Question


Recommended Posts

Posted

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??

 

Posted (edited)

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
  • Like 1
Posted

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.

Posted

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...

Posted (edited)

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
Posted

Lee,

 

That works perfectly!

Once again you are Totally Awesome!!

 

Thank you so very much Sir!!

 

ps: I really do appreciate it!

Posted

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. 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...