Author Topic: how can i read dim text to convert feet and inches, into just inches  (Read 2601 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
im looking to convert feet and inches below 4 feet into just inches.
however im having difficult getting the dim value to modify.

can anyone point me in the right direction on how to get the value of a dim so i can change it over or if anyone has anything like this i can build off

any help is appreciated

andrew_nao

  • Guest
Re: how can i read dim text to convert feet and inches, into just inches
« Reply #1 on: October 11, 2011, 09:43:14 AM »
ok i figured out how to read it
now for some reason i cant convert it... omg i need some coffee  :ugly:

Code: [Select]
(defun C:XDIM ( / ss ent elist cmdecho en olddim)
(defun *error* (msg)
    (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
      (princ (strcat "\nError: " msg)) )
    (and cmdecho (setvar 'cmdecho cmdecho))
    (princ)
  )
  (setq cmdecho (getvar 'cmdecho))
  (setvar 'cmdecho 1)
  (setvar 'dimatfit 2)
  (setq ds (getvar 'dimscale))
 
(Command "dim" "hor" PAUSE "" PAUSE "exit")
(setq ss (ssget "L"))
(if ss
 (progn
   (setq ent (ssname ss 0))
   (setq elist (entget ent))
   (if (= (cdr (assoc 0 elist)) "MTEXT")
     (command "explode" ent)
   ); if
    (setq en (ssget "L"'((0 . "TEXT"))))
     (setq ent (ssname en 0))
     (setq EN (entget ent))
     (setq olddim (cdr (assoc 1 EN)))
;; do math here
(entmod (SUBST (CONS 1 olddim) (ASSOC 1 en) en))
)
 ); progn
); if
  (setvar 'cmdecho cmdecho)
(princ)
)

hermanm

  • Guest
Re: how can i read dim text to convert feet and inches, into just inches
« Reply #2 on: October 11, 2011, 10:27:31 AM »
No need to do any math for dimension text.
Set primary units to "Fractional"
Add " as suffix if you want inch marks.

If you wish to automatically convert existing dimensions, get the measured value & compare to 4' (48")
You can either override the primary units, or create a different style & change to that style.

This will be easier using Active X.

andrew_nao

  • Guest
Re: how can i read dim text to convert feet and inches, into just inches
« Reply #3 on: October 11, 2011, 11:05:10 AM »
thanks for the reply.

I dont want to eliminate the feet and inches altogether, i only want to use inches up to 4 feet, anything greater than 4 feet i want to keep in feet and inches
anything smaller than 4 feet i want to be all inches


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: how can i read dim text to convert feet and inches, into just inches
« Reply #4 on: October 11, 2011, 12:52:22 PM »
Here is an oldie that you pick um.
Code: [Select]
;;;  Dim2Inches.lsp
;;;
;;; FUNCTION
;;; change Dimension units to Fractions and add " to override
;;;
;;;
;;; ARGUMENTS
;;; none
;;;
;;; USAGE
;;; d2i
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2004-2008 Charles Alan Butler
;;;  CAB at TheSwamp
;;;
;;; VERSION  1.0 Oct. 23, 2004
;;; YOU MAY USE THIS CODE ONLY FOR *NON-COMMERCIAL* PURPOSES AND ONLY
;;;  IF YOU RETAIN THIS HEADER COMPLETE AND UNALTERED
;;;
;;; you must contact me if you want to use it commercially
;;;
;;; REVISED By VINCENT POON
;;; VERSION  1.1 Mar. 17, 2005
;;;
;;; REVISED By CAB
;;; VERSION  1.2 Mar. 23, 2005
;;;  Changed to dimension to FRACTIONS & adds " to the suffix if empty
;;;   else adds " to the override if empty else does nothing
;;;
(defun c:d2i (/ ent obj )
  (vl-load-com)
  (graphscr)
  (while (setq ent (entsel "\n>>-->  Select Dimension to convert to inches."))
    (if (= (cdr (assoc 0 (setq elst (entget (car ent))))) "DIMENSION")
      (progn
        (setq ent (car ent)
              obj (vlax-ename->vla-object ent))
        (if (and (vlax-property-available-p obj 'primaryunitsprecision)
                 (vlax-property-available-p obj 'textoverride)
            )
          (progn
            (vla-put-UnitsFormat obj 5) ; make Fractional
            ;; changed from vla-get-textoverride to vla-get-TextSuffix
            (cond
              ((member (vla-get-TextSuffix obj) '("" "<>"))
                (vla-put-TextSuffix obj "\"")
              ) ; Suffix
              ((member (vla-get-textoverride obj) '("" "<>"))
                (vla-put-textoverride obj "<>\"")
               (prompt "\n*-* Text Suffix already in use, created override. *-*")
              )
              (T
                (prompt "\n*--* Text Suffix & Override in use, Change to Fractions.")
              )
            ) ; end cond stmt
          ) ; progn
          (prompt "\n**** Can not edit this Dimension Object, Canceled...")
        ) ; endif
        (vlax-release-object obj)
      ) ; progn
      (prompt "\n<<<  Not a dimension  >>>")
    ) ; endif
  )
  (princ)
)
;(prompt "\nDim to Inches loaded, Enter d2i to run.")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

andrew_nao

  • Guest
Re: how can i read dim text to convert feet and inches, into just inches
« Reply #5 on: October 11, 2011, 02:34:03 PM »
thanks for the reply CAB,
here is what i came up with, it might not be pretty, but it works

maybe someone else will find this useful also

Code: [Select]
  (DEFUN FTDEC (ASTR / BUF RES C R1)
(SETQ BUF "" RES 0.0)
(WHILE (> (STRLEN ASTR) 0)
(SETQ C (SUBSTR ASTR 1 1) ASTR (SUBSTR ASTR 2))
(COND
((= C "'")
(SETQ RES (* (ATOF BUF) 12.0) BUF "" ASTR (SUBSTR ASTR 2))
)
((= C "/")
(SETQ R1 (ATOF BUF) BUF "")
)
((= C " ")
(SETQ RES (+ RES (ATOF BUF)) BUF "")
)
((/= C (CHR 34))
(SETQ BUF (STRCAT BUF C))
)
)
)
(IF R1
(+ RES (/ R1 (ATOF BUF)))
(+ RES (ATOF BUF))
)
);end while

(defun C:NEWDIM ( / ss ent elist cmdecho en olddim chknum)
 
  (defun *error* (msg)
    (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
      (princ (strcat "\nError: " msg)) )
    (and cmdecho (setvar 'cmdecho cmdecho))
    (princ)
  )
  (setq cmdecho (getvar 'cmdecho))
  (setvar 'cmdecho 1)
 
(Command "dimlinear" PAUSE PAUSE pause "")

(setq ss (ssget "L"))
(if ss
 (progn
   (setq ent (ssname ss 0))
   (setq elist (entget ent))
   (if (= (cdr (assoc 0 elist)) "MTEXT")
     (command "explode" ent)
   ); if
    (setq en (ssget "L"'((0 . "TEXT"))))
     (setq ent (ssname en 0))
     (setq EN (entget ent))
     (setq olddim (cdr (assoc 1 EN)))
(setq chknum (fix (ftdec olddim)))
(if (< chknum 48)
  (progn
    (setq olddim (rtos (ftdec olddim) 5))
(setq olddim (strcat olddim "\""))
(entmod (SUBST (CONS 1 olddim) (ASSOC 1 en) en))
)
)

 ); progn
); if
(command "Change" "L" "" "P" "LA" "2" "")
(COMMAND "_.DDEDIT" "L" "")
  (setvar 'cmdecho cmdecho)
(princ)
); function
« Last Edit: October 11, 2011, 02:47:00 PM by andrew_nao »

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: how can i read dim text to convert feet and inches, into just inches
« Reply #6 on: October 11, 2011, 06:00:23 PM »
Cool, I was going to compile one, but I think between you and CAB, you have it. Just a heads up, CAB's will be much faster since it uses Visual Lisp, for some reason it just works much faster.