Please, help me edit lisp Import ID X Y Z Code to Autocad

Please, help me edit lisp Import ID X Y Z Code to Autocad

minhphuong_humg
Enthusiast Enthusiast
4,309 Views
7 Replies
Message 1 of 8

Please, help me edit lisp Import ID X Y Z Code to Autocad

minhphuong_humg
Enthusiast
Enthusiast

Hi Everybody.
Please help me edit lisp Import ID X Y Z Code to Autocad (file attach).
This lisp import ID, X, Y, Z, CODE (not unicode).
Help me, edit file lisp to import Code with text Unicode. 
Example data:
ID [space] X [space] Y [space] Z [space][space] CODE (Unicode)

Thank you very much.
Link file attach:
https://www.mediafire.com/folder/b9c7e6b2e2472/Importcad

0 Likes
Accepted solutions (1)
4,310 Views
7 Replies
Replies (7)
Message 2 of 8

john.uhden
Mentor
Mentor

I'm sorry, but I don't want to install some "Quick Converter" thing.

Can't you just post the files?

John F. Uhden

0 Likes
Message 3 of 8

minhphuong_humg
Enthusiast
Enthusiast

Dear, John uhden.

please view file attach. Pleaase help me.  Thanks.

 

0 Likes
Message 4 of 8

john.uhden
Mentor
Mentor

This is what IMPO.TXT looks like when opened with Textpad, which did some conversion to system default characters...

 

1 459942.8601 2374653.465 1 B?n Nghiêu
2 465347.3047 2375267.236 2 Ph??ng N? Lào
3 465668.0444 2374305.462 3 B?n Chi?ng Sáo
4 465300.1694 2374339.447 4 Làng Bình Lãng
5 464730.8869 2377249.722 5 Chiêng S?o

 

The description field looks like maybe Chinese to me.  But maybe that's okay.

 

Reading it from lisp line-by-line into a list looks like this...

 

("ÿþ1\000\t\0004\0005\0009\0009\0004\0002\000.\0008\0006\0000\0001\000\t\0002\00
03\0007\0004\0006\0005\0003\000.\0004\0006\0005\000\t\0001\000\t\000\t\000B\000£
\036n\000 \000N\000g\000h\000i\000ê\000u\000" "\000"
"\0002\000\t\0004\0006\0005\0003\0004\0007\000.\0003\0000\0004\0007\000\t\0002\0
003\0007\0005\0002\0006\0007\000.\0002\0003\0006\000\t\0002\000\t\000\t\000P\000
h\000°\001Ý\036n\000g\000 \000N\000¡\036 \000L\000à\000o\000" "\000"
"\0003\000\t\0004\0006\0005\0006\0006\0008\000.\0000\0004\0004\0004\000\t\0002\0
003\0007\0004\0003\0000\0005\000.\0004\0006\0002\000\t\0003\000\t\000\t\000B\000
£\036n\000 \000C\000h\000i\000Á\036n\000g\000 \000S\000á\000o\000" "\000"
"\0004\000\t\0004\0006\0005\0003\0000\0000\000.\0001\0006\0009\0004\000\t\0002\0
003\0007\0004\0003\0003\0009\000.\0004\0004\0007\000\t\0004\000\t\000\t\000L\000
à\000n\000g\000 \000B\000ì\000n\000h\000 \000L\000ã\000n\000g\000" "\000"
"\0005\000\t\0004\0006\0004\0007\0003\0000\000.\0008\0008\0006\0009\000\t\0002\0
003\0007\0007\0002\0004\0009\000.\0007\0002\0002\000\t\0005\000\t\000\t\000C\000
h\000i\000ê\000n\000g\000 \000S\000¡\036o\000")

John F. Uhden

0 Likes
Message 5 of 8

minhphuong_humg
Enthusiast
Enthusiast

Dear, John.uhden.

File attach, you choose font Tahoma or Time new roman (unicode).

file impo:

 

1 459942.8601 2374653.465 1 Bản Nghiêu
2 465347.3047 2375267.236 2 Phường Nạ Lào
3 465668.0444 2374305.462 3 Bản Chiềng Sáo
4 465300.1694 2374339.447 4 Làng Bình Lãng
5 464730.8869 2377249.722 5 Chiêng Sạo

 

Lisp:

 

(defun c:RFT(/ code data f h line pt pxy spc txt stt ten);Read File Txt
;| By : Gia Bach, gia_bach @ www.CadViet.com |;
(vl-load-com)
(defun Split(str / i kitu line lst txtPhanbiet)
(setq i 1 txtPhanbiet (strcat(chr 9)(chr 32)(chr 44)))
(while (< i (strlen str))
(setq kitu (substr str i 1))
(if (vl-string-search kitu txtPhanbiet)
(progn
(if (null Lst)
(setq Lst (list (substr Str 1 (- i 1))))
(setq Lst (append Lst (list (read (substr Str 1 (- i 1)))))))
(setq Str (substr Str (+ i 1)) i 1))
(setq i (1+ i)) ) )
(setq Lst (append Lst (list Str))) )
(or *h* (setq *h* 2 ))
(initget 6)
(setq h (getdist (strcat "\nNhap chieu cao Text <" (rtos *h*) "> :")) )
(if h (setq *h* h) (setq h *h*))
(if (setq ten (getfiled "Chon File txt" (getvar "dwgprefix") "txt" 8))
(progn
(or (tblsearch "layer" "Point") (command "-layer" "n" "Point" "") )
(or (tblsearch "layer" "Sothutu") (command "-layer" "n" "Sothutu" "c" 3 "Sothutu" "") )
(or (tblsearch "layer" "Caodo") (command "-layer" "n" "Caodo" "c" 4 "Caodo" "") )
(or (tblsearch "layer" "Code") (command "-layer" "n" "Code" "c" 2 "Code" "") )
(setq spc (vla-get-ModelSpace (vla-get-ActiveDocument(vlax-get-Acad-Object))))
(setq f (open (findfile ten) "r"))
(while (setq Line (read-line f))
(if (wcmatch Line (strcat "*"(chr 9)"*,*"(chr 32)"*,*`"(chr 44)"*"))
(progn
(setq data (split Line) code (last data))
(if (and
(= (vl-list-length data)5)
(setq pt (vl-remove code (cdr data)))
(not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-3d-point pt))) )
(progn
(setq stt (car data) pXY (list (car pt)(cadr pt)))
(vla-put-Layer (vla-addpoint spc (vlax-3d-point pXY)) "Point")
(vla-put-Layer (setq txt (vla-addtext spc stt (vlax-3d-point (list 0 0 0)) h)) "Sothutu")
(vla-put-Alignment txt 8)
(vla-put-TextAlignmentPoint txt (vlax-3d-point pXY))
(vla-put-Layer (setq txt (vla-addtext spc code (vlax-3d-point (list 0 0 0)) h)) "Code")
(vla-put-Alignment txt 6)
(vla-put-TextAlignmentPoint txt (vlax-3d-point (polar pXY 0 (* 0.2 h))))
(vla-put-Layer (vla-addtext spc (caddr pt) (vlax-3d-point pXY) h) "Caodo")

0 Likes
Message 6 of 8

Ajilal.Vijayan
Advisor
Advisor

Hello,

You have to save the text file as ANSI encoding and then try with the below code.

Notepad->File menu->Save as-> and then select Encoding: ANSI as shown below.

Capture.JPG

 

(defun c:RFT(/ code data f h line pt pxy spc txt stt ten);Read File Txt
 ;|  By : Gia Bach, gia_bach @  www.CadViet.com             |;    
 (vl-load-com)


;; String to List  -  Lee Mac
;; Separates a string using a given delimiter
;; str - [str] String to process
;; del - [str] Delimiter by which to separate the string
;; Returns: [lst] List of strings
 
(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)
    )
)

;;To convert the list of string value to list of real value
(defun CreatePointList(lst / pnt) 
	(setq pnt (list 
		(distof (car lst))
		(distof (cadr lst))
		(distof (caddr lst))
		) )
)
 
 (or *h* (setq *h* 2 ))
 (initget 6)
 (setq h (getdist (strcat "\nNhap chieu cao Text <" (rtos *h*) "> :")) )
 (if h (setq *h* h) (setq h *h*))
 (if (setq ten (getfiled "Chon File txt" (getvar "dwgprefix") "txt" 8))
   (progn
     (or (tblsearch "layer" "Point") (command "-layer" "n" "Point" "") )
     (or (tblsearch "layer" "Sothutu") (command "-layer" "n" "Sothutu" "c" 3 "Sothutu" "") )
     (or (tblsearch "layer" "Caodo") (command "-layer" "n" "Caodo" "c" 4 "Caodo" "") )
     (or (tblsearch "layer" "Code") (command "-layer" "n" "Code" "c" 2 "Code" "") )
     (setq spc (vla-get-ModelSpace (vla-get-ActiveDocument(vlax-get-Acad-Object))))
     (setq f (open (findfile ten) "r"))
     (while (setq Line (read-line f))
(if (wcmatch Line (strcat "*"(chr 9)"*,*"(chr 32)"*,*`"(chr 44)"*"))
  (progn
    (setq data (LM:str->lst Line (chr 9)) code (last data))
    (if (and
	  (= (vl-list-length data)5)
	  (setq pt (CreatePointList (vl-remove code (cdr data))))
	  (not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-3d-point pt))))
      (progn
		(vla-put-Layer (vla-addpoint spc (vlax-3d-point pt)) "Point")
		(vla-put-Layer (setq txt (vla-addtext spc (car data) (vlax-3d-point (list 0 0 0)) h)) "Sothutu")
		(vla-put-Alignment txt 8)
		(vla-put-TextAlignmentPoint txt (vlax-3d-point pt))
		(vla-put-Layer (setq txt (vla-addtext spc  code (vlax-3d-point (list 0 0 0)) h)) "Code")
		(vla-put-Alignment txt 6)
		(vla-put-TextAlignmentPoint txt (vlax-3d-point (polar pt 0 (* 0.2 h))))
		(vla-put-Layer (vla-addtext spc (caddr pt) (vlax-3d-point pt) h) "Caodo")
	))))) ) )
 (princ)
 )

 

0 Likes
Message 7 of 8

minhphuong_humg
Enthusiast
Enthusiast

Dear Ajilal,

You do not understand my idea.
I want to spray onto cad coordinates and note is Unicode code (accented letter).
If I choose ANSI then the text file will lose the original formatting that I desire.

0 Likes
Message 8 of 8

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

In that case I have updated the code by including the code from Lee Mac [http://www.theswamp.org/index.php?topic=39814

Try the below code.

 

 

(defun c:RFT(/ code data f h line pt pxy spc txt stt ten);Read File Txt
 ;|  By : Gia Bach, gia_bach @  www.CadViet.com             |;    
 (vl-load-com)
 
 (or *h* (setq *h* 2 ))
 (initget 6)
 (setq h (getdist (strcat "\nNhap chieu cao Text <" (rtos *h*) "> :")) )
 (if h (setq *h* h) (setq h *h*))
 (if (setq ten (getfiled "Chon File txt" (getvar "dwgprefix") "txt" 8))
   (progn
     (or (tblsearch "layer" "Point") (command "-layer" "n" "Point" "") )
     (or (tblsearch "layer" "Sothutu") (command "-layer" "n" "Sothutu" "c" 3 "Sothutu" "") )
     (or (tblsearch "layer" "Caodo") (command "-layer" "n" "Caodo" "c" 4 "Caodo" "") )
     (or (tblsearch "layer" "Code") (command "-layer" "n" "Code" "c" 2 "Code" "") )
     (setq spc (vla-get-ModelSpace (vla-get-ActiveDocument(vlax-get-Acad-Object))))
     (setq f (open (findfile ten) "r"))
	 
    (foreach Line (ReadUnicode ten) 
		(if (wcmatch Line (strcat "*"(chr 9)"*,*"(chr 32)"*,*`"(chr 44)"*"))
		  (progn
			(setq data (LM:str->lst Line (chr 9)) code (last data))
			(if (and
			  (= (vl-list-length data)6)
			  (setq pt (CreatePointList (vl-remove code (cdr data))))
			  (not(vl-catch-all-error-p (vl-catch-all-apply 'vlax-3d-point pt))))
			  (progn
				(vla-put-Layer (vla-addpoint spc (vlax-3d-point pt)) "Point")
				(vla-put-Layer (setq txt (vla-addtext spc (car data) (vlax-3d-point (list 0 0 0)) h)) "Sothutu")
				(vla-put-Alignment txt 8)
				(vla-put-TextAlignmentPoint txt (vlax-3d-point pt))
				(vla-put-Layer (setq txt (vla-addtext spc  code (vlax-3d-point (list 0 0 0)) h)) "Code")
				(vla-put-Alignment txt 6)
				(vla-put-TextAlignmentPoint txt (vlax-3d-point (polar pt 0 (* 0.2 h))))
				(vla-put-Layer (vla-addtext spc (caddr pt) (vlax-3d-point pt) h) "Caodo")
			)))
			);if
	);for 
	);progn 
	);if
 (princ)
 );defun
 
;; String to List  -  Lee Mac
;; Separates a string using a given delimiter
;; str - [str] String to process
;; del - [str] Delimiter by which to separate the string
;; Returns: [lst] List of strings
 
(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)
    )
)

;;-
;;To convert the list of string value to list of real value
(defun CreatePointList(lst / pnt) 
	(setq pnt (list 
		(distof (car lst))
		(distof (cadr lst))
		(distof (caddr lst))
		) )
)
 
 
 ;;http://www.theswamp.org/index.php?topic=39814
 ;;------------------------------------------------------
 (defun ReadUnicode ( file / _padzeros lst out n )

    (defun _padzeros ( s )
        (if (< (strlen s) 4) (_padzeros (strcat "0" s)) s)
    )
    (if (setq lst (LM:ReadBinaryStream file))
        (progn
            (cond
                (   (and (= 255 (car lst)) (= 254 (cadr lst))) ;; UTF-16 Little Endian
                    (setq lst (cddr lst))
                    (while (cadr lst)
                        (if (< (setq n (+ (car lst) (* 256 (cadr lst)))) 128)
                            (setq out (cons (chr n) out))
                            (setq out (cons (strcat "\\U+" (_padzeros (LM:Dec->Base n 16))) out))
                        )       
                        (setq lst (cddr lst))
                    )
                    (setq out (reverse out))
                )
                (   (and (= 254 (car lst)) (= 255 (cadr lst))) ;; UTF-16 Big Endian
                    (setq lst (cddr lst))
                    (while (cadr lst)
                        (if (< (setq n (+ (cadr lst) (* 256 (car lst)))) 128)
                            (setq out (cons (chr n) out))
                            (setq out (cons (strcat "\\U+" (_padzeros (LM:Dec->Base n 16))) out))
                        )
                        (setq lst (cddr lst))
                    )
                    (setq out (reverse out))
                )
                (   (setq out (mapcar 'chr lst))   ) ;; Assume ASCII
            )
           
            (LM:str->lst (apply 'strcat out) "\r\n")
        )
    )
)

(defun LM:Dec->Base ( n b )
    (if (< n b)
        (chr (+ n (if (< n 10) 48 55)))
        (strcat (LM:Dec->Base (/ n b) b) (LM:Dec->Base (rem n b) b))
    )
)


(defun LM:ReadBinaryStream ( file / adostream result )
    (if
        (and
            (setq file (findfile file))
            (setq adostream (vlax-create-object "ADODB.Stream"))
        )
        (progn
            (setq result
                (vl-catch-all-apply
                    (function
                        (lambda nil
                            (vlax-put-property  adostream 'type 1)
                            (vlax-invoke-method adostream 'open nil nil nil nil nil)
                            (vlax-invoke-method adostream 'loadfromfile file)
                            (vlax-put-property  adostream 'position 0)
                            (setq result (vlax-invoke-method adostream 'read -1))
                            (vlax-invoke-method adostream 'close)
                            result
                        )
                    )
                )
            )
            (vlax-release-object adostream)
            (if (not (vl-catch-all-error-p result))
                (vlax-safearray->list (vlax-variant-value result))
            )
        )
    )
)

 

0 Likes