pvsvprasad Posted October 9, 2016 Posted October 9, 2016 (edited) Dear Masters, I have one Lisp, with help of my existing lisp generating notepad file. i need CSV file format instead of notepad as a shown image format. Kindly make a modification in my existing Lisp. ;; gc:distinct (gilles chanteau) ;; Suprime tous les doublons d'une liste ;; ;; Argument ;; l : une liste (defun gc:distinct (l) (if l (cons (car l) (gc:distinct (vl-remove (car l) l))) ) ) (defun l-coor2l-pt (lst flag / ) (if lst (cons (list (car lst) (cadr lst) (if flag (+ (if (vlax-property-available-p ename 'Elevation) (vlax-get ename 'Elevation) 0.0) (caddr lst)) (if (vlax-property-available-p ename 'Elevation) (vlax-get ename 'Elevation) 0.0) ) ) (l-coor2l-pt (if flag (cdddr lst) (cddr lst)) flag) ) ) ) (defun c:ptdef2notepad ( / js dxf_cod mod_sel n lremov str_sep oldim ename l_pt l_pr pr l_x l_y tmp1 f_openx tmp2 f_openy) (princ "\nSelect model object for filtering: ") (while (null (setq js (ssget "_+.:E:S" (list '(0 . "*LINE,POINT,ARC,CIRCLE,ELLIPSE,INSERT") (cons 67 (if (eq (getvar "CVPORT") 1) 1 0)) (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model")) ) ) ) ) (princ "\nIsn't an available object!") ) (vl-load-com) (setq dxf_cod (entget (ssname js 0))) (foreach m (foreach n dxf_cod (if (not (member (car n) '(0 67 410 8 6 62 48 420 70))) (setq lremov (cons (car n) lremov)))) (setq dxf_cod (vl-remove (assoc m dxf_cod) dxf_cod)) ) (initget "Single All Manual") (if (eq (setq mod_sel (getkword "\nSelect mode, [single/All/Manual]<Manual>: ")) "Single") (setq n -1) (if (eq mod_sel "All") (setq js (ssget "_X" dxf_cod) n -1) (setq js (ssget dxf_cod) n -1) ) ) (setq str_sep " " ;-> **** YOU CAN CHANGE THIS STRING BY WHAT YOU WONT ! **** <- oldim (getvar "dimzin") ) (setvar "dimzin" 0) (repeat (sslength js) (setq ename (vlax-ename->vla-object (ssname js (setq n (1+ n))))) (setq l_pr (list 'StartPoint 'EndPoint 'Center 'InsertionPoint 'Coordinates 'FitPoints)) (foreach pr l_pr (if (vlax-property-available-p ename pr) (setq l_pt (if (or (eq pr 'Coordinates) (eq pr 'FitPoints)) (append (if (eq (vla-get-ObjectName ename) "AcDbPolyline") (l-coor2l-pt (vlax-get ename pr) nil) (if (and (eq pr 'FitPoints) (zerop (vlax-get ename 'FitTolerance))) (l-coor2l-pt (vlax-get ename 'ControlPoints) T) (l-coor2l-pt (vlax-get ename pr) T) ) ) l_pt ) (append (l-coor2l-pt (vlax-get ename pr) T) l_pt) ) ) ) ) ) (setq l_x (gc:distinct (mapcar '(lambda (x) (rtos (/ x 1.0) 2 2)) (vl-sort (mapcar 'car l_pt) '<)))) ;-> **** YOU CAN CHANGE UNIT AND PREC (rtos x unit prec) ! **** <- (setq l_y (gc:distinct (mapcar '(lambda (x) (rtos (/ x 1.0) 2 2)) (vl-sort (mapcar 'cadr l_pt) '<)))) ;-> **** YOU CAN CHANGE UNIT AND PREC (rtos x unit prec) ! **** <- (setq tmp1 (vl-filename-mktemp "tmp_x.csv") f_openx (open tmp1 "w") ) (write-line (apply 'strcat (mapcar '(lambda (x) (strcat x str_sep)) l_x)) f_openx) (close f_openx) (startapp "notepad" tmp1) (setq tmp2 (vl-filename-mktemp "tmp_y.csv") f_openy (open tmp2 "w") ) (write-line (apply 'strcat (mapcar '(lambda (x) (strcat x str_sep)) l_y)) f_openy) (close f_openy) (startapp "notepad" tmp2) (setvar "dimzin" oldim) (prin1) ) Please find sample drawing and sample CSV Format. Thanking you, Best regards. Points export to CSV.dwg Edited October 11, 2016 by pvsvprasad Quote
BIGAL Posted October 10, 2016 Posted October 10, 2016 The code you posted does not really match the question. To just export the "POINTS" to a csv is just so short. (defun c:ptscsv ( / ss fo fname x) (setq ss (ssget "X" '((0 . "point")))) (setq fo (open "c:\\Temp\\tmp_Pts.csv" "W")) ; change directory name to suit. (repeat (setq x (sslength ss)) (setq pts (ssname ss (setq x (- x 1)))) (setq pt (assoc 10 (entget pts))) (write-line (strcat (rtos (cadr pt) 2 3) "," (rtos (caddr pt) 2 3)) fo) ) ; repeat (close fo) ) Quote
pvsvprasad Posted October 10, 2016 Author Posted October 10, 2016 (edited) Dear sir, Thank you for your kind reply and lisp. while running your lisp showing error as attached picture. kindly find. Thanking you, Best regards. Edited October 10, 2016 by pvsvprasad Quote
StevJ Posted October 10, 2016 Posted October 10, 2016 I believe the .csv file must already exist before an attempt is made to write to it. Steve Quote
pvsvprasad Posted October 10, 2016 Author Posted October 10, 2016 Dear sir, Thank you for your kind reply.without already exist any idea for develop and open CSV file automatically? i found the CSV file in Temp directory and format of points as mentioned in attached pic. kindly find. it is different than Post#1 (i.e no need doubled coordinates values). please find Post#1 sample pic.kindly Modify Post#1 lisp. Thanking you, Best regards. Quote
BKT Posted October 10, 2016 Posted October 10, 2016 If you are now using BIGAL's code you don't need to create a csv file first - The code will do that. I do not see any "doubled coordinate values" in your attached image. Could you explain further what you're trying to get from this? BKT Quote
pvsvprasad Posted October 10, 2016 Author Posted October 10, 2016 If you are now using BIGAL's code you don't need to create a csv file first - The code will do that. I do not see any "doubled coordinate values" in your attached image. Could you explain further what you're trying to get from this? BKT Dear Sir, Thank you for your kind reply. please find attached image of actually BIGAL's code produced and my requirement format. in my required format Values are in Ascending order. so kindly modify the existing lisp to produce required format of X, Y Coordinates. Thanking you, Best Regards. Quote
BIGAL Posted October 11, 2016 Posted October 11, 2016 Excel oh yeah a command called Data sort. To write a sort routine is just not worth it. I though it was obvious that as a example code I had to put the answer some where C:\temp the remark even says change. Rtos 2 3 the "3" is number of decimal places you can have more or less. Are you asking for the bounding box co-ords not actually all the points ? Dont need excel for that. Quote
pvsvprasad Posted October 11, 2016 Author Posted October 11, 2016 Excel oh yeah a command called Data sort. To write a sort routine is just not worth it. I though it was obvious that as a example code I had to put the answer some where C:\temp the remark even says change. Rtos 2 3 the "3" is number of decimal places you can have more or less. Are you asking for the bounding box co-ords not actually all the points ? Dont need excel for that. Yes sir, i need sorting. with help of my example code at Post#1, developing like 0.00 600.00 1200.00 2200.00 for X coordinates sorted with space separator side by side and same as developed for Y coordinates sorting too. so now i need modification as below one under one coordinate instead of "side by side and space separator": 0.00 600.00 1200.00 2200.00 and same as Y coordinates too. by CSV file as shown in Post#1 image. if not possible by CSV file format kindly modify for same notepad file format by example lisp with one under one coordinate value instead of "side by side and space separator". Thanking you, with best regards. Quote
BIGAL Posted October 11, 2016 Posted October 11, 2016 So what you want is the 4 corners of the box ?? Quote
pvsvprasad Posted October 11, 2016 Author Posted October 11, 2016 So what you want is the 4 corners of the box ?? Dear sir, Why box is created? no need box. i need insertion points with sorting. like a attached pic. please find. for example "0" is repeated 4 times for X coordinates. but i need single time only instead of multiple or duplicates. like a sorting points. please run my Post#1 code. with help of that code produces in note pad as 0.00 600.00 1200.00 2200.00. i need exactly this sorting format. but one under one value like : 0.00 600.00 1200.00 2200.00 Thanking you, with best regards. 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.