Tharwat Posted July 1, 2010 Posted July 1, 2010 Hi Suppose that I have a file called ( try.txt ) and it is consist of 10 text lines. How could I chose line number 5 with the function read-line ... ???? (defun c:try (/ sset tx) (setq sset (open "c:/try.txt" "r")) (setq tx (read-line sset)) (command "_.text" pause "" "" tx "") (close sset) (princ) ) The above mentioned program will get the first line, But I need to select the fifth one .... Regards Tharwat Quote
fuccaro Posted July 1, 2010 Posted July 1, 2010 Read 4 lines and do nothing with (repeat four times the read-line). Read the 5th line and use it as you just did. SSET is a pretty unusual filename... Quote
alanjt Posted July 1, 2010 Posted July 1, 2010 Use a counter... (defun _FileLine2Text (file num pt / fo line) (if (findfile file) ((lambda (i) (setq fo (open file "R")) (while (and (setq line (read-line fo)) (> num (setq i (1+ i))))) (close fo) (if (eq num i) (entmakex (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 line) (cons 10 (trans pt 1 0)) ) ) ) ) 0 ) ) ) Quote
alanjt Posted July 1, 2010 Posted July 1, 2010 Read 4 lines and do nothing with (repeat four times the read-line). Read the 5th line and use it as you just did. SSET is a pretty unusual filename... Actually, I like that idea better. It's limitation is that if you say 100 and there's only 2 lines of text, it will continue to read until the repeat process is over. Quote
Tharwat Posted July 1, 2010 Author Posted July 1, 2010 Thanks Gentle men. Here is the combination of the tow answers ...... What you think ???? (defun c:try (/ sset tx pt) (setq sset (open "c:/try.txt" "r")) (repeat 5 (setq tx (read-line sset))) (setq pt(getpoint"\nText location:")) (entmakex (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 tx) (cons 10 (trans pt 1 0)) ) ) (princ) ) It is really wonderful My great thanks Tharwat Quote
fuccaro Posted July 1, 2010 Posted July 1, 2010 I can not try it, but for sure it is more elegant. Entmake-ing text is at least 10 times better than creating it with Command. People use to use the name SSET for selection sets... Quote
Tharwat Posted July 1, 2010 Author Posted July 1, 2010 I can not try it, but for sure it is more elegant. Entmake-ing text is at least 10 times better than creating it with Command.People use to use the name SSET for selection sets... I do agree with you, And I changed the name of the file which is better that the name of sset to fname. And in regard to the entmake function, I have got used to it due to the best performance that it does. And using commnad frequently in Lisp files would reduce the Autocad movements. Thanks a lot Tharwat Quote
alanjt Posted July 1, 2010 Posted July 1, 2010 I'd at least add a little error checking to make sure you picked the point. (defun c:Try (/ sset tx pt) (if (findfile "c:/try.txt") (progn (setq sset (open "c:/try.txt" "r")) (repeat 5 (setq tx (read-line sset))) (if (and (eq (type tx) 'STR) (setq pt (getpoint "\nText location : "))) (entmakex (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 tx) (cons 10 (trans pt 1 0)) ) ) ) ) (alert "FILE NOT FOUND!") ) (princ) ) Quote
Tharwat Posted July 2, 2010 Author Posted July 2, 2010 I'd at least add a little error checking to make sure you picked the point. Thanks Alanjt ... That was nice......... And I added one more alert if Text couldn't be found. (defun c:Try (/ [color=Red]fname[/color] tx pt) (if (findfile "c:/try.txt") (progn (setq [color=Red]fname[/color] (open "c:/try.txt" "r")) (repeat 5 (setq tx (read-line [color=Red]fname[/color]))) (if (and (eq (type tx) 'STR) (setq pt (getpoint "\nText location : "))) (entmakex (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 tx) (cons 10 (trans pt 1 0)) ) ) [color=Red](alert "TEXT NOT EXISTED")[/color] ) ) (alert "FILE NOT FOUND!") ) (princ) ) Many Thanks Tharwat Quote
alanjt Posted July 2, 2010 Posted July 2, 2010 You'll need to break up the and statement. Right-click when it's time to pick a point and you'll get the "TEXT NOT EXISTED" alert. Quote
Tharwat Posted July 2, 2010 Author Posted July 2, 2010 Hello. I have changed the and to equal to none, But it announce an error. (defun c:Try (/ fname tx pt) (if (findfile "c:/try.txt") (setq fname (open "c:/try.txt" "r")) (alert [color="Red"]"FILE NOT FOUND!"[/color]));;[color="red"] This alert is suppressed to command line[/color] (repeat 16 (setq tx (read-line fname)));;; [color="Red"]Text is not avaliable in reallity[/color] (if ([color="Red"]eq tx nil[/color]);;; [color="Red"]What's the right action in here[/color] (progn (alert "TEXT NOT EXISTED")[color="red"] This alert is suppressed to command line[/color] (princ)) (setq pt (getpoint "\nText location : ")) ) (entmakex (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 tx) (cons 10 (trans pt 1 0)))) (princ) ) Thanks Tharwat Quote
alanjt Posted July 2, 2010 Posted July 2, 2010 (defun c:Try (/ fo tx pt) (if (findfile "c:/try.txt") (progn (setq fo (open "c:/try.txt" "r")) (repeat 5 (setq tx (read-line fo))) (close fo) (if (eq (type tx) 'STR) (if (setq pt (getpoint "\nText location : ")) (entmakex (list '(0 . "TEXT") (cons 40 (getvar 'textsize)) (cons 1 tx) (cons 10 (trans pt 1 0)) ) ) ) (alert "Text line empty.") ) ) (alert "File not found.") ) (princ) ) 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.