Jump to content

Recommended Posts

Posted

Hi i need a lisp to convert a csv file to txt (is an ascii file with spesific structure). I rename it to *txt   to open it with notepad.

 

Please help me because i have to convert a lot of coordinates 

 

Thanks

test.txt test.csv

Posted (edited)

This is a survey instrument data file, so before everyone jumps in, 99% of instruments can read a csv file.

 

So provide a reason why you are not using that method rather than waste a lot of peoples time. I know what I am talking about I worked for Topcon.

 

Is it because you do not want to pay the instrument maker for a upload / download program ? These should be free just do a bit of a google.

 

 

Edited by BIGAL
Posted (edited)

Hi Bigal. My total station not support csv files. I have  check it. 

Edited by prodromosm
Posted

That text file looks to be in Leica GSI-16 format which is space delineated.

 

Have you asked Leica for a conversion programme?

Posted

In fact Leica Survey Office, which I got as a free download, does the conversion. Attached is your test file converted in one second.

test.gsi

Posted

`leica program is not working properly in win 7,win8,win 10. Works good only in windows XP ,and i dont have windows XP. Unfortunately Leica is a big super market for me  nothing more. The don't support us at all. They don't have usb drivers for win 10 ...... I test everything i can find in the  internet ...an excell file that convert to gsi , a leica geosystem program that convert to gsi but all the times i find errors in the gsi files . This programs not work for me. So i need a lisp file to do the job. Realy i try but nothing is working.

Posted

Your instrument must be quite old if it cannot handle .csv files.

 

I use Leica Survey Office on a Windows 10 computer which is running a virtual Windows XP, and a virtual Windows 98 (so I can still use Quick Basic).

 

Best of luck with finding your .lsp file, or get a computer with Windows XP running.

 

If you want the format of the GSI data, you should get the TPS 1000 System Manual.

Posted

can any one convert this csv file to gsi file with lisp?

 

Thanks

Posted

Yes my insturment is old and i need this lisp file. Can any one help?

Posted

I find this lisp code bu is not working .Can any one update it to support csv files and convert them to gsi?

 

(defun c:to-tc()
(defun *error* (msg)
       (princ "error: ")
       (princ msg)
       (terpri)
)
===========================
(setq ha (getvar "pdsize"))
(setq pds (* ha 2.0))
(setq pass (getvar "maxsort"))
(if (= pass 1001)
(progn
(setq i (open "c:/tc600/tc.xyz" "w"))
(prompt "...        Select Your Point Please      ...")
(princ "                              Working ... Please Wait!")
(setq ent1 (ssget '((0 . "point"))))
(setq num (sslength ent1))
(setq cnt 0)
(repeat num
(setq s1 (ssname ent1 cnt))
(setq s2 (entget s1))
(setq pnt (cdr (assoc 10 s2)))
(setq x (car pnt))
(setq y (cadr pnt))
(setq inx (fix x))
(setq iny (fix y))
(setq x (rtos x 2 3))
(setq y (rtos y 2 3))
(setq sinx (rtos inx 2 0))
(setq siny (rtos iny 2 0))
(setq lsx (strlen sinx))
(setq lsy (strlen siny)) 
(if (= lsx 6) 
(progn
(setq sinx (substr sinx 2 5))
(setq x (substr x 2 9))
(setq lsx 5)
)
)
(if (= lsy 6)
(progn
(setq siny (substr siny 2 5))
(setq y (substr y 2 9))
(setq lsy 5)
)
)
(setq flx (+ lsx 3))
(setq fly (+ lsy 3))
(setq llsx (+ 2 lsx))
(setq llsy (+ 2 lsy))
(setq rx (substr x llsx 3))
(setq ry (substr y llsy 3))
(setq cnt (1+ cnt))
(setq scnt (rtos cnt 2 0))
(setq lcnt (strlen scnt))
(if (= lcnt 1) (setq fcnt (strcat "11000" scnt "+0000000" scnt)))
(if (= lcnt 2) (setq fcnt (strcat "1100" scnt "+000000" scnt)))
(if (= lcnt 3) (setq fcnt (strcat "110" scnt "+00000" scnt)))
(princ fcnt i)
(princ " " i)
(if (= lsx 4) (setq fx (strcat "81..00+0" sinx rx)))
(if (= lsy 4) (setq fy (strcat "82..00+0" siny ry)))
(if (= lsx 5) (setq fx (strcat "81..00+" sinx rx)))
(if (= lsy 5) (setq fy (strcat "82..00+" siny ry)))
(if (= lsx 3) (setq fx (strcat "81..00+00" sinx rx)))
(if (= lsy 3) (setq fy (strcat "82..00+00" siny ry)))
(if (= lsx 2) (setq fx (strcat "81..00+000" sinx rx)))
(if (= lsy 2) (setq fy (strcat "82..00+000" siny ry)))
(if (= lsx 1) (setq fx (strcat "81..00+00000" sinx rx)))
(if (= lsy 1) (setq fy (strcat "82..00+00000" siny ry)))
(setq fz "83..00+00000000")
(princ fx i)
(princ " " i)
(princ fy i)
(princ " " i)
(princ fz i)
(princ "\n" i)
(command "osnap" "none")
(setq p2 (polar pnt 2.4 (* 1.25 ha)))
(command "text" "m" p2 ha 0 scnt)
)
(close i)
)
)
(command "osnap" "nod")
(princ)
)

 

Thanks

Posted

Keep in mind that this forum and www.theswamp.org should not be abused as a free software service. To always ask for code and never make any attempt to learn to code yourself, is not a good idea in the long run.

 

Let's just say I am in a very, very good mood:

; Library function
(defun KGA_Data_FileRead (fnm / lst ptr str)
  (if (setq ptr (open fnm "r"))
    (progn
      (while (setq str (read-line ptr))
        (setq lst (cons str lst))
      )
      (close ptr)
      (reverse lst)
    )
  )
)

; Library function
(defun KGA_Data_FileWrite (fnm lst / ptr)
  (if (setq ptr (open fnm "w"))
    (progn
      (foreach str lst
        (write-line str ptr)
      )
      (close ptr)
      T
    )
  )
)

; Library function
(defun KGA_String_Join (strLst delim)
  (if strLst
    (apply
      'strcat
      (cons
        (car strLst)
        (mapcar '(lambda (a) (strcat delim a)) (cdr strLst))
      )
    )
    ""
  )
)

; Library function
(defun KGA_String_PadLeft (str ch len)
  (repeat (- len (strlen str))
    (setq str (strcat ch str))
  )
  str
)

; Library function
(defun KGA_String_Tokenize (str delim / ret sub)
  (setq delim (append (vl-string->list delim) '(nil)))
  (setq str (vl-string->list str))
  (repeat (1+ (length str))
    (if (vl-position (car str) delim)
      (progn
        (setq ret (cons (vl-list->string (reverse sub)) ret))
        (setq sub nil)
      )
      (setq sub (cons (car str) sub))
    )
    (setq str (cdr str))
  )
  (reverse ret)
)

; 20190417
; (CSV_To_GSI_Read "C:\\Downloads\\test.csv")
(defun CSV_To_GSI_Read (fnm)
  (mapcar
    '(lambda (str / lst)
      (setq lst (KGA_String_Tokenize str ","))
      (cons (car lst) (mapcar 'read (cdr lst)))
    )
    (KGA_Data_FileRead fnm)
  )
)

; 20190417
; (CSV_To_GSI_Sort (CSV_To_GSI_Read "C:\\Downloads\\test.csv"))
(defun CSV_To_GSI_Sort (lst) ; Lst is output from CSV_To_GSI_Read.
  (vl-sort
    lst
    '(lambda (a b) (< (car a) (car b)))
  )
)

; 20190417
; *110122+00000000000000S9
;     idx            label
; (CSV_To_GSI_FormatPointId 122 "S9")
(defun CSV_To_GSI_FormatPointId (idx lab)
  (strcat
    "*11"
    (KGA_String_PadLeft (itoa idx) "0" 4)
    "+"
    (KGA_String_PadLeft lab "0" 16)
  )
)

; 20190417
; 81..10+0000000304279082
; (CSV_To_GSI_FormatCoord "81" 304279.082)
(defun CSV_To_GSI_FormatCoord (axisPre coord) ; AxisPre is "81", "82" or "83".
  (strcat
    axisPre
    "..10+"
    (KGA_String_PadLeft (rtos (* 1000 coord) 2 0) "0" 16)
  )
)

; 20190417
; (CSV_To_GSI_Convert (CSV_To_GSI_Sort (CSV_To_GSI_Read "C:\\Downloads\\test.csv")))
(defun CSV_To_GSI_Convert (lst / i) ; Lst is (sorted) output from CSV_To_GSI_Read.
  (setq i 0)
  (mapcar
    '(lambda (sub)
      (strcat
        (CSV_To_GSI_FormatPointId (setq i (1+ i)) (car sub))
        " "
        (CSV_To_GSI_FormatCoord "81" (cadr sub))
        " "
        (CSV_To_GSI_FormatCoord "82" (caddr sub))
        " "
        (CSV_To_GSI_FormatCoord "83" (cadddr sub))
        " "
      )
    )
    lst
  )
)

; 20190417
(defun C:CSV_To_GSI ( / lst src trg)
  (if
    (and
      (setq src (getfiled "CSV file" (getvar 'dwgprefix) "csv" 0))
      (setq lst (CSV_To_GSI_Read src))
      (setq trg (getfiled "GSI file" (strcat (vl-filename-directory src) "\\") "gsi" 1))
    )
    (KGA_Data_FileWrite
      trg
      (CSV_To_GSI_Convert (CSV_To_GSI_Sort lst))
    )
  )
  (princ)
)

 

  • Thanks 1
  • 1 year later...
Posted

Hi  Roy_043  
Is it possible to modify the code?
Change of reading from an external file

TO
We can choose points directly from Drawing


Then it gives the same result

 

(if (setq s (ssget '((0 . "POINT")))
	     i -1)  ;;("1" 512127.0 2.40303e+006 1.4801 P)
       (repeat (sslength s)
	 
	 (setq i (1+ i))
	     (setq   XYZ (cdr (assoc 10 (entget (ssname s I)))))
	 (entmakex (list (cons 0 "TEXT")
                  (cons 10  XYZ)
                  (cons 40 0.1)
		 (cons 8 "00-text")
                  (cons 1  (rtos (1+ i) 2 0)))

              );_ entmake

	 (entmakex (list (cons 0 "TEXT")
                  (cons 10  XYZ)
                  (cons 40 0.1)
		 (cons 8 "00-text")
                  (cons 1  "P"))

              );_ entmake
	 (setq sL (APPEND (LIST (strcat(rtos (1+ i) 2 0)","(rtos (CAR XYZ) 2 0)","(rtos (CADR XYZ) 2 0)","(rtos (CADDR XYZ) 2 0)  ",P")) sL))    
       
   )
    )

 

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