Jump to content

coordinate point list (*.txt file) and table


Guest

Recommended Posts

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    6

  • MSasu

    4

  • shailujp

    2

  • Tuns

    1

Top Posters In This Topic

Posted Images

Nice lisp Mr Lee.If i need only (N,X,Y) what i need to do ?

1,309922.37,4242993.50
2,309928.18,4243002.99
3,309929.57,4243003.76
4,309930.81,4243004.45
5,309931.97,4243003.84
6,309933.59,4243003.00
7,309941.05,4242999.26
8,309946.61,4242996.29
9,309951.36,4242993.40
10,309954.93,4242991.36
11,309952.39,4242985.47
12,309949.97,4242979.80
13,309948.47,4242976.55
14,309948.03,4242976.72
15,309945.16,4242978.20
16,309944.86,4242978.41
17,309939.39,4242982.16
18,309937.52,4242983.45
19,309930.32,4242988.39
20,309925.14,4242991.84

Link to comment
Share on other sites

Hi Lee,

 

I have a similar request. Can you help me on this. I have been looking for something very similar what you have just posted.

 

The only difference is that I have excel file instead of txt file. But that can be changed.

 

Can my data be inserted as table just by specifying the excel file (or automatically detect the file name that I saved by this lisp) and insertion point rather than going via datalink and then table...

 

Thanks in advance

XYT21.lsp

Link to comment
Share on other sites

Hi shailujp,

 

You could save your Excel file to a tab-delimited text file format, which could then be imported using the program I have posted in reply#5.

Though, you would need to change the data delimiter parameter found at the top of the program source code from:

del "," ;; Data Delimiter String

to a tab character:

del "\t" ;; Data Delimiter String

I hope this helps!

Link to comment
Share on other sites

Hi Lee,

 

So I changed the lisp per what you explained. I also changed the following line so that it gives me 5 columns inserted vs just 3 per your original program.

 

 
hdl '("Sr No" "X:" "Y:" "Dia:" "Type") ;; Table Headings

 

Now, the issue is that I get two headings since I already have headings at the top of my data and again the "hdl" is again creating one more heading. I could not fix it.

 

New Picture.jpg

 

Also, how can this two lisp (yours and mine) be merged so when I run XYT21 lisp it creates the excel file and brings it in as a table (without having to locate the excel file)?

 

Please excuse my inexperience but should there be only few lines on my lisp that just brings a datalinked table rather then the huge program? Something like "_.-table" and then look for the same file that my lisp creates and use the table format same as excel format via datalink?

 

This is how I was planning and doing my trial and error before this post.

 

I'm not sure which is a better option. Please guide.

Link to comment
Share on other sites

  • 1 month later...

Why has my name been removed from all of my subfunctions? :x

 

EDIT: I see that the post in question has now been removed, but I am still curious as to why you (prodromosm) would go to the trouble of removing my name from every function used in the program?

 

Nevertheless, you will receive no more code from me prodromosm.

Edited by Lee Mac
Link to comment
Share on other sites

Why has my name been removed from all of my subfunctions? :x

 

EDIT: I see that the post in question has now been removed, but I am still curious as to why you (prodromosm) would go to the trouble of removing my name from every function used in the program?

 

Nevertheless, you will receive no more code from me prodromosm.

 

Lee I translate it to my language to understand it ........ok .It was a mistake of me sorry

Link to comment
Share on other sites

So why would the translation retain all other headings except my name? :roll:

He probably did that so that the people he works with will think he wrote it and not you. That would be my guess at least because I see no plausible reason for ONLY your name to be removed.

Link to comment
Share on other sites

He probably did that so that the people he works with will think he wrote it and not you. That would be my guess at least because I see no plausible reason for ONLY your name to be removed.

 

this is not true :nono:

Link to comment
Share on other sites

I want to add a command to give the text size , all the times have text size 4.5 and is too big

;; 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 "Επιλέξτε το αρχείο  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  -  [url]www.lee-mac.com[/url]     ;;
;;------------------------------------------------------------;;
;;  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  -  [url]www.lee-mac.com[/url]            ;;
;;----------------------------------------------------------------------;;

(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 "Επιλέξτε το αρχείο  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  -  [url]www.lee-mac.com[/url]              ;;
;;----------------------------------------------------------------------;;
;;  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                              ;;
;;----------------------------------------------------------------------;;

Edited by prodromosm
Link to comment
Share on other sites

What I was suggesting you was to call the aforementioned command and adjust there the prefered text height; next call Lee Mac's tool to insert the table.

Link to comment
Share on other sites

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