MJLM Posted February 15, 2014 Posted February 15, 2014 Is it possible to read an entire file of simple txt (ascii) holding many lines of data produced from a while loop into the clipboard? I ve found a routine that when given a string it will copy it into the clipboard. Problem is, how can I select the entire file (all lines) an put it in one variable and paste it into the clipboard? Or is there an other way? I know the read-line command but this reads only one line, as far as I know... Quote
MSasu Posted February 15, 2014 Posted February 15, 2014 You may want to check the DOS_CLIPBOARD function from DOSLib pack. Quote
Snownut Posted February 15, 2014 Posted February 15, 2014 its true read-line only reads one line at a time, if used in conjunction with a while loop and strcat you can read an entire text file and have be represented by one variable. (caution on 255 character length limit) Quote
MJLM Posted February 15, 2014 Author Posted February 15, 2014 make sense but I think this way the contents in the clipboard will be one straight lengthy line. My intent is to have it as 1 2 4 20U 2 3 4 5N 3 4 4 5W etc... each line with a carriage return. Is it possible with read-line as you said? Quote
Snownut Posted February 15, 2014 Posted February 15, 2014 Instead of creating a variable with a single line of the entire text file, you could create a list variable, with each item in the list being one line of the text file. (setq file (open filename "r")) (while (setq tline (read_line file)) ;this will stop at end of file (setq fileL (cons tline fileL)) ) (close file) (setq fileL (reverse fileL)) Quote
cwake Posted February 15, 2014 Posted February 15, 2014 It is possible... yes. And to separate each "line" of text you would... (setq clipboardtxt (strcat clipboardtxt line "\n")) From memory, I don't think you'll find a character limit problem either. That only applies to the TEXT entity, not the ability of a symbol to hold the string. I am puzzled why you would want to though. If the data was coming from AutoCAD, being able to paste it elsewhere is handy. But when from a file? I have text editors to do that sort of thing. But it is possible. Quote
MJLM Posted February 15, 2014 Author Posted February 15, 2014 Sorry I may have not explained it the way I should. I already have a while loop creating on each pass a line just like I wrote above. I get the file full of lines alright but instead on manually copying pasting the whole text from this file to an other software (pron to error process), I though I could have the lines instead of a file, in the clipboard. After experimenting a bit I managed to do it as you say cwake. Command (setq clipboardtxt (strcat clipboardtxt line "\n")) did the trick for me. Thank you guys for your help. Quote
irneb Posted February 16, 2014 Posted February 16, 2014 Sorry I may have not explained it the way I should. I already have a while loop creating on each pass a line just like I wrote above. I get the file full of lines alright but instead on manually copying pasting the whole text from this file to an other software (pron to error process), I though I could have the lines instead of a file, in the clipboard. After experimenting a bit I managed to do it as you say cwake. Command (setq clipboardtxt (strcat clipboardtxt line "\n")) did the trick for me. Thank you guys for your help. You might want to optimize that a bit. Since AutoLisp uses a immutable string (same as DotNet does) it might become slow when you've got 100's or 1000's of lines to concatenate together. This is because every time you concatenate a new string variable is actually created - the old one (or two) are never changed (the very definition of immutable). There are 2 ways you can go about this: Add each line to a list and then use apply to concatenate the entire list into one string in one go, but then since read-line throws away the "\n" character at the end of each line your concatenated string is then all on one single line. Or read the entire file into a string in one go, I'd go with the VBScript library's FileSystemObject and read the entire file into a string object. Like I did in this post: http://www.theswamp.org/index.php?topic=43151.msg483767#msg483767 Quote
irneb Posted February 16, 2014 Posted February 16, 2014 (caution on 255 character length limit) From memory, I don't think you'll find a character limit problem either. That only applies to the TEXT entity, not the ability of a symbol to hold the string.There is a limit, but it's quite a distance away from 256 characters:http://forums.augi.com/showthread.php?133549-What-is-the-real-maximum-string-length&p=1145258&viewfull=1#post1145258 Quote
BIGAL Posted February 17, 2014 Posted February 17, 2014 What about create mtext and pick the one object ? Quote
Recommended Posts
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.