好的,可能是不同的方法,没有自动但手动选择
- ; Dimensions to CSV - written for CadTutor by RLX on 7 th of july 2017
- ; Purpose is to create csv file with format :
- ; --------------------
- ; | A | B |
- ; --------------------
- ; | Dim1 | 100 |
- ; --------------------
- ; | | 110 |
- ; --------------------
- ; | Dim2 | 97.5 |
- ; --------------------
- ; | | 23.9 |
- ; --------------------
- ;
- ; Program will loop until the user presses space, enter, R-mouse or escape [sERmoE]
- ; step 1 : select (text) description for placement in column A
- ; step 2 : program will directly switch to dimension selection mode and will do so util [sERmoE]
- ; step 3 : after step 2 program will go back to step 1 (text selection mode) again until [sERmoE]
- ; step 4 : data will be processed and saved to same name as dwg but with extension csv
- ; step 5 : if user presses space the created csv file will be opened with associated program (if any)
- ; since program uses grread to directly read keyboard and mouse input I've programmed also a few keys for zooming
- ; + and - , z(oom) and e(xtents) , keys are case insensitive.
- ; Program directly reads cursor position and when no entity is found under selected point it switches to window
- ; mode (crossing actually).
- ; Since opp on CadTutor expressed the wish to be able to select each dimension individually, when program switches
- ; to window mode , still only one entity will get selected , just so you know you know...
- ; If dimension has text override , this will be the value saved to csv file
- (defun c:RlxDimensionToCSV ( / dim-title dim dim-sel csv-list csv-name)
- (vl-load-com)
- (princ "\nSelect dimension title (text) : ")
- (setq dim-title (RlxSel1 "TEXT"))
- (while dim-title
- (setq dim-title (cdr (assoc 1 (entget dim-title))))
- (if (assoc dim-title csv-list)
- (alert "Dimension title allready in list")
- (progn
- (setq dim-sel '())
- (princ "\nSelect dimensions : ")
- (while (setq dim (RlxSel1 "DIMENSION"))
- (if (not (member dim dim-sel))
- (setq dim-sel (reverse (cons dim (reverse dim-sel))))))
- (if (and dim-title dim-sel)
- (setq csv-list (reverse (cons (list dim-title dim-sel) (reverse csv-list)))))
- ); end progn
- ); end if
- (princ "\nSelect next dimension title or enter to write selection to csv file : ")
- (setq dim-title (RlxSel1 "TEXT"))
- ); end while
-
- ; refresh drawing
- (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
-
- ;selection process is complete , now process & save data
- (if (not (vl-consp csv-list))
- (alert "No data to process - ending program")
- (progn
- (setq csv-list (_convert csv-list))
- (if (vl-consp csv-list) (write_to_csv csv-list)(alert "Nothing to write"))
- (if (and csv-name (and (findfile csv-name)))(RlxDimensionsToCSV_OpenCSV))
- )
- )
- (princ)
- )
- (defun write_to_csv ( %lst / pref dname csv-fp row )
- (setq pref (getvar "dwgprefix") dname (vl-filename-base (getvar "dwgname")) csv-name (strcat pref dname ".csv"))
- (if (setq csv-fp (open csv-name "w"))
- (progn
- (foreach row %lst
- (write-line (strcat (car row) "," (cadr row)) csv-fp)
- (mapcar '(lambda (x)(write-line (strcat "," x) csv-fp)) (cddr row)))
- (close csv-fp)(gc)
- )
- )
- )
- (defun RlxDimensionsToCSV_OpenCSV ()
- (princ "\nPress space to open csv report , any other key to exit")
- (if (equal (grread) '(2 32)) (or (shell_open (findfile csv-name))(command "notepad" (findfile csv-name)))))
- (defun shell_open ( target / shell result )
- (if (and (setq target (findfile target))
- (setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")))
- (progn
- (setq result (vl-catch-all-apply 'vlax-invoke (list shell 'open target)))
- (vlax-release-object shell)(not (vl-catch-all-error-p result)))))
- (defun get_type ( %o )
- (cond
- ((= (type %o) 'ENAME)(cdr (assoc 0 (entget %o))))
- ((= (type %o) 'VLA-object)(cdr (assoc 0 (entget (vlax-vla-object->ename %o)))))
- (t nil)
- )
- )
- (defun RlxSel1 ( $e-type / done-selecting inp i p2 result e ent)
- (princ (strcat "\nEsc, enter, Rmouse to cancel, zoom with E(extend), Z(oom) or + / -\nSelect " $e-type))
- (setq done-selecting nil)
- (while (not done-selecting)
- (setq inp (vl-catch-all-apply 'grread (list nil 4 2)))
- (if (vl-catch-all-error-p inp)
- (setq done-selecting t result nil)
- (cond
- ; if point selected
- ((= (car inp) 3)
- ; if point has object under it
- (if (setq ent (nentselp (cadr inp))) (setq e (car ent) typ (get_type e)))
- (cond
- ; if we have object and object is the right type we have a winner
- ((and e typ (eq $e-type typ))
- (redraw e 3)(setq done-selecting t result e))
- ; maybe its the parent
- ; this happens when type is dimension and you select dimensions text
- ((and (caddr ent) (setq ent (last (last ent)))(eq $e-type (get_type ent)))
- (redraw ent 3)(setq done-selecting t result ent))
- ; sorry object is not the right stuf
- ((and e typ (not (eq $e-type typ)))
- (princ (strcat "\nYou selected the wrong type (" $e-type ")")))
- ; else try crossing selection
|