Text Area calculation

Text Area calculation

k005
Advisor Advisor
3,112 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,113 Views
40 Replies
Replies (40)
Message 2 of 41

pbejse
Mentor
Mentor

@k005 wrote:

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²

 

What you need is an association list. for example

 

(setq wanted_list '(
	     ("PZ01 (150/25)" "0.375 m²")
	     ("SZ12 (60/40)" "0.24 m²")
	     ("PZ03 (180/30)" "0.54 m²")
	    )
)

 

When you collect the TEXT object you can use the string value as key to get the desired value.

 

(setq en (car (entsel "\nSelect TEXT object: ")))
(setq str (cdr (assoc 1 (entget en))))
      
(if (setq f (assoc str wanted_list))
  (princ (strcat "\nValue is " (cadr f)))
)

 

Let say str is ""SZ12 (60/40)" You will get this result

"Value is 0.24 m²"

 

Hope this helps

 

 

Message 3 of 41

k005
Advisor
Advisor

@pbejse 

 

First, we will select TEXT objects and create a list.

 

after that:

In this list, we will multiply the values in parentheses. i.e. according to the corresponding object.

We will print dwg as TEXT object in m unit. so much.

 

wanted list ( in DWG )
0.375 m²
0.24 m²
0.54 m²

0 Likes
Message 4 of 41

pbejse
Mentor
Mentor

@k005 wrote:

In this list, we will multiply the values in parentheses. i.e. according to the corresponding object.

We will print dwg as TEXT object in m unit. so much.

 


I figured as much, at first i wasnt sure of that.

Question : is the string just like this "SZ12 (60/40)"? and not in a middle/start/end of a longer string?

 

Message 5 of 41

k005
Advisor
Advisor

Yes. This is how String usually looks like.
The values we want are always in parentheses.

0 Likes
Message 6 of 41

pbejse
Mentor
Mentor

Here you go

(defun _WantedList (str / p )
  (if
      (wcmatch str "*(*#/#*)*")
      (setq p (vl-string-position 40 str)
          str (strcat (rtos (apply '*
		(cons  0.0001
		  (read (Vl-string-subst " " "/" (substr str (1+ p)))) )
	      		) 2 2 ) " m²")
	    )
	)
  )

_$ (_WantedList "PZ03 (180/30)")
"0.54 m²"
_$ (_WantedList "HERE IT IS ANYWAY, SZ12 (60/40) YEAH WHY NOT")
"0.24 m²"

I'll ask anyway, what to do for this kind of string value?

_$ (_WantedList "THERE ARE TWO HERE PZ03 (180/30) AND SZ12 (60/40)")
"0.54 m²"

As you can see, it gives you only the first. If this never happens then dont worry about it.

 

HTH

0 Likes
Message 7 of 41

k005
Advisor
Advisor

 

 

That way a string value cannot be in my work. only 1 left parenthesis. 1 becomes a right parenthesis.

0 Likes
Message 8 of 41

k005
Advisor
Advisor

@pbejse 

 

(defun _WantedList (str / p )
  (if
      (wcmatch str "*(*#/#*)*")
      (setq p (vl-string-position 40 str)
          str (strcat (rtos (apply '*
		(cons  0.0001
		  (read (Vl-string-subst " " "/" (substr str (1+ p)))) )
	      		) 2 2 ) " m²")
	    )
	)
  )

 

error:

 

; error: too few arguments

0 Likes
Message 9 of 41

pbejse
Mentor
Mentor

@k005 wrote:

That way a string value cannot be in my work. only 1 left parenthesis. 1 becomes a right parenthesis.


Ok then, use the want _WantedList function to get the value as shown on my previous post, Or do you need help to complete the program? 

 


@k005 wrote:

error:

; error: too few arguments

 

How did you use the sub? You need to supply the collected string value.

(setq en (car (entsel "\nSelect TEXT object: ")))
(setq str (cdr (assoc 1 (entget en))))
(setq new value (wanted_list str))

HTH

 

0 Likes
Message 10 of 41

k005
Advisor
Advisor

@pbejse 

 

I could not merge the codes...

0 Likes
Message 11 of 41

pbejse
Mentor
Mentor

@k005 wrote:

I could not merge the codes...


Post your entire code and we will merge it for you.

 

 

 

0 Likes
Message 12 of 41

hak_vz
Advisor
Advisor

--

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 13 of 41

k005
Advisor
Advisor

 

@pbejse 

 

The code is what you sent... there is no other code.?

 

I think the question is a bit confused.

I am attaching dwg file.

 

 

0 Likes
Message 14 of 41

pbejse
Mentor
Mentor

@k005 wrote:

I think the question is a bit confused.


It is confusing.

 

You have all those string object with the current value of  "SZ07 (60/30)", convert the value to "m unit" 

and do what with the result?  print on the command line? an alert box? is that per selection? or all of the same time?

OR

Place a new TEXT object with the new string or replace the current string with the new value? "SZ07 (60/30)" as "SZ07 ("0.18 m²)" or just "0.18 m²" 

 

 

Message 15 of 41

hak_vz
Advisor
Advisor

I also wanted to reply, but request is a bit confusing. In reality this is a simple string substitution using assoc lists if we deal with unique list members in basic list ie ("SZ01 (30/60)" . 0.325). We don't know if SZ01 is some member position mark or a type. In other words, do we have other possible type (position) for which area corresponds to led say 0.325 m2, That means do (xxxx 60/30) or (xxxx 30/60) have same area 0.325 for any type (position)?

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 16 of 41

k005
Advisor
Advisor

 

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

0 Likes
Message 17 of 41

k005
Advisor
Advisor

Yes . I admit it's a bit confusing.

0 Likes
Message 18 of 41

k005
Advisor
Advisor

 

@pbejse 

 

@hak_vz 

 

If we simplify;

 

What I need are the results of the multiplications.

0 Likes
Message 19 of 41

hak_vz
Advisor
Advisor

Ok. What I guess from you sample you have unique positions in your drawing. For each of this you have unique replacing area value that is result of calculation (let say total rebar section area). Try to explain what you work. Most of us area engineers and will probably understand you request easier with some more details provided, and we may even offer you better solution (approach) to final solution.

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 20 of 41

k005
Advisor
Advisor

@hak_vz 

 

 

Calculating the (xx*xx) values in all the texts in the drawing I sent. So much. Another issue is related to drawing.

0 Likes