any lisp for converting feet inches to approximate feet.

any lisp for converting feet inches to approximate feet.

Yuvaraju.Dhananjay
Enthusiast Enthusiast
2,194 Views
11 Replies
Message 1 of 12

any lisp for converting feet inches to approximate feet.

Yuvaraju.Dhananjay
Enthusiast
Enthusiast
Hi

I need lisp for converting the feet inches of text into feet text.please help me.

Example: 34'6''--> 35'(above 5'' inch )
34.5''-->34' ( equal 5'' inch)
34.3''-->34' ( below 5'' inch)

Thanks
Raj
0 Likes
Accepted solutions (1)
2,195 Views
11 Replies
Replies (11)
Message 2 of 12

_gile
Consultant
Consultant

Hi,

 

EDIT: works now with negative values

 

(defun roundToFoot (str / n)
  (if (setq n (distof str 3))
    (rtos (* 12.
             (fix
               ((if (minusp n)
                  -
                  +
                )
                 (/ n 12.)
                 0.5
               )
             )
          )
          3
    )
  )
)

(roundToFoot "34'6\"") => "35'"
(roundToFoot "34'5\"") => "34'"
(roundToFoot "34'3\"") => "34'"

 

(roundToFoot "-34'6\"") => "-35'"
(roundToFoot "-34'3\"") => "-34'"



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 12

Kent1Cooper
Consultant
Consultant

.... with the DIMZIN System Variable set to a value other than 1 or 3.

Kent Cooper, AIA
0 Likes
Message 4 of 12

Kent1Cooper
Consultant
Consultant

Here's another way, unaffected by the DIMZIN System Variable value:

(defun NFT ; = Nearest Foot Text
  (str / rne)
  (setq rne (distof str 3)); = real number equivalent
  (strcat
    (if (minusp rne) "-" "")
    (itoa (fix (+ (abs (/ rne 12)) 0.5)))
    "'"
  ); strcat
); defun

Command: (nft "34'-6 1/2\"")
"35'"

Command: (nft "34'-5 1/2\"")
"34'"

Command: (nft "-34'-5 1/2\"")
"-34'"

Command: (nft "-38'-9 1/2\"")
"-39'"

 

EDIT:  And given the "approximate" in the Subject line, consider changing this line for the foot mark:

    "'"

 

to this, to include a plus-or-minus symbol at the end if used in Text or Mtext content:

    "'%%p"

Kent Cooper, AIA
Message 5 of 12

_gile
Consultant
Consultant

Nice catch @Kent1Cooper.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 12

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

Kent,

 

this is really good. but it's not working in my drawing. Could you please go through the drawing which I have attached now. 

there is 2 type of text. buried and aerial text.

 

thanks 

 

raj

0 Likes
Message 7 of 12

Kent1Cooper
Consultant
Consultant

@Yuvaraju.Dhananjay wrote:

.... 

this is really good. but it's not working in my drawing. Could you please go through the drawing which I have attached now. 

....


The code is only for the conversion of the character content of a string.  [The same is true for @_gile's suggestion].  To apply that change to a Text [or Mtext or Attribute or Dimension with override...] object  of which such a string constitutes the contents, you need to wrap it in some more code, to pull out the contents string, modify it with the (nft) function, and impose the modified version back into the string content of the object.  This works for me on the Text objects in your drawing:

 

(vla-put-TextString (setq obj (vlax-ename->vla-object (car (entsel "\nSelect Text to round to nearest foot: ")))) (nft (vla-get-TextString obj)))

If you need to apply the same to other kinds of things, such as Mtext if it might contain any internal formatting, or any kind of text-containing object if the contents might include more than just the distance part, or an Attribute for which different code would be needed to pull its contents out, then more work is needed.

 

It could also be made to work on multiple  selected objects all at once, and even to handle the different possible object types each in their own way, if needed.

 

You may need to do:

 

(vl-load-com)

 

first.  It can also be done without that, using (subst)/(entmod) methods and entity data, if you prefer.

Kent Cooper, AIA
0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
....  It can also be done without that, using (subst)/(entmod) methods and entity data, if you prefer.

Like this, for instance:

(entmod
  (subst
    (cons 1 
      (nft
        (cdr (assoc 1 (setq edata (entget (car (entsel "\nSelect Text to round to nearest foot: "))))))
      ); nft
    ); cons
    (assoc 1 edata)
    edata
  ); subst
); entmod
Kent Cooper, AIA
Message 9 of 12

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

Thanks a lot kent. Can you add "defun" value to this code? So that I can easily recall the code whenever it needs.

0 Likes
Message 10 of 12

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

I have 1000 of these texts, Kent. Each time needs to upload this code and make only one text for modification. If you give any "defun" command that really works. 

0 Likes
Message 11 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

Using the first code approach, and for Text objects only, and without verifying that each has content that actually represents a distance, or disallowing Text on locked Layers:

(defun C:TNF ; = Text to Nearest Foot
  (/ nft ss n)
  (defun NFT ; = Nearest Foot Text
    (str / rne)
    (setq rne (distof str 3)); = real number equivalent
    (strcat
      (if (minusp rne) "-" "")
      (itoa (fix (+ (abs (/ rne 12)) 0.5)))
      "'" ;;;;; or "'%%P" instead, to add plus/minus symbol
    ); strcat
  ); defun -- NFT
  (prompt "\nTo round Text to Nearest Foot,")
  (if (setq ss (ssget '((0 . "TEXT"))))
    (repeat (setq n (sslength ss))
      (vla-put-TextString
        (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
        (nft (vla-get-TextString obj))
      ); ...put...
    ); repeat
  ); if
  (princ)
); defun -- C:TNF
(vl-load-com)
(prompt "\nType TNF to round distance Text to the nearest Foot.")
Kent Cooper, AIA
Message 12 of 12

Yuvaraju.Dhananjay
Enthusiast
Enthusiast

awesome 

0 Likes