Jump to content

Recommended Posts

Posted

Hi Im new to lsp, i have a text file that has been generated from an external source, i need to import the data into cad within a table. The text file has been written with spaces splitting the cell values. for example

 

The text file would read:

CADTutor The best free help for AutoCAD on the web

 

The table would need to be as follows:

Column A..|Column B........... | Column C

CADTutor |The best free help| For AutoCAD on the web

 

Could anyone point me in the right direction of how to do this, I hope this makes sence?!

 

Dan

Posted

Found this one on my machine, give it a try

(use tab delimited file as source)

(defun C:TX2TB (/ atable c delim file  headers i lst p pt r th wids x)
;; fixo 2008 (excerpt from old lib. utils)
;; local defuns
   (defun file-to-list (filename / file result line)
 (if (findfile filename)
   (progn (setq file (open filename "r"))
   (while (setq line (read-line file))
     (setq result (cons line result))
   )
   (close file)
   (reverse result)
   )
   (alert (strcat "File " filename " not found!"))
 )
)
(defun split-string (str delim / pos)
 ;; Splits a string into a list of strings at every
 ;; occurrence of the delimiter (single-letter string).
 (setq pos (vl-string-position (ascii delim) str))
 (if (null pos)
   (list str)
   (cons (substr str 1 pos)
  (split-string (substr str (+ pos 2)) delim)
   )
 )
)
   
 
(defun setcelltext (col row st aln)
       (vla-settext atable row col st)
       (vla-setcellalignment atable row col aln)
     )
 
   ;; main part 
   (setq file (getfiled "Select points file:" "C:\\Test\\" "TXT;CSV" )
   ;; text file is tab delimited, values are in order of: a[TAB]b[TAB]c[TAB]d   etc. 

 (setq lst (file-to-list file))
 
 (setq delim (chr 9));TAB
 ;(setq delim (chr 59));semicolon
 ;(setq delim (chr 44));comma
 (setq lst (mapcar '(lambda (p)(split-string p (chr 9)))lst));used TAB delimiter
 (setq i 0)
 ;(setq headers nil)
 (repeat (length (car lst))
 (setq headers (cons  (strcat "Column" (itoa (setq i (1+ i)))) headers)))
 (setq headers (reverse headers))
 (setq th (if (zerop (getvar 'textsize))(* (getvar 'dimtxt) 1.5)(* (getvar 'textsize) 1.5)))
 (repeat (length headers)
   (setq wids (cons
  (apply 'max
  (mapcar '(lambda(y)(* (strlen y) th))
   (mapcar 'car lst)))
  wids)
  )
   )
(if (setq pt (getpoint "\n Specify Table Location :"))
       (progn
         (setq
           atable (vla-addtable
                 (vla-get-block
                   (vla-get-activelayout
                     (vla-get-activedocument (vlax-get-acad-object))
                   )
                 )
                 (vlax-3d-point pt)
                 (+ (length lst) 2)
                 (length headers)
                 th
                 (* th 15)
               )
         )
         (setq i -1)
         (repeat (length (car lst))
           (vla-setcolumnwidth atable (setq i (1+ i)) (nth i wids))
         )
  ;;title
         (vla-settext
           atable
           0
           0
           (strcat "Table Title")
         )
  ;headers
  (setq c -1 r 1)
  (repeat (length (car lst))
    (setcelltext (setq c (1+ c)) r (nth i headers) 5);align middle center
       )
     (setq r 2)
     ;; data rows
     (foreach item lst
(setq c 0)
(foreach a item
       (setcelltext c r a 4);align middle left
  (setq c (1+ c)))
       (setq r (1+ r)))
     )
   )
 (princ)
)
(vl-load-com)

Posted

Just a couple of extra to Fixo's above maybe usefull those not familar with chr x either can be used in most cases but Tab requires chr. Next step once the rules are known is to create a table

 

(setq delim (chr 9));TAB
 ;(setq delim (chr 59));semicolon
 ;(setq delim (chr 44));comma
 ;(setq delim ",") ; comma
 ;(setq delim " ") ; space
 ;(setq delim (chr 32)); space
 ;(setq delim (chr 46)); period
 ;(setq delim ".")); period
 ;(setq delim (chr 45)); - minus
 ;(setq delim "-)); - minus

 

Just a question is the data a column of letters always the same lengths for each word then different method can do it using SUBSTR

 

(setq ans (substr textstring 1 9)) ; this is Cadtutor 

Posted

Thank you Alan, this is a good point

Cheers :)

Posted (edited)

thanks for the reply guys that's perfect.

 

The data is arranged into columns so the characters 1-9 need to go to column a characters 10-25 in column b etc.

 

where abouts would the (setq ans (substr textstring 1 9)) need to go?

 

also is it possible to change the column width for each column individually? ive worked out how to do all of them but for example column b needs to be about double the size of a?

Edited by dan_g8
Posted

Fixo will probably help you out with a modified version using substr but for your info.

 

(setq ans1 (substr textstring 1 9))
(setq ans2 (substr textstring 10 25))
(setq ans3 (substr textstring 26 39))
also
(vla-setcolumnwidth objtable 0 15) ; 0 is first column 15 is width

  • 1 year later...
Posted

HOW MAKE BEAM SECTION DETAIL WITH LISP AUTOCAD

 

Hello all.

 

I have problems with AutoCAD. how to draw a detailed section beam quickly and correctly? , as supported beam left, center and right support which uses data from Excel or from ETABS.

 

Please help.

Thank you very much..,...

  • 5 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...