Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun c:makeatable ( / startpt data rdline digits lineno currentpoint indexpt datapt indexrelpt datarelpt temp1 temp2 temp3 wide1 wide2 rowheight txtheight tempvar)
- (setq filename (getfiled "Rise-per-tooth Data File" "C:/Temp/drawings/" "csv" 128)) ;prompt user to open the file containing the data
- (setq csvfile (open filename "r")) ;open the file to read its contents
- (setq startpt (getpoint "\n Table insertion point: ")) ;prompt user to choose the insertion point
- ;------------;prompt user to input the parameters; if nil, default value is set;--------------------------;
- ;
- ;** This code is useful when default values are needed, so that the user doesn't have to enter them. **;
- ;** If the values appear jumbled, kindly run the program again with appropriate values. **;
- ;** **;
- (initget (+ 2 4))
- (if (not(setq txtheight (getreal "\n Enter Text height: ")))
- (setq txtheight 3.0)
- )
- (princ)
- (initget (+ 2 4))
- (if (not(setq wide1 (getreal "\n Enter first column width: ")))
- (setq wide1 10.0)
- )
- (princ)
- (initget (+ 2 4))
- (if (not(setq wide2 (getreal "\n Enter second column width: ")))
- (setq wide2 25.0)
- )
- (princ)
- (initget (+ 2 4))
- (if (not(setq rowheight (getreal "\n Enter Row height: ")))
- (setq rowheight 5.0)
- )
- (princ)
- ;----------------------------------------------------------------------------------------------------------;
- (setq lineno 1) ;this var stores the line at which the program is currently at
- (setq digits 0) ;this var stores the (number of digits - 1) of the index
- (setq currentpt startpt) ;initialize currentpt
- ;------------------------------;while loop;----------------------------------------------------------------;
- (while (> lineno 0)
- (cond ((> lineno 9) ;check the number of ;
- (setq digits 1) ;digits in the index ;
- )
- ((> lineno 99)
- (setq digits 2)
- )
- );end cond
- ;----------------------temporary variables----------------------;
- (setq temp1 (- wide1 (* (/ txtheight 3) (+ digits 1))))
- (setq temp2 (* -1 (/ (+ rowheight txtheight) 2)))
- (setq temp3 (+ wide1 (* txtheight 2)))
- ;---------------------------------------------------------------;
- (setq indexrelpt (list temp1 temp2 0)) ;these are relative points which can ;
- (setq datarelpt (list temp3 temp2 0)) ;adjust according to the number of digits of index ;
- (setq indexpt (mapcar '+ ;these lines ;
- currentpt ;set the coordinates ;
- indexrelpt ;for the index ;
- ) ; ;
- )
- (setq datapt (mapcar '+ ;these lines ;
- currentpt ;set the coordinates ;
- datarelpt ;for the data ;
- ) ; ;
- )
- (setq rdline (read-line csvfile)) ;read a line from the CSV file
- (setq data (substr rdline (+ 3 digits))) ;extract the data from the read line
- (command "text" datapt txtheight 0 data) ;write the data
- (command "text" indexpt txtheight 0 lineno) ;write the index number
- (setq lineno (1+ lineno)) ;increment line number
- ;(setq tempvar (* -1 rowheight)) ;another temporary variable
- (setq tempvar(list 0 (* -1 rowheight) 0))
- (setq currentpt (mapcar '+ ;increment the ;
- currentpt ;current point ;
- tempvar ;coordinates ;
- ) ; ;
- )
- )
- ;------------------------------;while loop ends;----------------------------------------------------------;
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement