Levelling program with the third decimal in superscript.

Levelling program with the third decimal in superscript.

miklos.bartal
Explorer Explorer
388 Views
6 Replies
Message 1 of 7

Levelling program with the third decimal in superscript.

miklos.bartal
Explorer
Explorer

Hello Everyone! 

 

I fixed an old levelling program which I found on the internet, but didn't work me. 

Everything is working now, but I want to write the third decimal number in superscript (which is the mm height). 

 

I tried the way that I defined different functions, and with RTOS I can get (RTOS yvalue 2 3) - (RTOS yvalue 2 2) = 0.00x  

 

 (SETQ ltext1 (LM:RTOS yvalue 2 2))
;         (SETQ ltext2 (LM:RTOS yvalue 2 3))
;         (SETQ ltext3 (- ltext2 ltext1))
;         (SETQ ltext4 (* 1000 ltext3))
	 (SETQ ltext (STRCAT prefix ltext1 (something magical to have superscript) ltext4))

 

than I would have the "ltext" which I insert to an Mtext of a dynamic block. 

 

Instead of this: image.png  I'd like to have this:  miklosbartal_0-1642584815803.png

 

Lets see if there is a solution, thank you for your help in advance! 

 

 

0 Likes
389 Views
6 Replies
Replies (6)
Message 2 of 7

hak_vz
Advisor
Advisor

Try this code. It creates MTEXT with third decimal in superscript. Since you say that you know some lisp programing you can modify this code according to your needs.

 

 

 

(defun ltrs(val / a b c d pt pref)
(if (< val 0.0) (setq pref "-")(setq pref "+"))
(setq val (atof(rtos (abs val) 2 3)))
(setq a (fix val) b (* 1000.0(- val a)) c (rtos b 2 3))
(if (< b 10) (setq c (strcat "00" c)))
(if (and(>= b 10)(< b 100)) (setq c (strcat "0" c)))
(setq a (itoa a) b (substr c 1 2) d (substr c 3 1))
(setq a (strcat pref a "." b))
(setq a (strcat "\\A1;" a "{\\H0.7x;\\S" d "^;}"))
(setq pt (getpoint "\nPick insertion point >"))
(entmake
	(list
		(cons 0 "MTEXT")
		(cons 100 "AcDbEntity")
		(cons 100 "AcDbMText")
		(cons 1 a)
		(cons 10 pt);Reference rectangle width
		(cons 40 2.5) ;nominal text height
		(cons 41 0.0)
		(cons 50 0.0);rotation angle
		(cons 71 4);middle left
		(cons 72 1);left to right
		
	) ;list
) ;entmake

(princ)
)

(defun c:ltrs () (ltrs (getreal "\nInput value >")))

 

 

 

Usage

 

 

 

(ltrs 1.235)

 

 

 

Or

 

 

 

Command: LTRS
Input value >2
Pick insertion point >
Command:

 

 

 

 Untitled.png

To just get a mtext string

 

(defun c:ltr () (ltr (getreal "\nInput value >")))

(defun ltr(val / a b c d pt pref)
(if (< val 0.0) (setq pref "-")(setq pref "+"))
(setq val (atof(rtos (abs val) 2 3)))
(setq a (fix val) b (* 1000.0(- val a)) c (rtos b 2 3))
(if (< b 10) (setq c (strcat "00" c)))
(if (and(>= b 10)(< b 100)) (setq c (strcat "0" c)))
(setq a (itoa a) b (substr c 1 2) d (substr c 3 1))
(setq a (strcat pref a "." b))
(strcat "\\A1;" a "{\\H0.7x;\\S" d "^;}")
)
Command: LTR
Input value >1.15
"\\A1;+1.15{\\H0.7x;\\S0^;}"

Or

(setq ltext (ltr value))

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 7

hak_vz
Advisor
Advisor

@miklos.bartal  Have you tested the code I provided? Do you need any changes or functionality?

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 7

miklos.bartal
Explorer
Explorer

Thank you for your answer, til now I had no time, but tomorrow I will try. 

0 Likes
Message 5 of 7

miklos.bartal
Explorer
Explorer

Hello! 

 

I just finished the code and tried it. 

It works but have some issues. Sometimes it has a negative superscript, and it seems randomly. 

Do you have any idea? 

miklosbartal_0-1642675518815.png

there should be the problem somewhere: 

(SETQ yvalue (+ yd ldatum))
	  (COND
	    ((= yvalue 0) (SETQ prefix "%%P")) ;level prefix if zero
	    ((> yvalue 0) (SETQ prefix "+")) ;level prefix if plus
	    ((< yvalue 0) (SETQ prefix "")) ;level prefix if minus
	    ) ;end cond
         (SETQ ltext1 (ATOF(LM:RTOS yvalue 2 2)))
         (SETQ ltext2 (ATOF(LM:RTOS yvalue 2 3)))
         (SETQ ltext3 (* 1000 (- ltext2 ltext1)))
         (SETQ ltext1 (LM:RTOS ltext1 2 2))
         (SETQ ltext3 (LM:RTOS ltext3 2 0))
	 (SETQ ltext (STRCAT prefix ltext1))
         (SETQ ltext (STRCAT "\\A1;" ltext "{\\H0.7x;\\S" ltext3 "^;}"))

Thanks! 

0 Likes
Message 6 of 7

miklos.bartal
Explorer
Explorer

And it is cheating with the mm heights. 

miklosbartal_0-1642676140149.png

In my point of view the ltext2 is always bigger than ltext1, because rtos cuts the initial yvalue after the specified decimal place and do not rounding at all. So I don't understand what is the problem. 

Lets say:

- yvalue= 109,119235

- ltext1= 109,11

- ltext2= 109,119

- ltext3= 9

(SETQ ltext1 (ATOF(LM:RTOS yvalue 2 2)))
(SETQ ltext2 (ATOF(LM:RTOS yvalue 2 3)))
(SETQ ltext3 (* 1000 (- ltext2 ltext1)))

 

0 Likes
Message 7 of 7

hak_vz
Advisor
Advisor

@miklos.bartal  Have you tried code I provided? It worked well for all test cases and I applied corrections in case when decimal part is either .00x or .0xx since using rtos on decimal part will omit zeros.  Currently have no time to test your code.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes