TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pedroantonio on November 24, 2013, 04:00:21 PM

Title: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 24, 2013, 04:00:21 PM
I found at CadTutor forum , a Lee Mac lisp code. It is very useful but a have a little problem with the text size. I dont know a lot of things about lisp that's way  i ask for you if any one can add a commad from the text size.

thank you

Code: [Select]
;; Text File to Table  -  Lee Mac
;; Prompts the user to select a text file containing 4 columns of comma-delimited data
;; and generates an AutoCAD Table containing the file data at the point specified.

(defun c:txt2tab ( / *error* des ins lin lst txt )

    (defun *error* ( msg )
        (if (= 'file (type des)) (close des))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
   
    (if (setq txt (getfiled "choose a file  P,X,Y,Z (*.txt)" "" "txt" 16))
        (if (setq des (open txt "r"))
            (progn
                (while (setq lin (read-line des))
                    (if (= 4 (length (setq lin (LM:str->lst lin ","))))
                        (setq lst (cons lin lst))
                    )
                )
                (setq des (close des))
                (if lst
                    (if (setq ins (getpoint "\nSpecify point for table: "))
                        (LM:addtable
                            (vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
                                (if (= 1 (getvar 'cvport))
                                    'paperspace
                                    'modelspace
                                )
                            )
                            (trans ins 1 0)
                            nil
                            (cons '("A/A" "X" "Y" "Z") (reverse lst))
                            nil
                        )
                    )
                    (princ "\nNo valid data found in selected file.")
                )
            )
            (princ "\nUnable to open selected file for reading.")
        )
    )
    (princ)
)

;;---------------------=={ Add Table }==----------------------;;
;;                                                            ;;
;;  Creates an AutoCAD Table Object at the specified point,   ;;
;;  populated with the given data and optional title.         ;;
;;------------------------------------------------------------;;
;; Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com     ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  spc - VLA Block Object                                    ;;
;;  ins - WCS Insertion Point for Table                       ;;
;;  ttl - [Optional] Table title                              ;;
;;  lst - Matrix list of data to populate the table           ;;
;;  eqc - If T, columns are of equal width                    ;;
;;------------------------------------------------------------;;
;;  Returns:  VLA Table Object                                ;;
;;------------------------------------------------------------;;

(defun LM:AddTable ( spc ins ttl lst eqc / dif hgt i j obj stn sty wid )
    (setq sty
        (vlax-ename->vla-object
            (cdr
                (assoc -1
                    (dictsearch
                        (cdr
                            (assoc -1
                                (dictsearch (namedobjdict) "acad_tablestyle")
                            )
                        )
                        (getvar 'ctablestyle)
                    )
                )
            )
        )
    )
    (setq hgt (vla-gettextheight sty acdatarow))
    (if (LM:Annotative-p (setq stn (vla-gettextstyle sty acdatarow)))
        (setq hgt (/ hgt (getvar 'cannoscalevalue)))
    )
    (setq wid
        (mapcar
            (function
                (lambda ( col )
                    (apply 'max
                        (mapcar
                            (function
                                (lambda ( str )
                                    (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
                                        (textbox
                                            (list
                                                (cons 01 str)
                                                (cons 40 hgt)
                                                (cons 07 stn)
                                            )
                                        )
                                    )
                                )
                            )
                            col
                        )
                    )
                )
            )
            (apply 'mapcar (cons 'list lst))
        )
    )
    (if
        (and ttl
            (< 0.0
                (setq dif
                    (/
                        (-
                            (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
                                (textbox
                                    (list
                                        (cons 01 ttl)
                                        (cons 40 hgt)
                                        (cons 07 stn)
                                    )
                                )
                            )
                            (apply '+ wid)
                        )
                        (length wid)
                    )
                )
            )
        )
        (setq wid (mapcar '(lambda ( x ) (+ x dif)) wid))
    )
    (setq obj
        (vla-addtable spc
            (vlax-3D-point ins)
            (1+ (length lst))
            (length (car lst))
            (* 2.0 hgt)
            (if eqc
                (apply 'max wid)
                (/ (apply '+ wid) (float (length (car lst))))
            )
        )
    )
    (vla-put-regeneratetablesuppressed obj :vlax-true)
    (vla-put-stylename obj (getvar 'ctablestyle))
    (setq i -1)
    (if (null eqc)
        (foreach col wid
            (vla-setcolumnwidth obj (setq i (1+ i)) col)
        )
    )
    (if ttl
        (progn
            (vla-settext obj 0 0 ttl)
            (setq i 1)
        )
        (progn
            (vla-deleterows obj 0 1)
            (setq i 0)
        )
    )
    (foreach row lst
        (setq j 0)
        (foreach val row
            (vla-settext obj i j val)
            (setq j (1+ j))
        )
        (setq i (1+ i))
    )
    (vla-put-regeneratetablesuppressed obj :vlax-false)
    obj
)

;; Annotative-p
;; Returns T if the given Textstyle is annotative

(defun LM:annotative-p ( sty )
    (and (setq sty (tblobjname "style" sty))
         (setq sty (cadr (assoc -3 (entget sty '("AcadAnnotative")))))
         (= 1 (cdr (assoc 1070 (reverse sty))))
    )
)

;; String to List
;; Separates a string using a given delimiter
;; str - [str] string to process
;; del - [str] delimiter by which to separate the string

(defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
        (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
        (list str)
    )
)
(vl-load-com) (princ)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;----------------------=={ Text File to Table }==----------------------;;
;;                                                                      ;;
;;  Prompts the user to select a text file and generates an AutoCAD     ;;
;;  Table at the point specified, representing the file data.           ;;
;;----------------------------------------------------------------------;;
;;    Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com            ;;
;;----------------------------------------------------------------------;;

(defun c:txt2tab2 ( / *error* del des hdl ins lin lst txt )

    (setq ttl nil ;; Table Title (nil for no title)
          hdl '("A/A" "X" "Y") ;; Table Headings
          del "," ;; Data Delimiter String
    )
   
    (defun *error* ( msg )
        (if (= 'file (type des)) (close des))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
   
    (if (setq txt (getfiled "choose a file   P,X,Y (*.txt)" "" "txt" 16))
        (if (setq des (open txt "r"))
            (progn
                (while (setq lin (read-line des))
                    (setq lst (cons (mapcar '(lambda ( a b ) a) (LM:str->lst lin del) hdl) lst))
                )
                (setq des (close des))
                (if lst
                    (if (setq ins (getpoint "\nSpecify point for table: "))
                        (LM:addtable
                            (vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
                                (if (= 1 (getvar 'cvport))
                                    'paperspace
                                    'modelspace
                                )
                            )
                            (trans ins 1 0) ttl (cons hdl (reverse lst)) nil
                        )
                    )
                    (princ "\nNo valid data found in selected file.")
                )
            )
            (princ "\nUnable to open selected file for reading.")
        )
    )
    (princ)
)

;;---------------------------=={ Add Table }==--------------------------;;
;;                                                                      ;;
;;  Creates an AutoCAD Table Object at the specified point, populated   ;;
;;  with the given data and optional title.                             ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Arguments:                                                          ;;
;;  spc - VLA Block object                                              ;;
;;  ins - WCS Insertion point for table                                 ;;
;;  ttl - [Optional] Table title                                        ;;
;;  lst - Matrix list of data to populate the table                     ;;
;;  eqc - If T, columns are of equal width                              ;;
;;----------------------------------------------------------------------;;
;;  Returns:  VLA Table Object                                          ;;
;;----------------------------------------------------------------------;;

(defun LM:AddTable ( spc ins ttl lst eqc / dif hgt i j obj stn sty wid )
    (setq sty
        (vlax-ename->vla-object
            (cdr
                (assoc -1
                    (dictsearch
                        (cdr
                            (assoc -1
                                (dictsearch (namedobjdict) "acad_tablestyle")
                            )
                        )
                        (getvar 'ctablestyle)
                    )
                )
            )
        )
    )
    (setq hgt (vla-gettextheight sty acdatarow))
    (if (LM:Annotative-p (setq stn (vla-gettextstyle sty acdatarow)))
        (setq hgt (/ hgt (getvar 'cannoscalevalue)))
    )
    (setq wid
        (mapcar
            (function
                (lambda ( col )
                    (apply 'max
                        (mapcar
                            (function
                                (lambda ( str )
                                    (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
                                        (textbox
                                            (list
                                                (cons 01 str)
                                                (cons 40 hgt)
                                                (cons 07 stn)
                                            )
                                        )
                                    )
                                )
                            )
                            col
                        )
                    )
                )
            )
            (apply 'mapcar (cons 'list lst))
        )
    )
    (if
        (and ttl
            (< 0.0
                (setq dif
                    (/
                        (-
                            (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
                                (textbox
                                    (list
                                        (cons 01 ttl)
                                        (cons 40 hgt)
                                        (cons 07 stn)
                                    )
                                )
                            )
                            (apply '+ wid)
                        )
                        (length wid)
                    )
                )
            )
        )
        (setq wid (mapcar '(lambda ( x ) (+ x dif)) wid))
    )
    (setq obj
        (vla-addtable spc
            (vlax-3D-point ins)
            (1+ (length lst))
            (length (car lst))
            (* 2.0 hgt)
            (if eqc
                (apply 'max wid)
                (/ (apply '+ wid) (float (length (car lst))))
            )
        )
    )
    (vla-put-regeneratetablesuppressed obj :vlax-true)
    (vla-put-stylename obj (getvar 'ctablestyle))
    (setq i -1)
    (if (null eqc)
        (foreach col wid
            (vla-setcolumnwidth obj (setq i (1+ i)) col)
        )
    )
    (if ttl
        (progn
            (vla-settext obj 0 0 ttl)
            (setq i 1)
        )
        (progn
            (vla-deleterows obj 0 1)
            (setq i 0)
        )
    )
    (foreach row lst
        (setq j 0)
        (foreach val row
            (vla-settext obj i j val)
            (setq j (1+ j))
        )
        (setq i (1+ i))
    )
    (vla-put-regeneratetablesuppressed obj :vlax-false)
    obj
)

;; Returns T if the given Textstyle is annotative

(defun LM:annotative-p ( sty )
    (and (setq sty (tblobjname "style" sty))
         (setq sty (cadr (assoc -3 (entget sty '("AcadAnnotative")))))
         (= 1 (cdr (assoc 1070 (reverse sty))))
    )
)

;; String to List
;; Separates a string using a given delimiter
;; str - [str] string to process
;; del - [str] delimiter by which to separate the string

(defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
        (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
        (list str)
    )
)

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
    (strcat
        "\n:: Text2Table.lsp | Version 1.1 | \\U+00A9 Lee Mac "
        (menucmd "m=$(edtime,0,yyyy)")
        "\n:: Type \"txt2tab\" to Invoke ::"
    )
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;
Title: Re: coordinate point list (*.txt file) and table
Post by: CAB on November 24, 2013, 05:56:57 PM
The text height comes from the current Table Style. You need to update the table style.
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 25, 2013, 02:37:30 AM
I am trying to add this lines in the code
Code: [Select]
(command "_layer" "m" "table" "c" "7" "" )
(setq scl(/ (getreal  "\n Specify the scale (100,200,500,etc) : ") 100))
(setq hgt(* 0.25 scl))

but is not working
Title: Re: coordinate point list (*.txt file) and table
Post by: irneb on November 25, 2013, 03:00:00 AM
Lee's code is using the Annotation Scale factor. Perhaps you could simply change that when running this code.

Edit: Just a question though. Why go this route? You know you can open that TXT file in Excel (it's the same thing as a CVS file). Then you can select the columns & rows you want, copy to clipboard (Ctrl+C) and paste special into ACad (paste it as ACad Objects - which turns the spreadsheet into an acad table).

Unless I'm missing something, I don't see how it's that much more work.
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 25, 2013, 03:06:52 AM
Can any one tranform this lisp to add my code in ? please  :embarrassed:
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 25, 2013, 04:10:01 AM
any ideas ? :-o
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 25, 2013, 05:48:48 AM
Quote
Edit: Just a question though. Why go this route? You know you can open that TXT file in Excel (it's the same thing as a CVS file). Then you can select the columns & rows you want, copy to clipboard (Ctrl+C) and paste special into ACad (paste it as ACad Objects - which turns the spreadsheet into an acad table).

yes i know but with this lisp is faster.I tryed and the Table Style setting and Annotation Scale factor but the result is not i want ...please someone help :embarrassed:
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 25, 2013, 09:53:57 AM
i am tryind to add this lines

Code: [Select]
(command "_layer" "m" "table" "c" "7" "" )
(setq scl(/ (getreal  "\n Specify the scale (100,200,500,etc) : ") 100))
(setq hgt(* 0.25 scl))

somebody helps me ..... please :cry:
Title: Re: coordinate point list (*.txt file) and table
Post by: Kerry on November 25, 2013, 07:11:59 PM

Since you found this at CadTutor ; have you asked in the thread that you acquired the code from ?
Title: Re: coordinate point list (*.txt file) and table
Post by: CAB on November 25, 2013, 10:06:51 PM
http://www.cadtutor.net/forum/showthread.php?81678-coordinate-point-list-(*.txt-file)-and-table
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 26, 2013, 02:41:14 AM
Quote
Since you found this at CadTutor ; have you asked in the thread that you acquired the code from ?

First of all same people answer in the posts in the both of this sites. And second i don't think that it's the problem. I think that if somebody really know how to fix this lisp will help .... I said

Quote
I found at CadTutor forum , a Lee Mac lisp code. It is very useful but a have a little problem with the text size. I dont know a lot of things about lisp that's way  i ask for you if any one can add a commad from the text size.

So if somebody really knows please help me... If you don't , not hurt feelings

Thanks ....
Title: Re: coordinate point list (*.txt file) and table
Post by: ymg on November 26, 2013, 05:39:11 AM
pedroantonio,


Shouting in the forum won't help you.

Cab's answer is perfectly valid simply modify the tablestyle.

This being said, if you are deadset about doing it in the program, why don't you creates your layer before the table is created and simply issue a scale command after creation.

ymg
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 26, 2013, 10:48:33 AM
Sorry about Shouting bur i explain that I dont know a lot of things about lisp that's way  i ask for you if any one can add a commad from the text size. I don't know how to change this code. If you can help me...

thanks
Title: Re: coordinate point list (*.txt file) and table
Post by: CAB on November 26, 2013, 11:39:55 AM
Have you tried this?
Title: Re: coordinate point list (*.txt file) and table
Post by: dgorsman on November 26, 2013, 12:23:22 PM
Sorry about Shouting bur i explain that I dont know a lot of things about lisp that's way  i ask for you if any one can add a commad from the text size. I don't know how to change this code. If you can help me...

thanks

Thats one of the points of this community.  We won't necessarily do it for you, but we can hold your hand (and give the occaisonal kick in the caboose) to help you learn so you can do it yourself.
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 27, 2013, 02:13:42 AM

CAB i do this changes but i have problem with the cells  of the table are too big.I try to make them smaller but nothing
Title: Re: coordinate point list (*.txt file) and table
Post by: ymg on November 27, 2013, 04:22:55 AM
pedroantonio,

Why don't you post your drawing then we'll have a look

ymg
Title: Re: coordinate point list (*.txt file) and table
Post by: ymg on November 27, 2013, 05:22:20 AM
pedroantonio,

Here's the code modified by scaling after creation adjust the value of the scaling to your taste.
Also added your layer creation command.

Look at the vl-cmdf lines in the code below.

This is not the ideal way, as we should be modifying the style from autolisp.

It is a quick hack and will work.

ymg

Code - Auto/Visual Lisp: [Select]
  1. ;; Text File to Table  -  Lee Mac
  2. ;; Prompts the user to select a text file containing 4 columns of comma-delimited data
  3. ;; and generates an AutoCAD Table containing the file data at the point specified.
  4.  
  5. (defun c:txt2tab ( / *error* des ins lin lst txt )
  6.  
  7.     (defun *error* ( msg )
  8.         (if (= 'file (type des)) (close des))
  9.         (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  10.             (princ (strcat "\nError: " msg))
  11.         )
  12.         (princ)
  13.     )
  14.    
  15.     (if (setq txt (getfiled "choose a file  P,X,Y,Z (*.txt)" "" "txt" 16))
  16.         (if (setq des (open txt "r"))
  17.             (progn
  18.                 (while (setq lin (read-line des))
  19.                     (if (= 4 (length (setq lin (LM:str->lst lin ","))))
  20.                         (setq lst (cons lin lst))
  21.                     )
  22.                 )
  23.                 (setq des (close des))
  24.                 (if lst
  25.                     (if (setq ins (getpoint "\nSpecify point for table: "))
  26.                        (progn
  27.                         (vl-cmdf "_LAYER" "_M"  "table" "_C" "7" "" "")
  28.                         (setq obj (LM:addtable
  29.                                      (vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
  30.                                           (if (= 1 (getvar 'cvport))
  31.                                                      'paperspace
  32.                                                      'modelspace
  33.                                           )
  34.                                      )
  35.                                      (trans ins 1 0)
  36.                                     nil
  37.                                     (cons '("A/A" "X" "Y" "Z") (reverse lst))
  38.                                     nil
  39.                                    )
  40.                          )
  41.                          (vl-cmdf "_SCALE" (entlast) "" ins 5) ; Replace the 5 with  desired scale here
  42.                         )
  43.                     )
  44.                     (princ "\nNo valid data found in selected file.")
  45.                 )
  46.             )
  47.             (princ "\nUnable to open selected file for reading.")
  48.         )
  49.     )
  50.     (princ)
  51. )
  52.  
  53. ;;---------------------=={ Add Table }==----------------------;;
  54. ;;                                                            ;;
  55. ;;  Creates an AutoCAD Table Object at the specified point,   ;;
  56. ;;  populated with the given data and optional title.         ;;
  57. ;;------------------------------------------------------------;;
  58. ;; Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com     ;;
  59. ;;------------------------------------------------------------;;
  60. ;;  Arguments:                                                ;;
  61. ;;  spc - VLA Block Object                                    ;;
  62. ;;  ins - WCS Insertion Point for Table                       ;;
  63. ;;  ttl - [Optional] Table title                              ;;
  64. ;;  lst - Matrix list of data to populate the table           ;;
  65. ;;  eqc - If T, columns are of equal width                    ;;
  66. ;;------------------------------------------------------------;;
  67. ;;  Returns:  VLA Table Object                                ;;
  68. ;;------------------------------------------------------------;;
  69.  
  70. (defun LM:AddTable ( spc ins ttl lst eqc / dif hgt i j obj stn sty wid )
  71.     (setq sty
  72.         (vlax-ename->vla-object
  73.             (cdr
  74.                 (assoc -1
  75.                     (dictsearch
  76.                         (cdr
  77.                             (assoc -1
  78.                                 (dictsearch (namedobjdict) "acad_tablestyle")
  79.                             )
  80.                         )
  81.                         (getvar 'ctablestyle)
  82.                     )
  83.                 )
  84.             )
  85.         )
  86.     )
  87.     (setq hgt (vla-gettextheight sty acdatarow))
  88.     (if (LM:Annotative-p (setq stn (vla-gettextstyle sty acdatarow)))
  89.         (setq hgt (/ hgt (getvar 'cannoscalevalue)))
  90.     )
  91.     (setq wid
  92.         (mapcar
  93.             (function
  94.                 (lambda ( col )
  95.                     (apply 'max
  96.                         (mapcar
  97.                             (function
  98.                                 (lambda ( str )
  99.                                     (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
  100.                                         (textbox
  101.                                             (list
  102.                                                 (cons 01 str)
  103.                                                 (cons 40 hgt)
  104.                                                 (cons 07 stn)
  105.                                             )
  106.                                         )
  107.                                     )
  108.                                 )
  109.                             )
  110.                             col
  111.                         )
  112.                     )
  113.                 )
  114.             )
  115.             (apply 'mapcar (cons 'list lst))
  116.         )
  117.     )
  118.     (if
  119.         (and ttl
  120.             (< 0.0
  121.                 (setq dif
  122.                     (/
  123.                         (-
  124.                             (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
  125.                                 (textbox
  126.                                     (list
  127.                                         (cons 01 ttl)
  128.                                         (cons 40 hgt)
  129.                                         (cons 07 stn)
  130.                                     )
  131.                                 )
  132.                             )
  133.                             (apply '+ wid)
  134.                         )
  135.                         (length wid)
  136.                     )
  137.                 )
  138.             )
  139.         )
  140.         (setq wid (mapcar '(lambda ( x ) (+ x dif)) wid))
  141.     )
  142.     (setq obj
  143.         (vla-addtable spc
  144.             (vlax-3D-point ins)
  145.             (1+ (length lst))
  146.             (length (car lst))
  147.             (* 2.0 hgt)
  148.             (if eqc
  149.                 (apply 'max wid)
  150.                 (/ (apply '+ wid) (float (length (car lst))))
  151.             )
  152.         )
  153.     )
  154.     (vla-put-regeneratetablesuppressed obj :vlax-true)
  155.     (vla-put-stylename obj (getvar 'ctablestyle))
  156.     (setq i -1)
  157.     (if (null eqc)
  158.         (foreach col wid
  159.             (vla-setcolumnwidth obj (setq i (1+ i)) col)
  160.         )
  161.     )
  162.     (if ttl
  163.         (progn
  164.             (vla-settext obj 0 0 ttl)
  165.             (setq i 1)
  166.         )
  167.         (progn
  168.             (vla-deleterows obj 0 1)
  169.             (setq i 0)
  170.         )
  171.     )
  172.     (foreach row lst
  173.         (setq j 0)
  174.         (foreach val row
  175.             (vla-settext obj i j val)
  176.             (setq j (1+ j))
  177.         )
  178.         (setq i (1+ i))
  179.     )
  180.     (vla-put-regeneratetablesuppressed obj :vlax-false)
  181.     obj
  182. )
  183.  
  184. ;; Annotative-p
  185. ;; Returns T if the given Textstyle is annotative
  186.  
  187. (defun LM:annotative-p ( sty )
  188.     (and (setq sty (tblobjname "style" sty))
  189.          (setq sty (cadr (assoc -3 (entget sty '("AcadAnnotative")))))
  190.          (= 1 (cdr (assoc 1070 (reverse sty))))
  191.     )
  192. )
  193.  
  194. ;; String to List
  195. ;; Separates a string using a given delimiter
  196. ;; str - [str] string to process
  197. ;; del - [str] delimiter by which to separate the string
  198.  
  199. (defun LM:str->lst ( str del / pos )
  200.     (if (setq pos (vl-string-search del str))
  201.         (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
  202.         (list str)
  203.     )
  204. )
  205.  
  206. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  207.  
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 27, 2013, 05:37:29 PM
Thank you Ymg the first part of the lisp (P,X,Y,Z) now work perfect.

Can you help me little  with the second (P,X,Y)

Code: [Select]
;;----------------------=={ Text File to Table }==----------------------;;
;;                                                                      ;;
;;  Prompts the user to select a text file and generates an AutoCAD     ;;
;;  Table at the point specified, representing the file data.           ;;
;;----------------------------------------------------------------------;;
;;    Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com            ;;
;;----------------------------------------------------------------------;;

(defun c:txt2tab2 ( / *error* del des hdl ins lin lst txt )

    (setq ttl nil ;; Table Title (nil for no title)
          hdl '("A/A" "X" "Y") ;; Table Headings
          del "," ;; Data Delimiter String
    )
   
    (defun *error* ( msg )
        (if (= 'file (type des)) (close des))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
   
    (if (setq txt (getfiled "choose a file   P,X,Y (*.txt)" "" "txt" 16))
        (if (setq des (open txt "r"))
            (progn
                (while (setq lin (read-line des))
                    (setq lst (cons (mapcar '(lambda ( a b ) a) (LM:str->lst lin del) hdl) lst))
                )
                (setq des (close des))
                (if lst
                    (if (setq ins (getpoint "\nSpecify point for table: "))
                        (LM:addtable
                            (vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
                                (if (= 1 (getvar 'cvport))
                                    'paperspace
                                    'modelspace
                                )
                            )
                            (trans ins 1 0) ttl (cons hdl (reverse lst)) nil
                        )
                    )
                    (princ "\nNo valid data found in selected file.")
                )
            )
            (princ "\nUnable to open selected file for reading.")
        )
    )
    (princ)
)

;;---------------------------=={ Add Table }==--------------------------;;
;;                                                                      ;;
;;  Creates an AutoCAD Table Object at the specified point, populated   ;;
;;  with the given data and optional title.                             ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Arguments:                                                          ;;
;;  spc - VLA Block object                                              ;;
;;  ins - WCS Insertion point for table                                 ;;
;;  ttl - [Optional] Table title                                        ;;
;;  lst - Matrix list of data to populate the table                     ;;
;;  eqc - If T, columns are of equal width                              ;;
;;----------------------------------------------------------------------;;
;;  Returns:  VLA Table Object                                          ;;
;;----------------------------------------------------------------------;;

(defun LM:AddTable ( spc ins ttl lst eqc / dif hgt i j obj stn sty wid )
    (setq sty
        (vlax-ename->vla-object
            (cdr
                (assoc -1
                    (dictsearch
                        (cdr
                            (assoc -1
                                (dictsearch (namedobjdict) "acad_tablestyle")
                            )
                        )
                        (getvar 'ctablestyle)
                    )
                )
            )
        )
    )
    (setq hgt (vla-gettextheight sty acdatarow))
    (if (LM:Annotative-p (setq stn (vla-gettextstyle sty acdatarow)))
        (setq hgt (/ hgt (getvar 'cannoscalevalue)))
    )
    (setq wid
        (mapcar
            (function
                (lambda ( col )
                    (apply 'max
                        (mapcar
                            (function
                                (lambda ( str )
                                    (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
                                        (textbox
                                            (list
                                                (cons 01 str)
                                                (cons 40 hgt)
                                                (cons 07 stn)
                                            )
                                        )
                                    )
                                )
                            )
                            col
                        )
                    )
                )
            )
            (apply 'mapcar (cons 'list lst))
        )
    )
    (if
        (and ttl
            (< 0.0
                (setq dif
                    (/
                        (-
                            (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
                                (textbox
                                    (list
                                        (cons 01 ttl)
                                        (cons 40 hgt)
                                        (cons 07 stn)
                                    )
                                )
                            )
                            (apply '+ wid)
                        )
                        (length wid)
                    )
                )
            )
        )
        (setq wid (mapcar '(lambda ( x ) (+ x dif)) wid))
    )
    (setq obj
        (vla-addtable spc
            (vlax-3D-point ins)
            (1+ (length lst))
            (length (car lst))
            (* 2.0 hgt)
            (if eqc
                (apply 'max wid)
                (/ (apply '+ wid) (float (length (car lst))))
            )
        )
    )
    (vla-put-regeneratetablesuppressed obj :vlax-true)
    (vla-put-stylename obj (getvar 'ctablestyle))
    (setq i -1)
    (if (null eqc)
        (foreach col wid
            (vla-setcolumnwidth obj (setq i (1+ i)) col)
        )
    )
    (if ttl
        (progn
            (vla-settext obj 0 0 ttl)
            (setq i 1)
        )
        (progn
            (vla-deleterows obj 0 1)
            (setq i 0)
        )
    )
    (foreach row lst
        (setq j 0)
        (foreach val row
            (vla-settext obj i j val)
            (setq j (1+ j))
        )
        (setq i (1+ i))
    )
    (vla-put-regeneratetablesuppressed obj :vlax-false)
    obj
)

;; Returns T if the given Textstyle is annotative

(defun LM:annotative-p ( sty )
    (and (setq sty (tblobjname "style" sty))
         (setq sty (cadr (assoc -3 (entget sty '("AcadAnnotative")))))
         (= 1 (cdr (assoc 1070 (reverse sty))))
    )
)

;; String to List
;; Separates a string using a given delimiter
;; str - [str] string to process
;; del - [str] delimiter by which to separate the string

(defun LM:str->lst ( str del / pos )
    (if (setq pos (vl-string-search del str))
        (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
        (list str)
    )
)

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
    (strcat
        "\n:: Text2Table.lsp | Version 1.1 | \\U+00A9 Lee Mac "
        (menucmd "m=$(edtime,0,yyyy)")
        "\n:: Type \"txt2tab\" to Invoke ::"
    )
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

thanks
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 28, 2013, 02:44:17 AM
I try this but it is not working ... Any ideas

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;----------------------=={ Text File to Table }==----------------------;;
;;                                                                      ;;
;;  Prompts the user to select a text file and generates an AutoCAD     ;;
;;  Table at the point specified, representing the file data.           ;;
;;----------------------------------------------------------------------;;
;;    Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com            ;;
;;----------------------------------------------------------------------;;

(defun c:txt2tab9 (/ *error* del des hdl ins lin lst txt scl hgt)
  (setq scl (/ (getreal "\n Specify the scale (100,200,500,etc) : ")
       100
    )
  )
  (setq hgt (* 0.05 scl))
  (setq ttl nil
;; Table Title (nil for no title)
hdl '("A/A" "X" "Y")
;; Table Headings
del ","
    ;; Data Delimiter String
  )

  (defun *error* (msg)
    (if (= 'file (type des))
      (close des)
    )
    (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
      (princ (strcat "\nError: " msg))
    )
    (princ)
  )

  (if (setq txt (getfiled "choose a file   P,X,Y (*.txt)" "" "txt" 16))
    (if (setq des (open txt "r"))
      (progn
(while (setq lin (read-line des))
  (setq
    lst (cons
  (mapcar '(lambda (a b) a) (LM:str->lst lin del) hdl)
  lst
)
  )
)
(setq des (close des))
(if lst
  (if (setq ins (getpoint "\nSpecify point for table: "))
    (progn
       (vl-cmdf "_LAYER" "_M" "table" "_C" "7" "" "")
     
      (setq obj
     (LM:addtable
       (vlax-get-property
(vla-get-activedocument (vlax-get-acad-object))
(if (= 1 (getvar 'cvport))
   'paperspace
   'modelspace
)
       )
       (trans ins 1 0)
       ttl
       (cons hdl (reverse lst))
       nil
     )
      )
      (vl-cmdf "_SCALE" (entlast) "" ins hgt)
      (princ "\nNo valid data found in selected file.")
    )
  )
  (princ "\nUnable to open selected file for reading.")
)
      )
      (princ)
    )

    ;;---------------------------=={ Add Table }==--------------------------;;
    ;;                                                                      ;;
    ;;  Creates an AutoCAD Table Object at the specified point, populated   ;;
    ;;  with the given data and optional title.                             ;;
    ;;----------------------------------------------------------------------;;
    ;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
    ;;----------------------------------------------------------------------;;
    ;;  Arguments:                                                          ;;
    ;;  spc - VLA Block object                                              ;;
    ;;  ins - WCS Insertion point for table                                 ;;
    ;;  ttl - [Optional] Table title                                        ;;
    ;;  lst - Matrix list of data to populate the table                     ;;
    ;;  eqc - If T, columns are of equal width                              ;;
    ;;----------------------------------------------------------------------;;
    ;;  Returns:  VLA Table Object                                          ;;
    ;;----------------------------------------------------------------------;;

    (defun LM:AddTable
   (spc ins ttl lst eqc / dif hgt i j obj stn sty wid)
      (setq sty
     (vlax-ename->vla-object
       (cdr
(assoc
   -1
   (dictsearch
     (cdr
       (assoc -1
      (dictsearch (namedobjdict) "acad_tablestyle")
       )
     )
     (getvar 'ctablestyle)
   )
)
       )
     )
      )
      (setq hgt (vla-gettextheight sty acdatarow))
      (if (LM:Annotative-p
    (setq stn (vla-gettextstyle sty acdatarow))
  )
(setq hgt (/ hgt (getvar 'cannoscalevalue)))
      )
      (setq wid
     (mapcar
       (function
(lambda (col)
   (apply
     'max
     (mapcar
       (function
(lambda (str)
   ((lambda (box)
      (if box
(+ (* 2.5 hgt) (- (caadr box) (caar box)))
0.0
      )
    )
     (textbox
       (list
(cons 01 str)
(cons 40 hgt)
(cons 07 stn)
       )
     )
   )
)
       )
       col
     )
   )
)
       )
       (apply 'mapcar (cons 'list lst))
     )
      )
      (if
(and ttl
     (< 0.0
(setq dif
       (/
(-
   ((lambda (box)
      (if box
(+ (* 2.5 hgt) (- (caadr box) (caar box)))
0.0
      )
    )
     (textbox
       (list
(cons 01 ttl)
(cons 40 hgt)
(cons 07 stn)
       )
     )
   )
   (apply '+ wid)
)
(length wid)
       )
)
     )
)
(setq wid (mapcar '(lambda (x) (+ x dif)) wid))
      )
      (setq obj
     (vla-addtable
       spc
       (vlax-3D-point ins)
       (1+ (length lst))
       (length (car lst))
       (* 2.0 hgt)
       (if eqc
(apply 'max wid)
(/ (apply '+ wid) (float (length (car lst))))
       )
     )
      )
      (vla-put-regeneratetablesuppressed obj :vlax-true)
      (vla-put-stylename obj (getvar 'ctablestyle))
      (setq i -1)
      (if (null eqc)
(foreach col wid
  (vla-setcolumnwidth obj (setq i (1+ i)) col)
)
      )
      (if ttl
(progn
  (vla-settext obj 0 0 ttl)
  (setq i 1)
)
(progn
  (vla-deleterows obj 0 1)
  (setq i 0)
)
      )
      (foreach row lst
(setq j 0)
(foreach val row
  (vla-settext obj i j val)
  (setq j (1+ j))
)
(setq i (1+ i))
      )
      (vla-put-regeneratetablesuppressed obj :vlax-false)
      obj
    )

    ;; Returns T if the given Textstyle is annotative

    (defun LM:annotative-p (sty)
      (and (setq sty (tblobjname "style" sty))
   (setq sty (cadr (assoc -3 (entget sty '("AcadAnnotative")))))
   (= 1 (cdr (assoc 1070 (reverse sty))))
      )
    )

    ;; String to List
    ;; Separates a string using a given delimiter
    ;; str - [str] string to process
    ;; del - [str] delimiter by which to separate the string

    (defun LM:str->lst (str del / pos)
      (if (setq pos (vl-string-search del str))
(cons (substr str 1 pos)
      (LM:str->lst (substr str (+ pos 1 (strlen del))) del)
)
(list str)
      )
    )

    ;;----------------------------------------------------------------------;;

    (vl-load-com)
    (princ
      (strcat
"\n:: Text2Table.lsp | Version 1.1 | \\U+00A9 Lee Mac "
(menucmd "m=$(edtime,0,yyyy)")
"\n:: Type \"txt2tab\" to Invoke ::"
      )
    )
    (princ)

    ;;----------------------------------------------------------------------;;
    ;;                             End of File                              ;;
    ;;----------------------------------------------------------------------;;
  )
)
Title: Re: coordinate point list (*.txt file) and table
Post by: ymg on November 29, 2013, 07:55:41 AM
pedroantonio,

You are on the right track.  The only thing wrong is you close the progn at the wrong place.

Look at the comment below in the code section.

Also noted that I had put a setq obj (LM:Addtable......
You can do without it as we are using (entlast) to select the table.

Code: [Select]
                (if lst  ;Do we have a valid  list ?
                    (if (setq ins (getpoint "\nSpecify point for table: ")) ; Do we have a point
                       (progn ;added a progn here ymg
                        (vl-cmdf "_LAYER" "_M"  "table" "_C" "7" "" ""); make layer here ymg
                        (LM:addtable
                            (vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
                                (if (= 1 (getvar 'cvport))
                                    'paperspace
                                    'modelspace
                                )
                            )
                            (trans ins 1 0) ttl (cons hdl (reverse lst)) nil
                        )
                        (vl-cmdf "_SCALE" (entlast) "" ins 5) ; Replace the 5 with  desired scale here ymg
                      ); added end of progn we have a valid point here ymg 
                    )
                    (princ "\nNo valid data found in selected file.") ; this part executed if we don't have a valid list.
                )


ymg
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on November 30, 2013, 11:49:44 AM
ymg thank you for the help. Now the lisp work .  :-)
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on May 24, 2014, 10:55:58 AM
I want to ask a question.

We have this layer with color 7 here

Code - Auto/Visual Lisp: [Select]
  1. (vl-cmdf "_LAYER" "_M"  "table" "_C" "7" "" "")

if i want the text in the table have another color than the lines what changes i have to do in the code ?Be all in "table " layer ,only  change the color of the text

example lines color 7 , text color 30

Thanks

Title: Re: coordinate point list (*.txt file) and table
Post by: hanhphuc on May 25, 2014, 04:20:49 AM
@topographer, i don't know whether this demo suits you?
http://www.surveydrawing.net/free-excel-to-cad-software.html
Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on May 26, 2014, 12:53:10 AM
I try to add in text box 

Code: [Select]
(cons 62 3)
but nothing ....
Title: Re: coordinate point list (*.txt file) and table
Post by: hanhphuc on May 26, 2014, 02:45:46 AM
;;;According to the document
;;;Method
;;;object.SetRGB (Red, Green, Blue) ,where object=AcCmColor & R,G,B =Long

;;;Definations of AcCmColor
;;;AutoCAD true color object.
;;;
;;;VBA class name:
;;; AcadAcCmColor
;;;
;;;Create using:
;;; GetInterfaceObject ("AutoCAD.AcCmColor.16"), or
;;;Dim col As New AcadAcCmColor

I try follow step by step
;26/05/14 hp#008
Code: [Select]
(defun AcCmColor (color / AcCmC) ;color = index color

;Step1: get object
  (setq AcCmC (vla-getInterfaceObject
(vlax-get-acad-object)
"AutoCAD.AcCmColor.17" ;acad2007
      )
  )

;Step2: convert to RGB
  (vla-put-ColorIndex AcCmC color) ;where color behaves similar: (cons 62 color)

;Step3: result cons in a paired list = ( accmc (R G B))
  (cons AcCmC ;#<VLA-OBJECT IAcadAcCmColor ~ >
(list (vla-get-Red AcCmC)
      (vla-get-Green AcCmC)
      (vla-get-Blue AcCmC)
)
  )
) ;defun

; Try add the code below after (vla-settext... )

(apply 'vla-SetRGB (AcCmColor 3)); not (cons 62 3)

;;;Method
;;;object.SetCellContentColor(row, col, pColor)
;;;where object is IAcadTable & row,col=Long
;;;pColor = AcCmColor

(vla-SetCellContentColor obj row col (car(AcCmColor 3))); obj= IAcadTable in Lee's code
; where obj= IAcadTable is #<VLA-OBJECT IAcadTable ~ >
; (car(AcCmColor 2)) is #<VLA-OBJECT IAcadAcCmColor ~ >


Title: Re: coordinate point list (*.txt file) and table
Post by: pedroantonio on May 26, 2014, 03:15:34 AM
Hi hanhphuc  thank you for the help

Here is the code
Code - Auto/Visual Lisp: [Select]
  1. ;; Text File to Table  -  Lee Mac
  2. ;; Prompts the user to select a text file containing 4 columns of comma-delimited data
  3. ;; and generates an AutoCAD Table containing the file data at the point specified.
  4.  
  5. (defun c:txt2tab ( / *error* des ins lin lst txt hgt scl)
  6. (setq scl (getvar "useri1"))
  7.                        (setq hgt(* 0.0005 scl))
  8.     (defun *error* ( msg )
  9.         (if (= 'file (type des)) (close des))
  10.         (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  11.             (princ (strcat "\nError: " msg))
  12.         )
  13.         (princ)
  14.     )
  15.  
  16.     (if (setq txt (getfiled "choose a file   P,X,Y,Z (*.txt)" "" "txt" 16))
  17.         (if (setq des (open txt "r"))
  18.             (progn
  19.                 (while (setq lin (read-line des))
  20.                     (if (= 4 (length (setq lin (LM:str->lst lin ","))))
  21.                         (setq lst (cons lin lst))
  22.                     )
  23.                 )
  24.                 (setq des (close des))
  25.                 (if lst
  26.                     (if (setq ins (getpoint "\nSpecify point for table:"))
  27.                        (progn
  28.                         (vl-cmdf "_LAYER" "_M"  "table" "_C" "7" "" "")
  29.                    
  30.                          (setq obj (LM:addtable
  31.                                      (vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
  32.                                           (if (= 1 (getvar 'cvport))
  33.                                                      'paperspace
  34.                                                      'modelspace
  35.                                           )
  36.                                      )
  37.                                      (trans ins 1 0)
  38.                                     nil
  39.                                     (cons '("A/A" "X" "Y" "Z") (reverse lst))
  40.                                     nil
  41.                                    )
  42.                          )
  43.                          (vl-cmdf "_SCALE" (entlast) "" ins hgt) ; Replace the 5 with  desired scale here  
  44.                         )
  45.                     )
  46.                     (princ "\nNo valid data found in selected file.")
  47.                 )
  48.             )
  49.             (princ "\nUnable to open selected file for reading.")
  50.         )
  51.     )
  52.     (princ)
  53. )
  54.  
  55. ;;---------------------=={ Add Table }==----------------------;;
  56. ;;                                                            ;;
  57. ;;  Creates an AutoCAD Table Object at the specified point,   ;;
  58. ;;  populated with the given data and optional title.         ;;
  59. ;;------------------------------------------------------------;;
  60. ;; Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com     ;;
  61. ;;------------------------------------------------------------;;
  62. ;;  Arguments:                                                ;;
  63. ;;  spc - VLA Block Object                                    ;;
  64. ;;  ins - WCS Insertion Point for Table                       ;;
  65. ;;  ttl - [Optional] Table title                              ;;
  66. ;;  lst - Matrix list of data to populate the table           ;;
  67. ;;  eqc - If T, columns are of equal width                    ;;
  68. ;;------------------------------------------------------------;;
  69. ;;  Returns:  VLA Table Object                                ;;
  70. ;;------------------------------------------------------------;;
  71.  
  72. (defun LM:AddTable ( spc ins ttl lst eqc / dif hgt i j obj stn sty wid )
  73.     (setq sty
  74.         (vlax-ename->vla-object
  75.             (cdr
  76.                 (assoc -1
  77.                     (dictsearch
  78.                         (cdr
  79.                             (assoc -1
  80.                                 (dictsearch (namedobjdict) "acad_tablestyle")
  81.                             )
  82.                         )
  83.                         (getvar 'ctablestyle)
  84.                     )
  85.                 )
  86.             )
  87.         )
  88.     )
  89.     (setq hgt (vla-gettextheight sty acdatarow))
  90.     (if (LM:Annotative-p (setq stn (vla-gettextstyle sty acdatarow)))
  91.         (setq hgt (/ hgt (getvar 'cannoscalevalue)))
  92.     )
  93.     (setq wid
  94.         (mapcar
  95.             (function
  96.                 (lambda ( col )
  97.                     (apply 'max
  98.                         (mapcar
  99.                             (function
  100.                                 (lambda ( str )
  101.                                     (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
  102.                                         (textbox
  103.                                             (list
  104.                                                 (cons 01 str)
  105.                                                 (cons 40 hgt)
  106.                                                 (cons 07 stn)
  107.                                             )
  108.                                         )
  109.                                     )
  110.                                 )
  111.                             )
  112.                             col
  113.                         )
  114.                     )
  115.                 )
  116.             )
  117.             (apply 'mapcar (cons 'list lst))
  118.         )
  119.     )
  120.     (if
  121.         (and ttl
  122.             (< 0.0
  123.                 (setq dif
  124.                     (/
  125.                         (-
  126.                             (   (lambda ( box ) (if box (+ (* 2.5 hgt) (- (caadr box) (caar box))) 0.0))
  127.                                 (textbox
  128.                                     (list
  129.                                         (cons 01 ttl)
  130.                                         (cons 40 hgt)
  131.                                         (cons 07 stn)
  132.                                     )
  133.                                 )
  134.                             )
  135.                             (apply '+ wid)
  136.                         )
  137.                         (length wid)
  138.                     )
  139.                 )
  140.             )
  141.         )
  142.         (setq wid (mapcar '(lambda ( x ) (+ x dif)) wid))
  143.     )
  144.     (setq obj
  145.         (vla-addtable spc
  146.             (vlax-3D-point ins)
  147.             (1+ (length lst))
  148.             (length (car lst))
  149.             (* 2.0 hgt)
  150.             (if eqc
  151.                 (apply 'max wid)
  152.                 (/ (apply '+ wid) (float (length (car lst))))
  153.             )
  154.         )
  155.     )
  156.     (vla-put-regeneratetablesuppressed obj :vlax-true)
  157.     (vla-put-stylename obj (getvar 'ctablestyle))
  158.     (setq i -1)
  159.     (if (null eqc)
  160.         (foreach col wid
  161.             (vla-setcolumnwidth obj (setq i (1+ i)) col)
  162.         )
  163.     )
  164.     (if ttl
  165.         (progn
  166.             (vla-settext obj 0 0 ttl)  
  167.             (setq i 1)
  168.         )
  169.         (progn
  170.             (vla-deleterows obj 0 1)
  171.             (setq i 0)
  172.         )
  173.     )
  174.     (foreach row lst
  175.         (setq j 0)
  176.         (foreach val row
  177.             (vla-settext obj i j val)
  178.             (setq j (1+ j))
  179.         )
  180.         (setq i (1+ i))
  181.     )
  182.     (vla-put-regeneratetablesuppressed obj :vlax-false)
  183.     obj
  184. )
  185.  
  186. ;; Annotative-p
  187. ;; Returns T if the given Textstyle is annotative
  188.  
  189. (defun LM:annotative-p ( sty )
  190.     (and (setq sty (tblobjname "style" sty))
  191.          (setq sty (cadr (assoc -3 (entget sty '("AcadAnnotative")))))
  192.          (= 1 (cdr (assoc 1070 (reverse sty))))
  193.     )
  194. )
  195.  
  196. ;; String to List
  197. ;; Separates a string using a given delimiter
  198. ;; str - [str] string to process
  199. ;; del - [str] delimiter by which to separate the string
  200.  
  201. (defun LM:str->lst ( str del / pos )
  202.     (if (setq pos (vl-string-search del str))
  203.         (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
  204.         (list str)
  205.     )
  206. )
  207.  

i add after
Code: [Select]
    (vla-settext obj 0 0 ttl) 
Code - Auto/Visual Lisp: [Select]
  1. (defun AcCmColor (30/ AcCmC)    ;color = index color
  2.  
  3. ;Step1: get object
  4.                 (vlax-get-acad-object)
  5.                 "AutoCAD.AcCmColor.17" ;acad2007
  6.               )
  7.   )
  8.  
  9.                                         ;Step2: convert to RGB
  10.   (vla-put-ColorIndex AcCmC 30) ;where color behaves similar: (cons 62 color)
  11.  
  12.                                         ;Step3: result cons in a paired list = ( accmc (R G B))
  13.   (cons AcCmC                           ;#<VLA-OBJECT IAcadAcCmColor ~ >
  14.         (list (vla-get-Red AcCmC)
  15.               (vla-get-Green AcCmC)
  16.               (vla-get-Blue AcCmC)
  17.         )
  18.   )
  19. )                                       ;defun
  20.  

but nothing ...