วันอังคารที่ 28 เมษายน พ.ศ. 2563

SSGET POINT Coordinate X,Y,Z to Excel .CVS File.

SSGET POINT Coordinate X,Y,Z to Excel .CVS File.
การเลือกตำแหน่ง (point) โดยการเลือกครอบตำแหน่งที่ต้องการทั้งหมด แล้วทำการส่งค่า (Coordinate X,Y,Z) ไปยัง Excel โดยการบันทึกเป็นไฟล์ .CVS แล้วค่อยเลือกบันทึกเป็น .xlsx เป็นไฟล์ Excel เพื่อนำค่าไปใช้ต่อไป
(defun c:P2CVS2 (/)
(setq old_cmdecho  (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq txth (getvar "TEXTSIZE"))
(if (setq fn (getfiled "Save to CSV file." "" "csv" 1))
    (progn
              (setq f (open fn "w")) ;Open the file for writing
              (write-line (strcat "Num.,X,Y,Z") f) ;Write header line to file      
              (if (setq ss (ssget '((0 . "POINT"))))
                     (progn
                           (setq is 1)
                            (repeat (setq i (sslength ss))
                                  (setq ent  (entget (ssname ss (setq i (1- i))))
                                           pt   (cdr (assoc 10 ent))
                                  )
                                  (command "_point" pt)
                                  (command "_text" "mc" pt txth "0" (rtos is 2 0))
                                  (write-line
                                         (strcat (rtos is 2 0)
                                                ","
                                                (rtos(car pt)2 3)
                                                ","
                                                (rtos(cadr pt)2 3)
                                                ","
                                                (rtos(caddr pt)2 3)
                                         );strcat
                                         f
                                  );write-line
                                  (setq is (1+ is))    
                           );repeat
                     );progn
              );if ssget
              (close f) ;Close the file
              (princ)
       );progn
       (princ "Stopped. Exit.");if don't save cvs file
);if
(setvar "cmdecho" old_cmdecho)
(princ)
);End

วันอาทิตย์ที่ 26 เมษายน พ.ศ. 2563

Find Text Replace with Blocks


;|     
       Find Text Replace with Blocks
       - Enter Text String
       - Enter Block Name
|;
(defun c:t2b( / ss)
(setq old_cmdecho  (getvar "cmdecho"))
(setvar "cmdecho" 0)
(vl-load-com)
       (or txt (setq txt "CL"))
       (setq txt (getstring t (strcat "\nFind Text: <" txt "> :")))
       (if (= txt "")(setq txt "CL"))
;-----------------------------------
       (or blk (setq blk "CL100"))
       (setq blk (getstring t (strcat "\nBlock Name: <" blk "> :")))
       (if (= blk "")(setq blk "CL100"))
;-----------------------------------
       (setq ss (ssget "X" (list(cons 0 "*TEXT")(cons 1 txt))))
       (if ss
              (progn
                     (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
                     (mapcar '(lambda (x) (vl-cmdf "-insert" blk (cdr (assoc 10 (entget x))) 1 1 (* (/ 180 pi)
                                                                                                (cdr (assoc 50 (entget x)))))
                                  (entdel x)) ss
                     )
              )
              (princ "\nNo text entities found.")
       )
(setvar "cmdecho" old_cmdecho)
(princ)
);end
(prompt "\nEnter T2B to start. Find Text Replace with Blocks. ")

Find Text and Replace


;|     
       Find Text and Replace
       - Enter Old Text String
       - Enter New Text String
|;
(defun C:TRC (/ told tnew tss tdata); = Text Replace for Complete text/mtext strings
(setq old_cmdecho  (getvar "cmdecho"))
(setvar "cmdecho" 0)
;-----------------------------------
       (or told (setq told "Test"))
       (setq told (getstring t (strcat "\nFind Text: <" told "> :")))
       (if (= told "")(setq told "Test"))
;-----------------------------------
       (or tnew (setq tnew "Replace"))
       (setq tnew (getstring t (strcat "\nText Replace: <" tnew "> :")))
       (if (= tnew "")(setq tnew "Replace"))
;-----------------------------------
       (setq tss (ssget "X" (list (cons 1 told))))
       (repeat (sslength tss)
              (setq tdata (entget (ssname tss 0))
                       tdata (subst (cons 1 tnew) (assoc 1 tdata) tdata)
              ); end setq
              (entmod tdata)
              (ssdel (ssname tss 0) tss)
       ); end repeat
(setvar "cmdecho" old_cmdecho)
(princ)      
); end defun
(prompt "\nEnter TRC to start. Find Text and Replace.")

Run String / Number or String&Number



;|
      Run String / Number or String&Number
      Select Options 1 String 2 Number 3 String&Number
|;
(defun c:RST ()
(setq old_cmdecho  (getvar "cmdecho"))
(setvar "cmdecho" 0)
      (setq txtH (getvar "TEXTSIZE"))
      (setq txtS (getvar "textstyle"))
(initget "1 2 3")
      (setq opt (getkword "\mSelect Options : \n [1  String / 2  Number / 3  String&Number ] <1> "))
      (if (= opt "")(setq opt "1"))
      (if (or(= opt "1")(= opt "3"))(setq sta (getstring "\nEnter String : ")))
      (if (or(= opt "2")(= opt "3"))(setq nma (getreal "\nEnter Number : ")))
(while(setq pt (getpoint "\nPick Point :"))
      (if (= opt "1")
            (progn
                  (command "_.text" "_s" txtS "_j" "ml" pt txtH 0 sta)      
                  (setq sta (ascii sta)
                          sta (1+ sta)
                          sta (chr sta)
                  )
            )
      )
      (if (= opt "2")
            (progn
                  (command "_.text" "_s" txtS "_j" "ml" pt txtH 0 (rtos nma 2 3))
                  (setq nma (1+ nma))
            )
      )
      (if (= opt "3")
            (progn
                  (setq txt (strcat sta (rtos nma 2 3)))
                  (command "_.text" "_s" txtS "_j" "ml" pt txtH 0 txt)
                  (setq nma (1+ nma))
            )
      )    
      (princ)
);while     
(setvar "cmdecho" old_cmdecho)
(princ)
);end
(prompt "\nEnter RST to start. ")

วันศุกร์ที่ 17 เมษายน พ.ศ. 2563

Point to Excel .cvs file.



Pick POINT Coordinate X,Y,Z to Excel .CVS File.
การเลือกตำแหน่ง (point) โดยการกดเลือกเอาตามตำแหน่งที่ต้องการ แล้วทำการส่งค่า (Coordinate X,Y,Z) ไปยัง Excel โดยการบันทึกเป็นไฟล์ .CVS แล้วค่อยเลือกบันทึกเป็น .xlsx เป็นไฟล์ Excel เพื่อนำค่าไปใช้ต่อไป
(defun c:P2CVS1 (/)
(setq old_cmdecho  (getvar "cmdecho"))
(setq old_osnap (getvar "osmode")) 
(setvar "cmdecho" 0) 
(setvar "osmode" 37)  ;; 1+4+32 1=endpoint 4=center 32=node      
(setq txth (getvar "TEXTSIZE"))
(if (setq fn (getfiled "Save to CSV file." "" "csv" 1))
    (progn
              (setq f (open fn "w")) ;Open the file for writing
              (write-line (strcat "Num.,X,Y,Z") f) ;Write header line to file      
              (setq i 1)
              (while (setq pt (getpoint "\nPick Point : <Enter to Exit.>"))
                     (command "_point" pt)
                     (command "_text" "mc" pt txth "0" (rtos i 2 0))
                     (write-line 
                           (strcat (rtos i 2 0)
                           ","
                           (rtos(car pt)2 3)
                           ","
                           (rtos(cadr pt)2 3)
                           ","
                           (rtos(caddr pt)2 3)
                           );strcat
                     f
                     );write-line
              (setq i (1+ i))
              )
              (close f) ;Close the file
              (princ)
       );progn
       (princ "Stopped. Exit.");if don't save cvs file
);if
(setvar "cmdecho" old_cmdecho)
(setvar "osmode" old_osnap)
(princ)
);End