• Add-On’s
  • Download
  • History of AutoLISP
  • Lisp Resources
  • Run an AutoLISP

LispBox

~ This blog was initially created for people, who love autolisp routines, as I love it.

Monthly Archives: August 2015

Roman Integer Text/Mtext Converter “vica versa” by click on text

02 Sunday Aug 2015

Posted by danglar71 in Text

≈ Leave a comment

;Combined by Igal Averbuh 2015

(vl-load-com); if not already loaded

; Copyright ©2005 - Marc'Antonio Alessi, Italy - All rights reserved
; http://xoomer.virgilio.it/alessi
;
; Function: ALE_IsRoman
;
; Version 1.01 - 19/07/2005
;
; Description: verify and convert a Roman number to integer
; > Based on Roman classic style > 499 = CDXCIX
;
; Arguments:
; In_Str: a valid Roman number - string
;
; Return Values: integer from 1 to 3999 or nil on error
;
; Example:
; (ALE_IsRoman "MMMDCCCLXXXVI") => 3886
; (ALE_IsRoman "IIAIV") => nil
; (ALE_IsRoman "VV") => nil
;
; Note:
; ----> I=1 V=5 X=10 L=50 C=100 D=500 M=1000
; ascii 73 86 88 76 67 68 77
;
(defun ALE_IsRoman (In_Str / ValLst OutVal TmpVal IntVal NumLst)
(if
(or
(not
(vl-every
'(lambda (LmbDat)
(vl-position LmbDat '(73 86 88 76 67 68 77))
)
(setq ValLst (vl-string->list In_Str))
)
)
(wcmatch In_Str
(strcat
"*IIII*,*VV*,*XXXX*,*LL*,*CCCC*,*DD*,*MMMM*,"
"*IVIV*,*IXIX*,*XLXL*,*XCXC*,*CDCD*,*CMCM*,"
"*IIMXCC*,*VX*,*DCM*,*CMM*,*IXIV*,*MCMC*,"
"*XCX*,*IVI*,*LM*,*LD*,*LC*"
)
)
)
nil ;(progn (princ "\nNot valid Roman numeral! ") nil)
(progn
(setq
OutVal 0 TmpVal 0
NumLst '(
(73 . 1) (86 . 5) (88 . 10) (76 . 50)
(67 . 100) (68 . 500) (77 . 1000)
)
)
(foreach ForElm (reverse ValLst)
(if (= 3999 OutVal 1)
OutVal
;(progn (princ "\nOut of range! ") nil)
)
)
)
)

;
; Copyright ©2005 - Marc'Antonio Alessi, Italy - All rights reserved
; http://xoomer.virgilio.it/alessi
;
; Function: ALE_Int->Roman
;
; Version 1.00 - 20/07/2005
;
; Description: convert an integer to Roman number
; > Based on Roman classic style > 499 = CDXCIX
;
; Arguments:
; IntVal: integer from 1 to 3999
;
; Return Values: Roman number - string - or nil on error
;
; Example:
; (ALE_Int->Roman 3886) => "MMMDCCCLXXXVI"
; (ALE_Int->Roman 0) => nil
; (ALE_Int->Roman 4000) => nil
;
;
(defun ALE_Int->Roman (IntVal / OutStr ValLst)
(if (>= 3999 IntVal 1)
(progn
(setq
OutStr ""
ValLst
'( ( (48 . "")(49 . "I")(50 . "II")(51 . "III")(52 . "IV")
(53 . "V")(54 . "VI")(55 . "VII")(56 . "VIII")(57 . "IX") )
( (48 . "")(49 . "X")(50 . "XX")(51 . "XXX")(52 . "XL")
(53 . "L")(54 . "LX")(55 . "LXX")(56 . "LXXX")(57 . "XC") )
( (48 . "")(49 . "C")(50 . "CC")(51 . "CCC")(52 . "CD")
(53 . "D")(54 . "DC")(55 . "DCC")(56 . "DCCC")(57 . "CM") )
( (48 . "")(49 . "M")(50 . "MM")(51 . "MMM") ) )
)
(foreach ForElm (reverse (vl-string->list (itoa IntVal)))
(setq
OutStr (strcat (cdr (assoc ForElm (car ValLst))) OutStr)
ValLst (cdr ValLst)
)
)
OutStr
)
)
)

(defun c:rm ( / TxtObj)
(if (setq TxtObj (vlax-Ename->Vla-Object (car (entsel "\nSelect Integer Text/Mtext to convert to Roman text: "))))
(vla-Put-textstring
TxtObj
(ALE_Int->Roman (atoi(vla-Get-textstring TxtObj)))
)
)
)

(defun c:ri (/ txt txtdata txtstr)

(setq

txt (car (entsel "\nSelect Roman Text/Mtext 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

(defun c:ROM ()
(initget "Roman Integer")
(setq which
(cond
( (getkword
(strcat
"Convert to [Roman/Integer] : "
); strcat
); getkword
); User-entry condition
(which); User pressed Enter with previous choice -- use it
("Roman"); User pressed Enter without previous choice [first use] -- use initial default
); cond
); setq
(if (= which "Roman") (c:rm))
(if (= which "Integer") (c:ri))
); defun

(c:rom)

Recent Posts

  • Это наша плата за трусость
  • Set the Default Application to open DWG Files
  • Draw “Heat Grid” (Lee Mac)
  • PROGRAM FOR SPRINKLER DISTRIBUTION
  • How to remove Frames around blocks

Recent Comments

Wilmer Lacayo on Draw Centroid (center of gravi…
Jun on Convert Polylines to Leaders i…
Adel on HVAC Draw Branch Duct
danglar71 on Draw “Heat Grid” (…
IOAN VLAD on Draw “Heat Grid” (…

Archives

  • January 2021
  • March 2020
  • February 2020
  • January 2020
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014

Categories

  • 3D
  • Annonymous Blocks
  • Attribute
  • Batch
  • Blocks
  • Books
  • Common
  • Coordinates
  • Counting
  • dimmensions
  • draw
  • Export
  • Fractal
  • Hatch
  • HVAC
  • Images
  • Import
  • Info
  • Isometric
  • Layers
  • Layouts
  • Lisp Collection 2014
  • Mline
  • Pdf
  • Pipes
  • plot
  • Points
  • Protect
  • Text
  • Tips (English)
  • Tips (Russian)
  • ucs
  • Utilites
  • view
  • Vport
  • Xref

Recent Posts

  • Это наша плата за трусость
  • Set the Default Application to open DWG Files
  • Draw “Heat Grid” (Lee Mac)
  • PROGRAM FOR SPRINKLER DISTRIBUTION
  • How to remove Frames around blocks

Recent Comments

Wilmer Lacayo on Draw Centroid (center of gravi…
Jun on Convert Polylines to Leaders i…
Adel on HVAC Draw Branch Duct
danglar71 on Draw “Heat Grid” (…
IOAN VLAD on Draw “Heat Grid” (…

Archives

  • January 2021
  • March 2020
  • February 2020
  • January 2020
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014

Categories

  • 3D
  • Annonymous Blocks
  • Attribute
  • Batch
  • Blocks
  • Books
  • Common
  • Coordinates
  • Counting
  • dimmensions
  • draw
  • Export
  • Fractal
  • Hatch
  • HVAC
  • Images
  • Import
  • Info
  • Isometric
  • Layers
  • Layouts
  • Lisp Collection 2014
  • Mline
  • Pdf
  • Pipes
  • plot
  • Points
  • Protect
  • Text
  • Tips (English)
  • Tips (Russian)
  • ucs
  • Utilites
  • view
  • Vport
  • Xref

Create a free website or blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy