วันพฤหัสบดีที่ 8 กรกฎาคม พ.ศ. 2564

Add Dot decimal point and comma in Text

;|

      Add Dot decimal point and comma in Text

      Ex. Km.1+000000 to Km.1+000.000

      Ex. 1000 to 1000.000

      Ex. 1000000.00 to 1,000,000.00

      Create and Design by Songkhran Jongkul july 2021

|;

(defun c:addc ( / ss)

(setq old_cmdecho  (getvar "cmdecho"))

(setvar "cmdecho" 0)

(initget "1 2 3")

(setq opt (getkword "\nSelect Options :[ 1 Add Decimal Point .000 / 2 Add Number Decimal .123 / 3 Add Comma to Number ] : <1> "))

(if (= opt "")(setq opt "1"))

;;----------------------------------

(if (= opt "2")

      (progn

            (or ndec (setq ndec ".123"))

            (setq dectemp (getstring (strcat "\n Enter Decimal : <" ndec ">: " )))

            (if (= dectemp "")(setq dectemp ndec)

                  (setq ndec dectemp)

            )

      )

;;----------------------------------

      (progn

            (if (null dec)(setq dec 3))

            (if (setq tmp (getint (strcat "\nEnter Number of Decimal: <" (rtos dec 2 0) ">: ")))

                  (setq dec tmp)

            )

      )

)

 

(setq ss(ssget '((0 . "TEXT,MTEXT"))))

(setq cntr 0

        str null

)

(while (< cntr (sslength ss))

      (setq en(ssname ss cntr))

      (setq enlist(entget en))

      (setq stxt(cdr(assoc 1 enlist)))   

      (cond

            ((= opt "1")

                  (progn

                        (setq num (strlen stxt)

                                cnt (- num dec)

                        )

                        (setq str (strcat (substr stxt 1 cnt) "." (substr stxt (1+ cnt))))

                  )

            )

            ((= opt "2")(setq str (strcat stxt ndec)))

            ((= opt "3")(setq str (rtoc (atof stxt) dec)))

      )

      (setq enlist(subst (cons 1 str)(assoc 1 enlist) enlist))

      (entmod enlist)

      (setq cntr(1+ cntr ))

(princ)

);while

(setvar "cmdecho" old_cmdecho)

(princ)

)

 

(prompt "\nEnter ADDC to start. ")

 

(defun rtoc ( n p / d i l x );; n = any number p = precision

      (setq d (getvar 'dimzin))

      (setvar 'dimzin 0)

      (setq l (vl-string->list (rtos n 2 p))

              x (cond ((cdr (member 46 (reverse l)))) ((reverse l)))

              i 0

      )

      (setvar 'dimzin d)

      (vl-list->string

            (append

                  (reverse

                        (apply 'append

                              (mapcar

                                    '(lambda ( a b )

                                          (if (and (zerop (rem (setq i (1+ i)) 3)) b)

                                                (list a 44)

                                                (list a)

                                          )

                                    )

                                    x (append (cdr x) '(nil))

                              )

                        )

                  )

                  (member 46 l)

            )

      )

);end


ไม่มีความคิดเห็น:

แสดงความคิดเห็น