Jump to content

Convert Text Strings from Millimeter to meter


Ajmal

Recommended Posts

(defun c:Test (/ *error* dz ss f)
 ;; ==================================================    ;;
 ;;    Author : Tharwat Al Shoufi .Date: 22.Nov.2014    ;;
 ;;    Converts conversely Text Strings from        ;;
 ;;    Millimeter to Inch                 ;;
 ;; ==================================================    ;;
 (defun *error* (msg)
   (if dz
     (setvar 'DIMZIN dz)
   )
   (if (not (wcmatch msg "*CANCEL*,*EXIT*,*BREAK*"))
     (princ (strcat "\n ** Error : " msg " **"))
   )
 )
 (princ
   "\n Select Texts that either start with numbers or X character :"
 )
 (if (and (setq ss (ssget "_:L"
                          '((0 . "TEXT,MTEXT")
                            (1 . "1*,2*,3*,4*,5*,6*,7*,8*,9*,x*,X*")
                           )
                   )
          )
          (progn
            (initget 6 "Inch Millimeter")
            (setq *formula*
                   (cond
                     ((getkword
                        (strcat
                          "\n Specify convertion formula [inch/ Millimeter] < "
                          (if *formula*
                            *formula*
                            (setq *formula* "Inch")
                          )
                          " > :"
                        )
                      )
                     )
                     (*formula*)
                   )
            )

          )
          (if (eq *formula* "Inch")
            (setq f (list (/ 1.0 25.4) 4 0))
            (setq f (list 25.4 2 2))
          )
     )
   (progn
     (setq dz (getvar 'DIMZIN))
     (setvar 'DIMZIN 0)
     ((lambda (x / sn e s a)
        (while (setq sn (ssname ss (setq x (1+ x))))
          (entmod
            (subst
              (cons
                1
                (if
                  (wcmatch
                    (setq
                      a (strcase
                          (substr
                            (setq
                              s (cdr (assoc 1 (setq e (entget sn))))
                            )
                            1
                            1
                          )
                        )
                    )
                    "X*"
                  )
                   (if (/= (atof (substr s 2)) 0.)
                     (strcat a
                             (rtos (* (atof (substr s 2)) (car f))
                                   (cadr f)
                                   (caddr f)
                             )
                     )
                     s
                   )
                   (rtos (* (atof s) (car f)) (cadr f) (caddr f))
                )
              )
              (assoc 1 e)
              e
            )
          )
        )
      )
       -1
     )
     (setvar 'DIMZIN dz)
   )
 )
 (princ)
)

@Tharwat    can you edit this one "mm to m"

Link to comment
Share on other sites

Are they only number text so 100 times into m would not work ?

 

The wall length is 12234 and made of brick

 

Test on line above.

Edited by BIGAL
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...