Change text from Integer to Roman by click on text

Change text from Integer to Roman by click on text

danglar
Advocate Advocate
1,026 Views
8 Replies
Message 1 of 9

Change text from Integer to Roman by click on text

danglar
Advocate
Advocate

I found this function on site of Marc'Antonio Alessi http://xoomer.virgilio.it/alessi

function : ALE_Number_Roman.lsp

It can be very useful if we will have possibility to change any integer text (mtext) to Roman by click on text.

Can you create a little lisp to use this function as built-in?

0 Likes
Accepted solutions (1)
1,027 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

@apelbaum2014 wrote:

I found this ... function : ALE_Number_Roman.lsp

....

Can you create a little lisp to use this function as built-in?


Put the file into any location in your Support File Search Path list [in the Files tab in Options], and put this into your acaddoc.lsp file:

(load "ALE_Number_Roman")

 

and it will be loaded into and available in every drawing you open.

Kent Cooper, AIA
0 Likes
Message 3 of 9

danglar
Advocate
Advocate

Thank you for your replay, but the problem is in a way of program working. I mean the program returns the Roman value on the text screen and I want to

change existing integer "arabic" numeric text to the same Roman text by clicking on "arabic" numeric text in my drawing. How can I do it?

0 Likes
Message 4 of 9

Kent1Cooper
Consultant
Consultant

@apelbaum2014 wrote:

... I want to change existing integer "arabic" numeric text to the same Roman text by clicking on "arabic" numeric text in my drawing. ....


Will the arabic numeric text always consist of only characters representing an integer?  Never anything like "A12" or "357B"?

Kent Cooper, AIA
0 Likes
Message 5 of 9

danglar
Advocate
Advocate

In my case any arabic numeric text always consist of only characters representing an integer, but sometimes I have an exceptions..

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

@apelbaum2014 wrote:

In my case any arabic numeric text always consist of only characters representing an integer, but sometimes I have an exceptions..


For the only-integer-string cases, one way would be something like [in very basic terms, and untested]:

 

(defun C:Int2Roman (/ txt txtdata txtstr)

  (setq

    txt (car (entsel "\nSelect Text/Mtext representation of integer number to convert to Roman numeral: "))

    txtdata (entget txt)

    txtstr (cdr (assoc 1 txtdata))

  ); setq

  (entmod

    (subst

      (cons 1 (ALE_Int->Roman (atoi txtstr))); put new value in place of:

      (assoc 1 txtdata); old value, in:

      txtdata; entity data list

    ); subst

  ); entmod

); defun

 

That further assumes that if it's Mtext, it has no internal formatting [font, color, italics or other assignments], but only the plain numerical-character text content.

 

For the occasional exceptions:  There are threads on this Forum about changing the numerical portion of a string that may also contain other non-numerical characters.  Some are about incrementing or stepping the number value [increasing or decreasing it from what it currently is], and some are about assigning a replacement value that may be unrelated to the current value [a stepping value decided by the routine], but there may be other operations.  A Search will probably find something that you can use, substituting the (ALE_Int->Roman) function in place of whatever is used to set the new numerical text portion.

Kent Cooper, AIA
0 Likes
Message 7 of 9

danglar
Advocate
Advocate

Thank you. It works perfect for me! is it possible to do it in "opposite way" I mean for function ALE_IsRoman that verify and convert a Roman number to integer?

0 Likes
Message 8 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@apelbaum2014 wrote:

Thank you. It works perfect for me! is it possible to do it in "opposite way" I mean for function ALE_IsRoman that verify and convert a Roman number to integer?


You're welcome [I love it when something works even if I haven't actually tried it!].  To go the other way, the same general approach should work with the opposite function, but accounting for the fact that in contrast to (ALE_Int->Roman), its input is a string, and so does not need to be converted from string to number, and its output is a number, and so does need to be converted back to a text string:

 

(defun C:Roman2Int (/ txt txtdata txtstr)

  (setq

    txt (car (entsel "\nSelect Text/Mtext representation of Roman numeral to convert to integer text: "))

    txtdata (entget txt)

    txtstr (cdr (assoc 1 txtdata))

  ); setq

  (entmod

    (subst

      (cons 1 (itoa (ALE_IsRoman txtstr))); put new value in place of:

      (assoc 1 txtdata); old value, in:

      txtdata; entity data list

    ); subst

  ); entmod

); defun

 

It could be made more sophisticated, particularly to first apply the function and check whether it returns a number, that is, confirm that the input string represents a valid Roman numeral, before changing the text content [and if not, alert the User instead].

Kent Cooper, AIA
0 Likes
Message 9 of 9

danglar
Advocate
Advocate

Thank you very much! works Perfect!

0 Likes