Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Edit/Convert Text with Number Values

Anonymous

Edit/Convert Text with Number Values

Anonymous
No aplicable

I'm currently looking to edit all of the contents of a layer of multiple text boxes. Right now my method produces a new value (which is also okay, I just am trying to do it all in one go). I have a large array of texts with number values that are currently in decimal form (representing inches). I need to convert (or produce a new item) each one to feet in fraction form. I can currently do this one at a time using "field > formula > insert field > select object > contents > divide by 12 > additional formatting > conversion factor of 12 > set as architectural". I need a way to do this all at once by selecting the contents of a layer or something but cannot figure it out. Hopefully someone can help. Thank you.  

0 Me gusta
Responder
Soluciones aceptadas (1)
2.897 Vistas
6 Respuestas
Respuestas (6)

Kent1Cooper
Consultant
Consultant

Try this, in very simplest terms:

 

(defun C:DI2FIF (/ ss n tdata txt); = Decimal Inches to Feet-Inches-Fractions
  (if (setq ss (ssget '((0 . "TEXT"))))
    (repeat (setq n (sslength ss))
      (setq
        tdata (entget (ssname ss (setq n (1- n))))
        txt (cdr (assoc 1 tdata))
      ); setq
      (entmod
        (subst
          (cons 1 (rtos (atof txt) 4 2))
          (assoc 1 tdata)
          tdata
        ); subst
      ); entmod
    ); repeat
  ); if
); defun

Change that 2 to something else for a different round-to-nearest value [that's to the nearest 1/4"].

Kent Cooper, AIA

Anonymous
No aplicable

I'm pretty new, so I'm a little unsure what I am looking for. I have tried just copy/paste, but with no success. I also attempted to use it in the field formula. Thank you very much for the help

0 Me gusta

Kent1Cooper
Consultant
Consultant
Solución aceptada

[If the code lines didn't have any of the semicolon-prefixed comments, you could probably just copy-paste it into the Command line, but the comments foil that approach.]

 

Copy the code-window contents and paste into a plain-text editor such as Notepad.  Save to a file with a .lsp filetype ending [you can call it whatever you want before that].  In an AutoCAD drawing, use APPLOAD to navigate to and load that file.  The command name is the part immediately following the C: [in this case DI2FIF] -- type that in to use it.  It will ask you to "Select objects" in typical editing-command fashion, and you can choose them using any object-selection method(s) you like, and give it an Enter when you're done.  [It will "see" only plain-Text objects in the selection, so you can grab a window around an area even if it contains other kind(s) of thing(s).]  It will then convert the units format of each.

Kent Cooper, AIA

Anonymous
No aplicable

Thank you very much for all of your help and for following up! That's amazing of you. If you ever get a second, I'd like to know which part of the code sets the new format for future purposes so I can alter it for various scenarios? Again thank you for this. It is greatly appreciated. 

0 Me gusta

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... I'd like to know which part of the code sets the new format for future purposes so I can alter it for various scenarios? .... 


 

It's the (rtos) function [= convert real (number) to (text) string].  In this:

 

  (rtos (atof txt) 4 2)

 

the (atof) function converts the text-content string [I forget why it's an ato a floating-point [i.e. decimal, real] number for (rtos) to be able to work on it; the 4 is the units mode [Architectural, to get feet-inches-fractions]; and the 2 is the precision [which is the power of 2 of the largest denominator number to round to in units modes that do fractions, or the number of decimal places in Decimal-number units modes].

Kent Cooper, AIA

Anonymous
No aplicable

Thank you! I really appreciate you taking the time to teach me. Hope you have a great weekend!

0 Me gusta