kenji9727 Posted June 14, 2023 Posted June 14, 2023 Hello guys, would like to ask for your help that I'd like to have a lisp that can let me extract data from multiple lines which then the data can be exported into a txt file. Would like to export the angle of the line ( the angle extracted should be in the form of degree minute second), the distance and also the end point coordinate( Y & X) in this order. Thank you very much. I am struggling with this problem! Quote
Emmanuel Delay Posted June 15, 2023 Posted June 15, 2023 (edited) Sure, like this? Command EAL (for Export All Lines) Remove the lines that write the start point if you don't need them It creates and writes to "C\mytextfile.txt" (defun txt2file (textlines / line filename f) (setq filename "C:\\mytextfile.txt") ;; set to whatever you want (setq f (open filename "w")) (foreach line textlines (WRITE-LINE line f) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; EAL for Export All Lines (defun c:eal ( / ss i ang len p1 p2 x1 x2 y1 y2 ent ent_ textlines) (princ "\nSelect lines: ") (setq ss (ssget (list (cons 0 "LINE")))) ;;;; or use next line to absolutely auto select all lines ;;(setq ss (ssget "_X" (list (cons 0 "LINE")))) (setq i 0) (setq textlines (list "Angle; Length; Start X; Start Y; End X; End Y")) (repeat (sslength ss) (setq ent (ssname ss i)) (setq ent_ (entget ent)) (setq p1 (cdr (assoc 10 ent_ ))) (setq p2 (cdr (assoc 11 ent_ ))) (setq ang (angle p1 p2)) (setq len (distance p1 p2)) (setq textlines (append textlines (list (strcat (angtos ang 1 4) "; " (rtos len 2 3) "; " ;; that 3 is the number of decimals, feel free to put anothe value there (don't touch the 2) (rtos (nth 0 p1) 2 3) "; " (rtos (nth 1 p1) 2 3) "; " (rtos (nth 0 p2) 2 3) "; " (rtos (nth 1 p2) 2 3) )))) (setq i (+ i 1)) ) ;; save string to file (txt2file textlines) (princ) ) Edited June 15, 2023 by Emmanuel Delay Quote
BIGAL Posted June 15, 2023 Posted June 15, 2023 Are you trying to send to Excel if so save to a .CSV file. Depending on where you are in world use ";" or ",". Quote
mhupp Posted June 16, 2023 Posted June 16, 2023 2 hours ago, BIGAL said: Are you trying to send to Excel if so save to a .CSV file. Depending on where you are in world use ";" or ",". text files are treated the same as csv files in excel if they are formatted the same. you can even drag and drop them in. Quote
Steven P Posted June 16, 2023 Posted June 16, 2023 8 hours ago, mhupp said: text files are treated the same as csv files in excel if they are formatted the same. you can even drag and drop them in. It's been a while since I worked a lot with excel - forgotten a lot - but can you paste CSV formatted data from the clipboard instead of drag and drop a file? Excel is quite good at recognising what you want to do Quote
Emmanuel Delay Posted June 16, 2023 Posted June 16, 2023 1 hour ago, Steven P said: It's been a while since I worked a lot with excel - forgotten a lot - but can you paste CSV formatted data from the clipboard instead of drag and drop a file? Excel is quite good at recognising what you want to do The best way is still to open Excel, then Import data. Because ... Excel has the horrible habit to assume cell format. Half of the Entity handles (assuming you export them) are turned into numbers, "14E6" is seen as 14 million; some are turned into dates, ... Get Data from file has the best chance of this problem not occuring 1 Quote
marko_ribar Posted June 16, 2023 Posted June 16, 2023 @Emmanuel Delay Subroutine : txt2file has to have line : (close f) at the end for proper working... Have you tested your code? Quote
BIGAL Posted June 17, 2023 Posted June 17, 2023 Again "Are you trying to send to Excel ?" Can write direct to excel cells. 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.