Jump to content

How to work with every type of text


itacad

Recommended Posts

Hello, while I was looking for ways to copy texts, I came across this topic

http://www.cadtutor.net/forum/showthread.php?87782-Are-there-a-way-copy-and-paste-via-clipboard-by-lisp

where I found "demopaste" lisp.

The lisp works with single line text...I do a simple modification (I added an asterisk)

(if (setq string (ssget "_:S" '((0 . "*TEXT"))))

so now the lisp works with single line an multi line text.

Well, there are a lot of lisp that works with texts, but very often they are limited to some types of text...it is probably very difficult to program to work on all types of text, but it is also very limiting not to be able to work for example with the attributes.

Do you have any general suggest for works with multiple type of text?

Thank you in advance

Link to comment
Share on other sites

Do you have any general suggest for works with multiple type of text?

 

this?

(ssget "_:S" '((1 . "*")))

it includes all string.. ie: Attributes, Dimension Text, Mtext, Text, etc..

Link to comment
Share on other sites

Thank you...sorry but even with this change it does not paste on the attributes yet ...

For attributes only use this.

(ssget "_:S" '((0 . "INSERT")(66 . 1)))

Link to comment
Share on other sites

Sorry again...but even with this change the lisp doesn't paste text from the clipboard over attributes...or maybe I don't understand the suggests...

Link to comment
Share on other sites

If you have multiple attributes how do you know which one to change ?

 

You need to explain a bit more what it is your trying to do.

 

A manul version hold down Ctrl double click an attribute then Ctrl+v wiil paste over the existing attribute value.

Link to comment
Share on other sites

Meanwhile, I apologize for the insistence and try to explain myself better.

As already mentioned, I use continuously lisps to copy and paste texts on various text objects...most of the text objects that I have to use are attributes.

Fortunately, there are a lot of programs that allow you to select a text and paste it somewhere in a single operation without opening the editor...if you have to do it many times you will save a lot of time, that's why I'm against the "ctrl + c / ctrl + v" solution.

Unfortunately I work a lot with frozen layers and a system to bring text from a visible layer to a frozen layer is to temporarily save it in the clipboard...

There are many lisps that save a selected text in the clipboard, but I struggle to find one that performs the second part of the operation I have to do: take the text saved in the clipboard and paste it on a selected text object (attributes included).

When I tried the lisp "demopaste", I see that it does exactly what I need with the serious limit that can not paste on the attributes, the text that it takes from the clipboard ...so I asked questions to try to correct it!

Ultimately there are a lot of lisps that capture the text of a selected text object and paste it on any other type of text object...I would like to find a lisp that skips the first part of the text selection, and takes the text directly from the clipboard and paste it on any type of text object (attributes included)...

I hope you have understood (sorry for my english)! regards!

Link to comment
Share on other sites

Look at these two lines of code picking an attribute works.

 

(setq obj (vlax-ename->vla-object (car (nentsel "\nPick "))))
(vla-put-textstring obj "ZZZZ")

 

Need to use PBE code above will have a play

(setq ans pasted text)
(setq obj (vlax-ename->vla-object (car (nentsel "\nPick "))))
(vla-put-textstring obj ans)

Edited by BIGAL
Link to comment
Share on other sites

Thank you...sorry I can't use your suggestion...maybe the solution is trivial, but I am in trouble caused by the lack of knowledge of two languages: English and Lisp!

Meanwhile, thank you, we'll see if I can solve!

Link to comment
Share on other sites

Maybe this is what you are looking for. Although as Al has stated, how do you generically determine what attribute gets changed?

(defun c:foo (/ _puttext _getclipboardtext s txt)
 ;; RJP - 04.12.2018
 ;; Copies clipboard text to selected objects
 (defun _puttext (o s)
   (cond ((vlax-property-available-p o 'textstring) (vla-put-textstring o s))
  ((vlax-property-available-p o 'textoverride) (vla-put-textoverride o s))
  ((vlax-property-available-p o 'hasattributes)
   (foreach a (vlax-invoke o 'getattributes) (vla-put-textstring a s))
  )
   )
 )
 ;; http://www.theswamp.org/index.php?topic=35577.msg408049#msg408049
 (defun _getclipboardtext (/ htmlfile result)
   (setq
     result (vlax-invoke
       (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'parentwindow)
		 'clipboarddata
       )
       'getdata
       "Text"
     )
   )
   (vlax-release-object htmlfile)
   result
 )
 (cond
   ((null (setq txt (_getclipboardtext))) (print "Nothing in clipboard"))
   ((null (setq s (ssget ":L" '((0 . "insert,*text,multileader,dimension"))))) (print "Bye.."))
   ((foreach a	(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
      (_puttext a txt)
    )
   )
 )
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

Thank you...sorry I can't use your suggestion...maybe the solution is trivial, but I am in trouble caused by the lack of knowledge of two languages: English and Lisp!

Meanwhile, thank you, we'll see if I can solve!

 

I use this all day long http://www.cadtutor.net/forum/showthread.php?93900-VT-atrribute-amp-text-editor-RLX

but wish I had the time to rewrite...

 

Like many posts here , a drawing with what it is you try to accomplish would have been nice

Link to comment
Share on other sites

Here's a version that prompts for the attribute tag to change...

(defun c:foo (/ _puttext _getclipboardtext atts opt s sel tags txt x)
 ;; RJP - 04.12.2018
 ;; Copies clipboard text to selected objects
 (defun _puttext (o s)
   (cond ((vlax-property-available-p o 'textstring) (vla-put-textstring o s))
  ((vlax-property-available-p o 'textoverride) (vla-put-textoverride o s))
  ((vlax-property-available-p o 'hasattributes)
   (if (= 1 (length (setq atts (vlax-invoke o 'getattributes))))
     (vla-put-textstring (car atts) s)
     (progn (setq tags (mapcar '(lambda (x) (vla-get-tagstring x)) atts))
	    (setq opt (apply 'strcat (mapcar '(lambda (x) (strcat x "/")) tags)))
	    (initget 0 (apply 'strcat (mapcar '(lambda (x) (strcat x " ")) tags)))
	    (setq sel (cond ((getkword (strcat "\n[" opt "] <" (car tags) ">: ")))
			    ((car tags))
		      )
	    )
	    (foreach a atts
	      (if (= sel (vla-get-tagstring a))
		(vla-put-textstring a s)
	      )
	    )
     )
   )
  )
   )
 )
 ;; http://www.theswamp.org/index.php?topic=35577.msg408049#msg408049
 (defun _getclipboardtext (/ htmlfile result)
   (setq
     result (vlax-invoke
       (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'parentwindow)
		 'clipboarddata
       )
       'getdata
       "Text"
     )
   )
   (vlax-release-object htmlfile)
   result
 )
 (cond
   ((null (setq txt (_getclipboardtext))) (print "Nothing in clipboard"))
   ((null (setq s (ssget ":L" '((0 . "insert,*text,multileader,dimension"))))) (print "Bye.."))
   ((foreach a	(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
      (_puttext a txt)
    )
   )
 )
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

As always, I thank you for your work...I tried both solutions...the one that looks more like what I need is the second one, but I' don't want to specify the attribute from keyboard, I would like the "click" on an attribute determine to paste on that attribute (and only on that)...is it possible?

Link to comment
Share on other sites

Give this a try...

(defun c:foo (/ _puttext _getclipboardtext atts opt s sel tags txt x)
 ;; RJP - 04.12.2018
 ;; Copies clipboard text to selected objects
 (defun _puttext (o s / e)
   (cond ((vlax-property-available-p o 'textstring) (vla-put-textstring o s))
  ((vlax-property-available-p o 'textoverride) (vla-put-textoverride o s))
  ((vlax-property-available-p o 'hasattributes)
   (if (= 1 (length (setq atts (vlax-invoke o 'getattributes))))
     (vla-put-textstring (car atts) s)
     (and (setq e (car (nentsel "\nPick your attribute: ")))
	  (= "ATTRIB" (cdr (assoc 0 (entget e))))
	  (vla-put-textstring (vlax-ename->vla-object e) s)
     )
   )
  )
   )
 )
 ;; http://www.theswamp.org/index.php?topic=35577.msg408049#msg408049
 (defun _getclipboardtext (/ htmlfile result)
   (setq
     result (vlax-invoke
       (vlax-get (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'parentwindow)
		 'clipboarddata
       )
       'getdata
       "Text"
     )
   )
   (vlax-release-object htmlfile)
   result
 )
 (cond
   ((null (setq txt (_getclipboardtext))) (print "Nothing in clipboard"))
   ((null (setq s (ssget ":L" '((0 . "insert,*text,multileader,dimension"))))) (print "Bye.."))
   ((foreach a	(mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
      (_puttext a txt)
    )
   )
 )
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

ohhh this is (almost) what I need!!! my last question is: is it possible with a single click to select block and attribute?

In the case of a block, when I'll use the command, I will do it directly on the right attribute...

I apologize for the continuous requests, I probably had to explain myself much better

Link to comment
Share on other sites

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