Advertisement
govindap

Autolisp program

Aug 19th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 4.04 KB | None | 0 0
  1. (defun c:makeatable ( / filename csvfile startpt data rdline digits lineno currentpt datapt datarelpt baserelpt indexbasept temp2 temp3 temp4 temp5 wide1 wide2 rowheight txtheight tempvar tmps)
  2.    
  3.         (setq filename (getfiled "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 4.0)
  17.         )
  18.         (princ)
  19.                                                
  20.         (initget (+ 2 4))
  21.         (if (not(setq wide1 (getreal "\n Enter first column width: ")))    
  22.             (setq wide1 15.0)
  23.         )
  24.         (princ)
  25.    
  26.         (initget (+ 2 4))
  27.         (if (not(setq wide2 (getreal "\n Enter second column width: ")))       
  28.             (setq wide2 30.0)
  29.         )
  30.         (princ)
  31.        
  32.         (initget (+ 2 4))
  33.         (if (not(setq rowheight (getreal "\n Enter Row height: ")))    
  34.             (setq rowheight 7.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.    
  45.     ;-------*------temporary variables for the arrangement of the data------*-------;
  46.        
  47.         (setq temp2  (/ (+ rowheight txtheight) 2))
  48.         (setq temp3 (+ wide1 (* txtheight 2)))
  49.         (setq temp4 (+ wide1 (/ wide2 5)))     
  50.         (setq temp5 (- wide1 (/ wide1 20)))
  51.         (setq tempvar (list 0 (* -1 rowheight) 0))
  52.            
  53.     ;-------------------------------------------------------------------------------;
  54.    
  55.         (setq datarelpt (list temp4 temp2 0))   ;these are relative points;
  56.         (setq baserelpt (list temp5 temp2 0))
  57.    
  58.     ;------------------------------;while loop;-------------------------------------;
  59.    
  60.         (while (/= rdline "EOF")
  61.             (cond   ((> lineno 9)       ;check the number of    ;
  62.                  (setq digits 1)        ;digits in the index    ;
  63.                 )
  64.                 ((> lineno 99)
  65.                   (setq digits 2)
  66.                 )
  67.             );end cond
  68.    
  69.            
  70.    
  71.             (setq datapt (mapcar '+         ;these lines        ;
  72.                     currentpt       ;set the coordinates    ;
  73.                     datarelpt       ;for the data       ;
  74.                     )       ;           ;
  75.             )
  76.    
  77.             (setq indexbasept (mapcar '+    ;these lines        ;
  78.                 currentpt       ;set the coordinates    ;
  79.                     baserelpt       ;for the index      ;
  80.                     )       ;           ;
  81.             )
  82.    
  83.             (setq rdline (read-line csvfile))   ;read a line from the CSV file     
  84.             (setq data (substr rdline (+ 3 digits)));extract the data from the read line   
  85.    
  86.             (setq tmp (command "STYLE" "MONO" "MONOTXT" "" "" "" "" "" ""))     ;makes the text monospace
  87.    
  88.         ;-----------------------------printing the values-----------------------;
  89.    
  90.             (command "text" datapt txtheight 0 data)    ;write the data
  91.    
  92.             (command "text" "_j" "_r" indexbasept txtheight 0 lineno)   ;write the index number
  93.         ;-------------------------------------------------------------------;
  94.    
  95.             (setq lineno (1+ lineno))           ;increment line number
  96.    
  97.             (setq currentpt (mapcar '+      ;increment the      ;
  98.                     currentpt       ;current point      ;
  99.                     tempvar     ;coordinates        ;
  100.                     )       ;           ;
  101.             )
  102.         )  
  103.     ;------------------------------;while loop ends;------------------------------------;
  104.    
  105.         (entdel (entlast))  ;to remove the extra index number printed at the end
  106.         (close csvfile)     ;close the opened file
  107.         (princ)         ;clean exit
  108.     )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement