Text Area calculation

Text Area calculation

k005
Advisor Advisor
3,140 Views
40 Replies
Message 1 of 41

Text Area calculation

k005
Advisor
Advisor

How can I print the area of the text objects (**x**) in the texts I have given in the example?

Existing list ( text object)

PZ01 (150/25)
SZ12 (60/40)
PZ03 (180/30)
.....
.....

wanted list
0.375 m²
0.24 m²
0.54 m²
.....
.....

 

 

 

 

SZ01 (30/60)
SZ04 (60/35)
SZ02 (35/60)
SZ03 (30/60)
SZ06 (40/70)
SZ05 (60/40)
PZ02 (255/25)
SZ08 (80/30)
SZ07 (60/30)
SZ11 (60/30)
SZ10 (40/60)
SZ13 (40/90)
SZ09 (40/65)
SZ16 (40/60)
SZ17 (40/60)
SZ15 (40/60)
SZ14 (30/60)
PZ05 (25/180)
PZ04 (25/150)
PZ01 (150/25)
SZ12 (60/40)
PZ03 (180/30)

0 Likes
Accepted solutions (3)
3,141 Views
40 Replies
Replies (40)
Message 21 of 41

hak_vz
Advisor
Advisor
Accepted solution

I guess this is what you asked for.

 

 

(defun c:repl (/ *error* adoc  string_to_list ss e ent i nt)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(princ)
	)
	(defun string_to_list ( str del / pos )
		(if (setq pos (vl-string-search del str))
			(cons (substr str 1 pos) (string_to_list (substr str (+ pos 1 (strlen del))) del))
			(list str)
		)
	)
	(princ "\nSelect text to change with area >")
	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(setq ss (ssget '((0 . "TEXT"))) i -1)
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(while (< (setq i (1+ i)) (sslength ss))
		(setq ent (entget(ssname ss i)))
		(setq e (cdr (assoc 1 ent)))
		(setq e (substr e (+(vl-string-position  (ascii "(") e) 2)))
		(setq e (substr e 1 (- (strlen e)1))) 
		(setq e (string_to_list e "/"))
		(setq e (mapcar 'atof e))
		(setq nt(strcat "("(rtos (/ (* (car e)(cadr e)) 10000.0) 2 3) " \U+33A1" ")"))
		(setq ent (subst (cons 1 nt)(assoc 1 ent) ent))
		(entmod ent)
	)
	(vla-endundomark adoc)
	(princ "\nDone!")
	(princ)
)

It's time to switch to Euro 2020 Ukraine ws England.

 

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.
Message 22 of 41

k005
Advisor
Advisor

@hak_vz 

 

Thank you very much. Yes.! Super!

 

🤗

0 Likes
Message 23 of 41

pbejse
Mentor
Mentor
Accepted solution

@k005 wrote:

we will just create new TEXT. the format is just this: 0.18 m²


 

Here you go

 

(Defun c:TrueSize ( / _WantedList)
(defun _WantedList (str / p )
      (setq p (vl-string-position 40 str))
        (strcat "(" (rtos (apply '*
		(cons  0.0001
		  (read (Vl-string-subst " " "/" (substr str (1+ p)))) )
	      		) 2 3 ) " m²)")
	    )
  (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . "*(*#/#*)"))))
    (repeat (setq i (sslength ss))
      (setq str (getpropertyvalue (setq e (ssname ss (setq i (1- i)))) "TextString"))
      (setq new_str (_WantedList str))
      (setpropertyvalue e "TextString" new_str)
      )
    )(princ)
  )

 

HTH

 

Message 24 of 41

3wood
Advisor
Advisor

You can also try ALTEXT.

Use following codes in ALTEXT as a formula.

formula.PNG

;;; This is an example formula for ALTEXT.vlx
;;; It convert text in a format of "(36/60)" to "0.18m2"  

(defun ALTEXT_FORMULA (/ P1 P2 P3 T0 T1 T2)
  (setq P1 (vl-string-search "(" ALTEXT_STR_ORG) ;(setq ALTEXT_STR_ORG "SZ01 (60/40)")
	P2 (vl-string-search "/" ALTEXT_STR_ORG)
	P3 (vl-string-search ")" ALTEXT_STR_ORG)
	T0 (substr ALTEXT_STR_ORG 1 P1)
	T1 (substr ALTEXT_STR_ORG (+ P1 2) (- P2 P1 1))
	T2 (substr ALTEXT_STR_ORG (+ P2 2) (- P3 P2 1))
	)
   (if (and T0 T1 T2)
     (strcat T0 "(" (vl-string-right-trim "0" (rtos (/ (* (atoi T1) (atoi T2)) 10000.0) 2)) "m\U+00B2)")
     )
  )

Result drawing as in the attachment.

altext2-9.PNG

Message 25 of 41

k005
Advisor
Advisor

@3wood 

 

Thank you. I tried it. ( for 5 of them. trial version)

0 Likes
Message 26 of 41

k005
Advisor
Advisor

@pbejse 

 

 

In one word, Super!

Thank you so much . Exactly as I want. my friend.

0 Likes
Message 27 of 41

pbejse
Mentor
Mentor

@k005 wrote:

Thank you so much . Exactly as I want. my friend.


 

Thank you for letting me know it works for you.  There's one more thing we can do.

(Defun c:TrueSize ( / _WantedList)
(defun _WantedList (str / p )
      (setq p (vl-string-position 40 str))
      (setq n (apply '* 
		  (read (Vl-string-subst " " "/" (substr str (1+ p))))
	      		))
        (strcat "(" (rtos (* n 0.0001) 2 (1+ (fix (/ (log n) (log 10)))) ) " m²)")
	    )
  (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . "*(*#/#*)"))))
    (repeat (setq i (sslength ss))
      (setq str (getpropertyvalue (setq e (ssname ss (setq i (1- i)))) "TextString"))
      (setq new_str (_WantedList str))
      (setpropertyvalue e "TextString" new_str)
      )
    )(princ)
  )

That should take care of the decimal precision.

 

HTH

Message 28 of 41

k005
Advisor
Advisor

@pbejse 

 

Very good... , Thank you very much. 🤗

0 Likes
Message 29 of 41

k005
Advisor
Advisor

Hi@pbejse 

 

 

 

How should we change the code so that we can operate both with and without parentheses in this code?

 

I made a few code changes but without success.

 

 

 

  (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . "*(*#/#*)"))))

 

0 Likes
Message 30 of 41

pbejse
Mentor
Mentor

@k005 wrote:

How should we change the code so that we can operate both with and without parentheses in this code?

 

We can cerainly make it work for both formats, but as always, i need a sample drawing of what is and what it will be

[ before / after ] for both conditions so there will be no confusion. 

 

 

Message 31 of 41

k005
Advisor
Advisor

@pbejse 

 

 

I attached the file

0 Likes
Message 32 of 41

pbejse
Mentor
Mentor
Accepted solution
(Defun c:TrueSize ( / _Clean _WantedList ss str new_str)
(Defun _Clean (Str)
       (foreach itm '(("(" "") (")" "")(" " "")("/" " "))
		(setq str (Vl-string-subst (cadr itm) (car itm)str))))  
(defun _WantedList (str / val p )
	(if
	  (and
	  	(vl-some  '(lambda (d)
		    (setq p (vl-string-position d str))) '(40 32)
		  )
	  	(setq n (apply '*
			  (read (strcat  "(" (_Clean (substr str (1+ p))) ")"))
		      		))
		)
	 (strcat  (rtos (* n 0.0001) 2 (1+ (fix (/ (log n) (log 10)))) ) " m²")
	  
	)
  )  
  (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . "*(*#/#*),* *#/#*"))))
    (repeat (setq i (sslength ss))
      (setq str (getpropertyvalue (setq e (ssname ss (setq i (1- i)))) "TextString"))
      (setq new_str (_WantedList str))
      (setpropertyvalue e "TextString" new_str)
      )
    )(princ)
  )

HTH

 

Message 33 of 41

k005
Advisor
Advisor

@pbejse 

 

Thank you so much my friend. It's ok. 🤗

0 Likes
Message 34 of 41

k005
Advisor
Advisor

@pbejse 

😔

 

I exaggerated a bit, but can we just add a format like "30/60" to the list?

0 Likes
Message 35 of 41

pbejse
Mentor
Mentor

I suggest for now please look for other conditions that you might have overlooked.

Reply back only if you are sure you got every format covered.

 

 

0 Likes
Message 36 of 41

k005
Advisor
Advisor

@pbejse 

 

Now when I say every form... Actually, there is no other form for now. I have 3 formats in total...

0 Likes
Message 37 of 41

pbejse
Mentor
Mentor

@k005 wrote:

Now when I say every form... Actually, there is no other form for now. I have 3 formats in total...


A quick mod

 

(Defun c:TrueSize ( / _Clean _WantedList ss str new_str)
(Defun _Clean (Str)
       (foreach itm '(("(" "") (")" "")(" " "")("/" " "))
		(setq str (Vl-string-subst (cadr itm) (car itm)str))))  
(defun _WantedList (str / val p )
	(if
	  (and
	  	(or
		    (vl-some '(lambda (d)
			   (if (setq p (vl-string-position d str))
			      	(setq str (substr str (1+ p)))))
				 '(40 32))
	    	(wcmatch str "#*/*#"))
	  	(setq n (apply '*
			  (read (strcat  "(" (_Clean str) ")"))
		      		))
		)
	 (strcat  (rtos (* n 0.0001) 2 (1+ (fix (/ (log n) (log 10)))) ) " m²")
	  
	)
  )  
  (if (setq ss (ssget "_:L" '((0 . "TEXT")(1 . "*(*#/#*),* *#/#*,#*/*#"))))
    (repeat (setq i (sslength ss))
      (setq str (getpropertyvalue (setq e (ssname ss (setq i (1- i)))) "TextString"))
      (if
	  (setq new_str (_WantedList str))
      		(setpropertyvalue e "TextString" new_str)
	)
      )
    )(princ)
  )

 

HTH

 

Message 38 of 41

k005
Advisor
Advisor

@pbejse 

 

In one word, Super!.

 

Thank you very much. It's ok.

 

thanks my friend. 🤗

0 Likes
Message 39 of 41

k005
Advisor
Advisor

Hi@pbejse 

 

 

How can we print the total area without breaking these formats?

 


S103 30/80
S103 (30/80)

30/80

 

 

0 Likes
Message 40 of 41

pbejse
Mentor
Mentor

@k005 wrote:

How can we print the total area without breaking these formats?

Command: TrueSizer

 

 

0 Likes