Advertisement
govindap

autolisp program to import CSV data to autocad

Aug 11th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 3.35 KB | None | 0 0
  1. (defun c:makeatable ( / startpt data rdline digits lineno currentpoint indexpt datapt indexrelpt datarelpt temp1 temp2 temp3 wide1 wide2 rowheight txtheight tempvar)
  2.  
  3.     (setq filename (getfiled "Rise-per-tooth Data File" "C:/Temp/drawings/" "csv" 128)) ;prompt user to open the file containing the data
  4.     (setq csvfile (open filename "r"))                          ;open the file to read its contents
  5.     (setq startpt (getpoint "\n Table insertion point: "))      ;prompt user to choose the insertion point
  6.  
  7. ;------------;prompt user to input the parameters; if nil, default value is set;--------------------------;
  8. ;
  9. ;** This code is useful when default values are needed, so that the user doesn't have to enter them.    **;
  10. ;** If the values appear jumbled, kindly run the program again with appropriate values.         **;
  11. ;**                                                 **;
  12.  
  13.  
  14.     (initget (+ 2 4))
  15.     (if (not(setq txtheight (getreal "\n Enter Text height: ")))       
  16.         (setq txtheight 3.0)
  17.     )
  18.     (princ)
  19.  
  20.     (initget (+ 2 4))
  21.     (if (not(setq wide1 (getreal "\n Enter first column width: ")))    
  22.         (setq wide1 10.0)
  23.     )
  24.     (princ)
  25.  
  26.     (initget (+ 2 4))
  27.     (if (not(setq wide2 (getreal "\n Enter second column width: ")))       
  28.         (setq wide2 25.0)
  29.     )
  30.     (princ)
  31.    
  32.     (initget (+ 2 4))
  33.     (if (not(setq rowheight (getreal "\n Enter Row height: ")))    
  34.         (setq rowheight 5.0)
  35.     )
  36.     (princ)
  37. ;----------------------------------------------------------------------------------------------------------;   
  38.    
  39.     (setq lineno 1)                 ;this var stores the line at which the program is currently at
  40.     (setq digits 0)                 ;this var stores the (number of digits - 1) of the index
  41.  
  42.     (setq currentpt startpt)            ;initialize currentpt
  43.  
  44. ;------------------------------;while loop;----------------------------------------------------------------;
  45.  
  46.     (while (> lineno 0)
  47.         (cond   ((> lineno 9)           ;check the number of    ;
  48.              (setq digits 1)        ;digits in the index    ;
  49.             )
  50.             ((> lineno 99)
  51.               (setq digits 2)
  52.             )
  53.         );end cond
  54.  
  55.     ;----------------------temporary variables----------------------;
  56.        
  57.         (setq temp1 (- wide1 (* (/ txtheight 3) (+ digits 1))))
  58.         (setq temp2 (* -1 (/ (+ rowheight txtheight) 2)))  
  59.         (setq temp3 (+ wide1 (* txtheight 2)))     
  60.     ;---------------------------------------------------------------;
  61.  
  62.         (setq indexrelpt (list temp1 temp2 0))      ;these are relative points which can            ;
  63.         (setq datarelpt (list temp3 temp2 0))       ;adjust according to the number of digits of index  ;
  64.  
  65.         (setq indexpt (mapcar '+        ;these lines        ;
  66.                     currentpt   ;set the coordinates    ;
  67.                     indexrelpt  ;for the index      ;
  68.                 )           ;           ;
  69.         )
  70.  
  71.         (setq datapt (mapcar '+         ;these lines        ;
  72.                     currentpt   ;set the coordinates    ;
  73.                     datarelpt   ;for the data       ;
  74.                 )           ;           ;
  75.         )
  76.  
  77.         (setq rdline (read-line csvfile))       ;read a line from the CSV file     
  78.         (setq data (substr rdline (+ 3 digits)))    ;extract the data from the read line   
  79.  
  80.         (command "text" datapt txtheight 0 data)    ;write the data    
  81.  
  82.         (command "text" indexpt txtheight 0 lineno) ;write the index number
  83.  
  84.         (setq lineno (1+ lineno))       ;increment line number
  85.  
  86.         ;(setq tempvar (* -1 rowheight))        ;another temporary variable
  87.         (setq tempvar(list 0 (* -1 rowheight) 0))  
  88.  
  89.         (setq currentpt (mapcar '+          ;increment the      ;
  90.                     currentpt       ;current point      ;
  91.                     tempvar         ;coordinates        ;
  92.                 )               ;           ;
  93.         )
  94.     )  
  95. ;------------------------------;while loop ends;----------------------------------------------------------;
  96. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement