Jump to content

Recommended Posts

Posted (edited)

I write a lisp to fill data in a table from txt file and then the code do some calculation to fill the data in the rest of the colums

the txt file is like  this (i upload one)

 

1,0,0.00,0.00
2,3.95,0.00,0.00
3,20,0.34,2.40
4,40,0.35,0.00
5,60,0.00,1.23
6,80,0.00,1.10
7,100,0.00,0.32
8,114.419,0.00,0.36
9,134.75,0.01,0.17
10,155.08,0.05,1.17
11,175.08,0.00,1.40
12,191.753,0.00,1.78
13,194.78,0.01,0.79

 

before try to write this code use excell to do this. For the calculations  use this functions

 

calculation in column C
=IF(B4=0;0;B4-B3)
explain if  B4=0 then c3=0 if not then c3=B4-B3


calculation in column D

for line 3  =IF(B3=0;C3/2)
explain if  B3=0 then d3=c3/2

for the rest lines =IF(B3=0;C3/2;(C4+C3)/2)
explain if  B3=0 then d3=c3/2 if not then d3=(c4-c3)/2

calculation in column G 

G=D*E columns

calculation in column H 

H=D*F columns

At the end add a last line in the table and write


SUM              sumG  sumH 

 

Can any one help to fill the calculations  for the rest of the colums ?

 

(defun read-data-from-file (filename del)
  (setq file (open filename "r"))
  (setq data '())
  (while (setq line (read-line file))
    (setq data (cons (LM:str->lst line del) data))
  )
  (close file)
  (reverse data)
)

(defun LM:str->lst (str del / len lst pos)
  ;; String to List - Lee Mac
  (setq len (1+ (strlen del)))
  (while (setq pos (vl-string-search del str))
    (setq lst (cons (substr str 1 pos) lst)
          str (substr str (+ pos len))
    )
  )
  (reverse (cons str lst))
)

(defun create-table (doc title lst ipt / spc t_obj rows cols row cell)
  (setq spc (vlax-get-property doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
        t_obj (vla-addtable spc (vlax-3d-point ipt) (+ 2 (length lst)) 8 5.0 22.5) ; Set column count to 8
  )
  (vla-put-regeneratetablesuppressed t_obj :vlax-true)
  (mapcar (function (lambda (x y) (vlax-put-property t_obj x y))) (list 'horzcellmargin 'vertcellmargin 'rowheight) (list 0.5 0.5 5.0))
  (vla-settextstyle t_obj (+ acDataRow acHeaderRow acTitleRow) "TOPOCAD")
  
  ;; Title row
  (vlax-invoke t_obj 'setrowheight 0 10.0)
  (vlax-invoke t_obj 'setcelltextheight 0 0 2.5)
  (vlax-invoke t_obj 'settext 0 0 title)
  
  ;; Column headers row
  (setq headers '("0" "1" "2" "3" "4" "5" "6" "7"))
  (vlax-invoke t_obj 'setrowheight 1 10.0)
  (vlax-invoke t_obj 'setcelltextheight 1 0 2.5)
  (setq cell 0)
  (foreach header headers
    (vlax-invoke t_obj 'settext 1 cell header)
    (vlax-invoke t_obj 'setcelltextheight 1 cell 2.5)
    (setq cell (1+ cell))
  )
  
  (setq rows (vlax-get t_obj 'rows)
        cols (1- (vlax-get t_obj 'columns))
        row 2
  )
  
  ;; Loop through data cells and fill columns 1, 2, 5, 6
  (while (< row rows)
    (setq rdat (nth (- row 2) lst))
    (vlax-invoke t_obj 'setcelltextheight row 0 2.5)
    (vlax-invoke t_obj 'settext row 0 (nth 0 rdat))
    (vlax-invoke t_obj 'setcellalignment row 0 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 1 2.5)
    (vlax-invoke t_obj 'settext row 1 (nth 1 rdat))
    (vlax-invoke t_obj 'setcellalignment row 1 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 4 2.5)
    (vlax-invoke t_obj 'settext row 4 (nth 2 rdat))
    (vlax-invoke t_obj 'setcellalignment row 4 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 5 2.5)
    (vlax-invoke t_obj 'settext row 5 (nth 3 rdat))
    (vlax-invoke t_obj 'setcellalignment row 5 acMiddleCenter)
    
    (setq row (1+ row))
  )
  
  ;; Adjust column width
  (vla-setcolumnwidth t_obj 0 30)
  (vla-setcolumnwidth t_obj 1 30)
  (vla-setcolumnwidth t_obj 2 30)
  (vla-setcolumnwidth t_obj 3 30)
  (vla-setcolumnwidth t_obj 4 30)
  (vla-setcolumnwidth t_obj 5 30)
  (vla-setcolumnwidth t_obj 6 30)
  (vla-setcolumnwidth t_obj 7 30)
  
  (vla-put-regeneratetablesuppressed t_obj :vlax-false)
)

(defun c:test ()
  (vl-cmdf "_.UNDO" "_BE")
  ;; Define your delimiter (e.g., comma, semicolon)
  (setq del ",")
  (if (setq filename (getfiled "Select Data File" "" "txt;csv" 16))
    (if (setq data (read-data-from-file filename del))
      (progn
        (setq title "============= text ==================")
        (if (setq ins (getpoint "\nSpecify insertion point for table: "))
          (create-table (vla-get-activedocument (vlax-get-acad-object)) title data ins)
          (princ "\nNo valid data found in the selected file.")
        )
      )
      (princ "\nUnable to open the selected file for reading.")
    )
  )
  (vl-cmdf "_.UNDO" "_E")
  (princ)
)

 

Thanks

 

Edited by mhy3sx
Posted (edited)

I update the code with the calculatios in column 3 but something is missing. look the dwg  to understand . Delete data from column 6  and more

 

(defun read-data-from-file (filename del)
  (setq file (open filename "r"))
  (setq data '())
  (while (setq line (read-line file))
    (setq data (cons (LM:str->lst line del) data))
  )
  (close file)
  (reverse data)
)

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

(defun generate-sequence (start end)
  (if (<= start end)
    (cons start (generate-sequence (1+ start) end))
    '()
  )
)

(defun calculate-column-3 (data)
  (mapcar
    (lambda (row i)
      (cond
        ((zerop i) ; For the first row
         (cons (nth 0 row) (cons (nth 1 row) (cons (nth 1 row) (cdddr row)))))
        ((and (> i 0) (<= i (1- (length data))) (not (zerop (atof (nth 1 row)))))
         (cons (nth 0 row) (cons (nth 1 row) (cons (rtos (- (atof (nth 1 row)) (atof (nth 1 (nth (1- i) data))))) (cdddr row)))))
        (t
         (cons (nth 0 row) (cons (nth 1 row) (cons "0" (cdddr row)))))
      )
    ) data (generate-sequence 0 (1- (length data)))
  )
)

(defun create-table (doc title lst ipt / spc t_obj rows cols row cell)
  (setq spc (vlax-get-property doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
        t_obj (vla-addtable spc (vlax-3d-point ipt) (+ 2 (length lst)) 8 5.0 22.5)
  )
  (vla-put-regeneratetablesuppressed t_obj :vlax-true)
  (mapcar (function (lambda (x y) (vlax-put-property t_obj x y))) (list 'horzcellmargin 'vertcellmargin 'rowheight) (list 0.5 0.5 5.0))
  (vla-settextstyle t_obj (+ acDataRow acHeaderRow acTitleRow) "TOPOCAD")

  (vlax-invoke t_obj 'setrowheight 0 10.0)
  (vlax-invoke t_obj 'setcelltextheight 0 0 2.5)
  (vlax-invoke t_obj 'settext 0 0 title)

  (setq headers '("0" "1" "2" "3" "4" "5" "6" "7"))
  (vlax-invoke t_obj 'setrowheight 1 10.0)
  (vlax-invoke t_obj 'setcelltextheight 1 0 2.5)
  (setq cell 0)
  (foreach header headers
    (vlax-invoke t_obj 'settext 1 cell header)
    (vlax-invoke t_obj 'setcelltextheight 1 cell 2.5)
    (setq cell (1+ cell))
  )

  (setq rows (vlax-get t_obj 'rows)
        cols (1- (vlax-get t_obj 'columns))
        row 2
  )

  (while (< row rows)
    (setq rdat (nth (- row 2) lst))
    (vlax-invoke t_obj 'setcelltextheight row 0 2.5)
    (vlax-invoke t_obj 'settext row 0 (nth 0 rdat))
    (vlax-invoke t_obj 'setcellalignment row 0 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 1 2.5)
    (vlax-invoke t_obj 'settext row 1 (nth 1 rdat))
    (vlax-invoke t_obj 'setcellalignment row 1 acMiddleCenter)

    (vlax-invoke t_obj 'setcelltextheight row 2 2.5)
    (vlax-invoke t_obj 'settext row 2 (nth 2 rdat))
    (vlax-invoke t_obj 'setcellalignment row 2 acMiddleCenter)

    (vlax-invoke t_obj 'setcelltextheight row 4 2.5)
    (vlax-invoke t_obj 'settext row 4 (nth 3 rdat))
    (vlax-invoke t_obj 'setcellalignment row 4 acMiddleCenter)
    
    (setq row (1+ row))
  )

  (vla-setcolumnwidth t_obj 0 30)
  (vla-setcolumnwidth t_obj 1 30)
  (vla-setcolumnwidth t_obj 2 30)
  (vla-setcolumnwidth t_obj 3 30)
  (vla-setcolumnwidth t_obj 4 30)
  (vla-setcolumnwidth t_obj 5 30)
  (vla-setcolumnwidth t_obj 6 30)
  (vla-setcolumnwidth t_obj 7 30)

  (vla-put-regeneratetablesuppressed t_obj :vlax-false)
)

(defun c:vt ()
  (vl-cmdf "_.UNDO" "_BE")
  (setq del ",")
  (if (setq filename (getfiled "Select Data File" "" "txt;csv" 16))
    (if (setq data (read-data-from-file filename del))
      (progn
        (setq title "============= text ==================")
        (setq data (calculate-column-3 data))
        (if (setq ins (getpoint "\nSpecify insertion point for table: "))
          (create-table (vla-get-activedocument (vlax-get-acad-object)) title data ins)
          (princ "\nNo valid data found in the selected file.")
        )
      )
      (princ "\nUnable to open the selected file for reading.")
    )
  )
  (vl-cmdf "_.UNDO" "_E")
  (princ)
)

 

 

 

Edited by mhy3sx
Posted (edited)

any ideas?

 

Thanks

Edited by mhy3sx
Posted (edited)

I update the code. Dont delete data in rows now , but the calculation in column C is not in exactly in the correct possition. Look the dwg file.

 

(defun read-data-from-file (filename del)
  (setq file (open filename "r"))
  (setq data '())
  (while (setq line (read-line file))
    (setq data (cons (LM:str->lst line del) data))
  )
  (close file)
  (reverse data)
)

(defun LM:str->lst (str del / len lst pos)
  ;; String to List - Lee Mac
  (setq len (1+ (strlen del)))
  (while (setq pos (vl-string-search del str))
    (setq lst (cons (substr str 1 pos) lst)
          str (substr str (+ pos len))
    )
  )
  (reverse (cons str lst))
)

(defun create-table (doc title lst ipt / spc t_obj rows cols row cell)
  (setq spc (vlax-get-property doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
        t_obj (vla-addtable spc (vlax-3d-point ipt) (+ 2 (length lst)) 8 5.0 22.5) ; Set column count to 8
  )
  (vla-put-regeneratetablesuppressed t_obj :vlax-true)
  (mapcar (function (lambda (x y) (vlax-put-property t_obj x y))) (list 'horzcellmargin 'vertcellmargin 'rowheight) (list 0.5 0.5 5.0))
  (vla-settextstyle t_obj (+ acDataRow acHeaderRow acTitleRow) "TOPOCAD")
  
  ;; Title row
  (vlax-invoke t_obj 'setrowheight 0 10.0)
  (vlax-invoke t_obj 'setcelltextheight 0 0 2.5)
  (vlax-invoke t_obj 'settext 0 0 title)
  
  ;; Column headers row
  (setq headers '("0" "1" "2" "3" "4" "5" "6" "7"))
  (vlax-invoke t_obj 'setrowheight 1 10.0)
  (vlax-invoke t_obj 'setcelltextheight 1 0 2.5)
  (setq cell 0)
  (foreach header headers
    (vlax-invoke t_obj 'settext 1 cell header)
    (vlax-invoke t_obj 'setcelltextheight 1 cell 2.5)
    (setq cell (1+ cell))
  )
  
  (setq rows (vlax-get t_obj 'rows)
        cols (1- (vlax-get t_obj 'columns))
        row 2
  )
  
  ;; Loop through data cells and fill columns 0, 1, 2, 4, 5
  (while (< row rows)
    (setq rdat (nth (- row 2) lst))
    (vlax-invoke t_obj 'setcelltextheight row 0 2.5) ; Column A
    (vlax-invoke t_obj 'settext row 0 (nth 0 rdat))
    (vlax-invoke t_obj 'setcellalignment row 0 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 1 2.5) ; Column B
    (vlax-invoke t_obj 'settext row 1 (nth 1 rdat))
    (vlax-invoke t_obj 'setcellalignment row 1 acMiddleCenter)
    
    ;; Calculate Column C value
    (if (or (= row 2) (not (nth 1 (nth (- row 3) lst)))) 
      (setq c-value (if (= row 2) (atof (nth 1 rdat)) 0))
      (setq c-value (if (= (atof (nth 1 rdat)) 0)
                       0
                       (- (atof (nth 1 rdat)) (atof (nth 1 (nth (- row 3) lst))))))
    )
    
    (vlax-invoke t_obj 'setcelltextheight row 2 2.5) ; Column C
    (vlax-invoke t_obj 'settext row 2 (rtos c-value 2 2))
    (vlax-invoke t_obj 'setcellalignment row 2 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 4 2.5) ; Column E
    (vlax-invoke t_obj 'settext row 4 (nth 2 rdat))
    (vlax-invoke t_obj 'setcellalignment row 4 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 5 2.5) ; Column F
    (vlax-invoke t_obj 'settext row 5 (nth 3 rdat))
    (vlax-invoke t_obj 'setcellalignment row 5 acMiddleCenter)
    
    (setq row (1+ row))
  )
  
  ;; Adjust column width
  (vla-setcolumnwidth t_obj 0 30) ; Adjust column widths as needed
  (vla-setcolumnwidth t_obj 1 30)
  (vla-setcolumnwidth t_obj 2 30)
  (vla-setcolumnwidth t_obj 3 30)
  (vla-setcolumnwidth t_obj 4 30)
  (vla-setcolumnwidth t_obj 5 30)
  (vla-setcolumnwidth t_obj 6 30)
  (vla-setcolumnwidth t_obj 7 30)
  
  (vla-put-regeneratetablesuppressed t_obj :vlax-false)
)


(defun c:vt ()
  (vl-cmdf "_.UNDO" "_BE")
  ;; Define your delimiter (e.g., comma, semicolon)
  (setq del ",")
  (if (setq filename (getfiled "Select Data File" "" "txt;csv" 16))
    (if (setq data (read-data-from-file filename del))
      (progn
        (setq title "============= text ==================")
        (if (setq ins (getpoint "\nSpecify insertion point for table: "))
          (create-table (vla-get-activedocument (vlax-get-acad-object)) title data ins)
          (princ "\nNo valid data found in the selected file.")
        )
      )
      (princ "\nUnable to open the selected file for reading.")
    )
  )
  (vl-cmdf "_.UNDO" "_E")
  (princ)
)

 

The calculations in excell will be like this. Help me to update the lisp

 

calculation in column C
=IF(B4=0;0;B4-B3)
explain if  B4=0 then c3=0 if not then c3=B4-B3


calculation in column D

for line 3  =IF(B8=0;C8/2)
explain if  B3=0 then d3=c3/2

for the rest lines =IF(B9=0;C9/2;(C9+C8)/2)
explain if  B3=0 then d3=c3/2 if not then d3=(c4-c3)/2

calculation in column G 

G=D*E columns

calculation in column H 

H=D*F columns

At the end add a last line in the table and write


SUM          sumD    sumG  sumH

Thanks

 

Edited by mhy3sx
Posted (edited)

You appear to have a list of all the values so do one row at a time column C would be for a row (- (  Nth (1+ x)  lst) (nth x lst)). Note need to do for one less than the length of list as the last entry will error as there is no dummy value past the last item in the list. Then do last row.

 

I tend to use Insertrows in a table much easier as you just read each line of the list and add a row. 

 

Can read excel direct if you want.

 

(vla-insertrows objtable  numrows  (vla-GetRowHeight objtable (1- numrows)) 1)

 

 

Edited by BIGAL
  • Like 1
Posted

Hi BIGAL I finished the code but I need to ask somethig simple

 

I want to add two decimals in the results and add

 

(rtos 2 2)

To the results  but is not working. Can you  help me to fix it. Is any other way to set 2 decimals?

 

 

(defun read-data-from-file (filename del)
  (setq file (open filename "r"))
  (setq data '())
  (while (setq line (read-line file))
    (setq data (cons (LM:str->lst line del) data))
  )
  (close file)
  (reverse data)
)

(defun LM:str->lst (str del / len lst pos)
  ;; String to List - Lee Mac
  (setq len (1+ (strlen del)))
  (while (setq pos (vl-string-search del str))
    (setq lst (cons (substr str 1 pos) lst)
          str (substr str (+ pos len))
    )
  )
  (reverse (cons str lst))
)

(defun create-table (doc title lst ipt / spc t_obj rows cols row cell rdat c-value d-value g-value h-value prev-c-value d-sum g-sum h-sum)
  (setq spc (vlax-get-property doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
        t_obj (vla-addtable spc (vlax-3d-point ipt) (+ 2 (length lst)) 8 5.0 22.5)) ; Set column count to 8
  (vla-put-regeneratetablesuppressed t_obj :vlax-true)
  (mapcar (function (lambda (x y) (vlax-put-property t_obj x y))) (list 'horzcellmargin 'vertcellmargin 'rowheight) (list 0.5 0.5 5.0))
  (vla-settextstyle t_obj (+ acDataRow acHeaderRow acTitleRow) "TOPOCAD")
  
  ;; Title row
  (vlax-invoke t_obj 'setrowheight 0 10.0)
  (vlax-invoke t_obj 'setcelltextheight 0 0 2.5)
  (vlax-invoke t_obj 'settext 0 0 title)
  
  ;; Column headers row
  (setq headers '("0" "1" "2" "3" "4" "5" "6" "7"))
  (vlax-invoke t_obj 'setrowheight 1 10.0)
  (vlax-invoke t_obj 'setcelltextheight 1 0 2.5)
  (setq cell 0)
  (foreach header headers
    (vlax-invoke t_obj 'settext 1 cell header)
    (vlax-invoke t_obj 'setcelltextheight 1 cell 2.5)
    (setq cell (1+ cell))
  )
  
  (setq rows (vlax-get t_obj 'rows)
        cols (1- (vlax-get t_obj 'columns))
        row 2
        prev-c-value 0
        d-sum 0
        g-sum 0
        h-sum 0)
  
  ;; Loop through data cells and fill columns 0, 1, 2, 3, 4, 5, 6, 7
  (while (< row rows)
    (setq rdat (nth (- row 2) lst))
    (vlax-invoke t_obj 'setcelltextheight row 0 2.5) ; Column A, 0 
    (vlax-invoke t_obj 'settext row 0 (nth 0 rdat))
    (vlax-invoke t_obj 'setcellalignment row 0 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 1 2.5) ; Column B, 1
    (vlax-invoke t_obj 'settext row 1 (nth 1 rdat))
    (vlax-invoke t_obj 'setcellalignment row 1 acMiddleCenter)
    
    ;; Calculate Column C value for current row based on next row
    (if (< row (1- rows))
      (setq c-value (if (nth 1 (nth (- row 1) lst))
                     (- (atof (nth 1 (nth (- row 1) lst))) (atof (nth 1 rdat)))
                     0))
      (setq c-value 0)) ; Last row
    
    (vlax-invoke t_obj 'setcelltextheight row 2 2.5) ; Column C, 2
    (vlax-invoke t_obj 'settext row 2 (rtos c-value 2 2)) ; 2 decimal places
    (vlax-invoke t_obj 'setcellalignment row 2 acMiddleCenter)
    
    ;; Calculate Column D value based on conditions
    (if (= (nth 1 rdat) "0")
      (setq d-value (/ c-value 2))
      (setq d-value (/ (+ c-value prev-c-value) 2))
    )
    
    (vlax-invoke t_obj 'setcelltextheight row 3 2.5) ; Column D, 3
    (vlax-invoke t_obj 'settext row 3 (rtos d-value 2 2)) ; 2 decimal places
    (vlax-invoke t_obj 'setcellalignment row 3 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 4 2.5) ; Column E, 4
    (vlax-invoke t_obj 'settext row 4 (nth 2 rdat))
    (vlax-invoke t_obj 'setcellalignment row 4 acMiddleCenter)
    
    (vlax-invoke t_obj 'setcelltextheight row 5 2.5) ; Column F, 5
    (vlax-invoke t_obj 'settext row 5 (nth 3 rdat))
    (vlax-invoke t_obj 'setcellalignment row 5 acMiddleCenter)
  
    ;; Calculate Column G value: G = D * E
    (setq g-value (* d-value (atof (nth 2 rdat))))
    
    (vlax-invoke t_obj 'setcelltextheight row 6 2.5) ; Column G, 6
    (vlax-invoke t_obj 'settext row 6 (rtos g-value 2 2)) ; 2 decimal places
    (vlax-invoke t_obj 'setcellalignment row 6 acMiddleCenter)
    
    ;; Calculate Column H value: H = D * F
    (setq h-value (* d-value (atof (nth 3 rdat))))
    
    (vlax-invoke t_obj 'setcelltextheight row 7 2.5) ; Column H, 7
    (vlax-invoke t_obj 'settext row 7 (rtos h-value 2 2)) ; 2 decimal places
    (vlax-invoke t_obj 'setcellalignment row 7 acMiddleCenter)
    
    ;; Save the current C value for the next row calculation
    (setq prev-c-value c-value)
    
    ;; Add current row values to sums
    (setq d-sum (+ d-sum d-value))
    (setq g-sum (+ g-sum g-value))
    (setq h-sum (+ h-sum h-value))
  
    (setq row (1+ row))
  )
  
  ;; Add final row for sums
  (setq row rows)
  (vlax-invoke t_obj 'insertrows row 1.0 1)
  (vlax-invoke t_obj 'setcelltextheight row 0 2.5) ; Column A, 0
  (vlax-invoke t_obj 'settext row 0 "SUM")
  (vlax-invoke t_obj 'setcellalignment row 0 acMiddleCenter)
  
  (vlax-invoke t_obj 'setcelltextheight row 3 2.5) ; Column D, 3
  (vlax-invoke t_obj 'settext row 3 (rtos d-sum 2 2)) ; 2 decimal places
  (vlax-invoke t_obj 'setcellalignment row 3 acMiddleCenter)
  
  (vlax-invoke t_obj 'setcelltextheight row 6 2.5) ; Column G, 6
  (vlax-invoke t_obj 'settext row 6 (rtos g-sum 2 2)) ; 2 decimal places
  (vlax-invoke t_obj 'setcellalignment row 6 acMiddleCenter)
  
  (vlax-invoke t_obj 'setcelltextheight row 7 2.5) ; Column H, 7
  (vlax-invoke t_obj 'settext row 7 (rtos h-sum 2 2)) ; 2 decimal places
  (vlax-invoke t_obj 'setcellalignment row 7 acMiddleCenter)
  
  ;; Adjust column width
  (vla-setcolumnwidth t_obj 0 30) ; Adjust column widths as needed
  (vla-setcolumnwidth t_obj 1 30)
  (vla-setcolumnwidth t_obj 2 30)
  (vla-setcolumnwidth t_obj 3 30)
  (vla-setcolumnwidth t_obj 4 30)
  (vla-setcolumnwidth t_obj 5 30)
  (vla-setcolumnwidth t_obj 6 30)
  (vla-setcolumnwidth t_obj 7 30)
  
  (vla-put-regeneratetablesuppressed t_obj :vlax-false)
)




(defun c:vt ()
  (vl-cmdf "_.UNDO" "_BE")
  ;; Define your delimiter (e.g., comma, semicolon)
  (setq del ",")
  (if (setq filename (getfiled "Select Data File" "" "txt;csv" 16))
    (if (setq data (read-data-from-file filename del))
      (progn
        (setq title "============= text ==================")
        (if (setq ins (getpoint "\nSpecify insertion point for table: "))
          (create-table (vla-get-activedocument (vlax-get-acad-object)) title data ins)
          (princ "\nNo valid data found in the selected file.")
        )
      )
      (princ "\nUnable to open the selected file for reading.")
    )
  )
  (vl-cmdf "_.UNDO" "_E")
  (princ)
)

 

1.jpg

Posted (edited)

A possible easy fix try this (setvar 'dimzin 2) at start of code.

 

: (setq num 20)
20
: (rtos num 2 2)
"20.00"

: (setq num 12.5)
12.5
: (rtos num 2 2)
"12.50"

: (setq num 12.345)
12.345
: (rtos num 2 2)
"12.35"

Some extra hints

;; Set the text height for the Title, Header and Data rows
 (vla-SetTextHeight custObj acDataRow txtht)
 (vla-SetTextHeight custObj acHeaderRow (* txtht 1.2))
 (vla-SetTextHeight custObj acTitleRow (* txtht 1.5))


; Set the alignment for the Data, Header, and Title rows
 (vla-SetAlignment custObj (+ acDataRow acHeaderRow acTitleRow) acMiddleCenter)

(vla-SetTextStyle custObj (+ acDataRow acHeaderRow acTitleRow) "Arial")

 

Edited by BIGAL
  • Like 1

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...