teknomatika Posted March 16, 2012 Posted March 16, 2012 I have a routine, obtained, I think in the Autodesk Discussion Group, which exports autocad text to Notepad. However, I do not know why, regardless of the order of selection, the end result is always the reverse order. Can help, so that the output is correctly ordered? (defun c:T2NP (/ elist en fn fname i ss txt) (setvar "cmdecho" 0) (prompt "\n* Text file written to directory of current drawing *") (if (setq ss (ssget (list (cons 0 "TEXT")))) (progn (setq fname (getstring "\n* Enter text file name: ")) (if (= fname "") (setq fname (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)))) (setq fn (open (strcat (getvar "dwgprefix") fname ".txt") "w")) (setq i -1) (repeat (sslength ss) (setq i (1+ i)) (setq en (ssname ss i) elist (entget en) txt (cdr (assoc 1 elist))) (write-line txt fn)) (close fn))) (princ (strcat "\n* Text file " (getvar "dwgprefix") fname " has been created *")) (setvar "cmdecho" 1) (setq fn (strcat (getvar "dwgprefix") fname ".txt")) (startapp (strcat "Notepad " (chr 34) fn (chr 34))) (princ)) (prompt "\nType T2NP to invoke command") Quote
Lee Mac Posted March 16, 2012 Posted March 16, 2012 Since you are using an ssget selection method, there is no 'correct order'. The order in which the strings are written will depend on both the selection method and the order in which the Text objects were added to the drawing database. The strings are merely written as the program iterates through the selection set. If you want to order the Text objects, you will need either use a single object selection method, such as entsel, or implement a sort function, such as vl-sort, to sort the objects using a specific comparison function. 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.