csv - AutoLISP program giving inconsistent results -


software: autocad 2012 (japanese language)

system: ms windows 7 (japanese language)


the situation

i have made .lsp file defines new function "c:makeatable".

it asks user select .csv file , imports data drawing file opened in autocad. .csv file has 2 columns:

  1. serial number (integer)
  2. data (real number)

the last line of .csv file "eof".

the data imported should such each text entity independent of other, except fact arranged in tabular manner insertion point specified user.

now, problem whenever load .lsp file , call function, result not same. values appear perfectly in desired manner; many times values appear jumbled up. there 3 types of ways in values appear jumbled up.

  • i tried restarting application pc, no avail.
  • i have declared variables local, not interfered with.

here complete code: pastebin link available

(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)      (setq filename (getfiled "data file" "c:/temp/drawings/" "csv" 128))    ;prompt user open file containing data     (setq csvfile (open filename "r"))                          ;open file read contents     (setq startpt (getpoint "\n table insertion point: "))      ;prompt user choose insertion point  ;------------;prompt user input parameters; if nil, default value set;--------------------------; ; ;** code useful when default values needed, user doesn't have enter them.    **; ;** if values appear jumbled, kindly run program again appropriate values.         **; ;**                                                 **;       (initget (+ 2 4))     (if (not(setq txtheight (getreal "\n enter text height: ")))                 (setq txtheight 4.0)     )     (princ)      (initget (+ 2 4))     (if (not(setq wide1 (getreal "\n enter first column width: ")))              (setq wide1 15.0)     )     (princ)      (initget (+ 2 4))     (if (not(setq wide2 (getreal "\n enter second column width: ")))                 (setq wide2 30.0)     )     (princ)      (initget (+ 2 4))     (if (not(setq rowheight (getreal "\n enter row height: ")))              (setq rowheight 7.0)     )     (princ) ;----------------------------------------------------------------------------------------------------------;          (setq lineno 1) ;this var stores line @ program @     (setq digits 0) ;this var stores (number of digits - 1) of index      (setq currentpt startpt)    ;initialize currentpt   ;-------*------temporary variables arrangement of data------*-------;      (setq temp2  (/ (+ rowheight txtheight) 2))      (setq temp3 (+ wide1 (* txtheight 2)))     (setq temp4 (+ wide1 (/ wide2 5)))           (setq temp5 (- wide1 (/ wide1 20)))     (setq tempvar (list 0 (* -1 rowheight) 0))  ;-------------------------------------------------------------------------------;      (setq datarelpt (list temp4 temp2 0))   ;these relative points;     (setq baserelpt (list temp5 temp2 0))  ;------------------------------;while loop;-------------------------------------;      (while (/= rdline "eof")         (cond   ((> lineno 9)       ;check number of    ;              (setq digits 1)        ;digits in index    ;             )             ((> lineno 99)               (setq digits 2)             )         );end cond            (setq datapt (mapcar '+         ;these lines        ;                 currentpt       ;set coordinates    ;                 datarelpt       ;for data       ;                 )       ;           ;         )          (setq indexbasept (mapcar '+    ;these lines        ;             currentpt       ;set coordinates    ;                 baserelpt       ;for index      ;                 )       ;           ;         )          (setq rdline (read-line csvfile))   ;read line csv file               (setq data (substr rdline (+ 3 digits)));extract data read line              (setq tmp (command "style" "mono" "monotxt" "" "" "" "" "" ""))     ;makes text monospace      ;-----------------------------printing values-----------------------;          (command "text" datapt txtheight 0 data)    ;write data          (command "text" "_j" "_r" indexbasept txtheight 0 lineno)   ;write index number     ;-------------------------------------------------------------------;          (setq lineno (1+ lineno))           ;increment line number          (setq currentpt (mapcar '+      ;increment      ;                 currentpt       ;current point      ;                 tempvar     ;coordinates        ;                 )       ;           ;         )     )   ;------------------------------;while loop ends;------------------------------------;      (entdel (entlast))  ;to remove index number printed @ end     (close csvfile)     ;close opened file     (princ)         ;clean exit ) 

i checked points @ text being inserted [using (princ datapt) , (princ indexbasept)], , found them alright. however, when autocad creates these text objects on screen, occupy same position , jumbled up.

kindly tell me might going wrong , should now.

my first thought need turn off osnaps before running command.

(setq orig-osm (getvar "osmode")) (command "osmode" 0) ... rest of command ... (command "osmode" orig-osm) 

depending on constraints think generate table columns mtext (multi-line text) , explode them each after creation create separate text objects. can use (ssget "l") operate on last element added database.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -