Area field + m²

Area field + m²

aclima
Contributor Contributor
6,265 Views
17 Replies
Message 1 of 18

Area field + m²

aclima
Contributor
Contributor

Hello.

I believe this lisp may already exists but I've not be able to find it. Maybe one of you can help me.
I'm looking for a lisp that creates an mtext with the area of a polyline as object "field" and the suffix "m²", will be very useful for the work I'm doing. thank you

 

0 Likes
Accepted solutions (1)
6,266 Views
17 Replies
Replies (17)
Message 2 of 18

dennis
Advisor
Advisor
0 Likes
Message 3 of 18

Ranjit_Singh
Advisor
Advisor

Here's a very basic version

(defun c:somefunc  (/ mtobject mtht)
 (setq mtht     (getreal "\nEnsert mText Height: ")
       mtobject (vla-addmtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
                              (vlax-3d-point (getpoint "\nInsert mText Insertion Point :"))
                              0
                              (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                                      (itoa (vla-get-objectid (vlax-ename->vla-object (car (entsel "\nSelect Polyline: ")))))
                                      ">%).Area \\f \"%lu2%pr2%th44\">%"
                                      " m{\\H0.7x;\\S2^;}")))
 (vla-put-height mtobject mtht)
(princ))
0 Likes
Message 4 of 18

aclima
Contributor
Contributor

Hello

Thank you, this error appears after importing lisp with appload. Same arror appear after running the command.

 

"somefunc.lsp successfully loaded.
somefunc.lsp successfully loaded.
Command: ; error: malformed list on input
Command: ; error: malformed list on input"

0 Likes
Message 5 of 18

Ranjit_Singh
Advisor
Advisor

Try the attached

Message 6 of 18

aclima
Contributor
Contributor

Hi again!

Thanks a lot for the help.

I would make the following two changes: the command would not ask what the height of mtxt would be (it would use the default value), and more importantly, it would allow the user to change the pecision of the value it displays. In the work I am currently doing, for example, I should not present decimal places.

I also noticed that the text is not placed at the insertion point if the UCS is rotated.
Still, it's already a good help, thank you.

0 Likes
Message 7 of 18

Ranjit_Singh
Advisor
Advisor

I am mostly working in wcs and never try to catch ucs in my routines. Those are good points. Try below code.

(defun c:somefunc  (/ mtobject mtprec)
 (initget 7)
 (setq mtprec     (getint "\nEnter mText decimal Precision: ")
       mtobject (vla-addmtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
                              (vlax-3d-point (trans (getpoint "\nInsert mText Insertion Point :") 1 0))
                              0
                              (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                                      (itoa (vla-get-objectid (vlax-ename->vla-object (car (entsel "\nSelect Polyline: ")))))
                                      ">%).Area \\f \"%lu2%pr" (if (> mtprec 8) "8" (itoa mtprec)) "%th44\">%"
                                      " m{\\H0.7x;\\S2^;}")))
 (vla-put-height mtobject (getvar 'textsize))
 (mapcar '(lambda (x y) (setpropertyvalue (entlast) x y)) '("Direction/X" "Direction/Y") (list (car (getvar 'ucsxdir)) (cadr (getvar 'ucsxdir))))
 (princ))
Message 8 of 18

aclima
Contributor
Contributor

Nice 🙂

The only thing is, if i'm using it correctly, it doesn't allow to remove all decimal places with the "Enter mText decimal Precision" input. The minimum acceptable is 1.

I would also present the last value imputed in this option as default when running the command again command , to speed up the process of multiple area tagging.

thanks

 

 

0 Likes
Message 9 of 18

Ranjit_Singh
Advisor
Advisor
Accepted solution

That shouldn't be too difficult.

(defun c:somefunc  (/ mtobject prec)
 (if (null *somefuncmtprec*) (setq *somefuncmtprec* 2))
 (initget 4)
 (setq prec     (getint (strcat "\nEnter mText decimal Precision <" (itoa *somefuncmtprec*) ">: "))
       mtobject (vla-addmtext (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
                              (vlax-3d-point (trans (getpoint "\nInsert mText Insertion Point :") 1 0))
                              0
                              (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                                      (itoa (vla-get-objectid (vlax-ename->vla-object (car (entsel "\nSelect Polyline: ")))))
                                      ">%).Area \\f \"%lu2%pr" (if (> prec 8) (progn (setq *somefuncmtprec* 8) "8") (if (null prec) (itoa *somefuncmtprec*) (progn (setq *somefuncmtprec* prec) (itoa *somefuncmtprec*)))) "%th44\">%"
                                      " m{\\H0.7x;\\S2^;}")))
 (vla-put-height mtobject (getvar 'textsize))
 (mapcar '(lambda (x y) (setpropertyvalue (entlast) x y)) '("Direction/X" "Direction/Y") (list (car (getvar 'ucsxdir)) (cadr (getvar 'ucsxdir))))
 (princ))
Message 10 of 18

aclima
Contributor
Contributor

Thank you! 🙂

It works beautifully and will be a great help. 

 

 

0 Likes
Message 11 of 18

Ranjit_Singh
Advisor
Advisor

You are welcome Smiley Happy

0 Likes
Message 12 of 18

SufyanAhmed
Participant
Participant

Hi,Aclima

 

 

Find the attached file may be found useful to You.

0 Likes
Message 13 of 18

aclima
Contributor
Contributor

hello. This lisp is not working anymore, can you help?

0 Likes
Message 14 of 18

cadffm
Consultant
Consultant

Hi,

It is working the same way as before,  also in 2023.

 

Open a new file, draw a rectangle

load the lisp by APPLOAD and run command AA2

after this (you say it dowsn't work),

open your Textscreen[F2] and share the log content with us all.

Sebastian

0 Likes
Message 15 of 18

aclima
Contributor
Contributor

Hi, Thanks for the feed back, I'm referring to this one from @Ranjit_Singh . 

Cad loads but doesn't run, command is "mtobject", right?

cap.jpg

0 Likes
Message 16 of 18

cadffm
Consultant
Consultant

@aclima  schrieb:

Hi, Thanks for the feed back, I'm referring to this one from @Ranjit_Singh . 

Oh, okay - I checked the other one.

 

 

Cad loads but doesn't run, command

No (error)message?

Normally you get a message!?

Like "unknown command" is you try to start a command what doesn't exist.

 

is "mtobject", right?

?

CADffm_0-1651242197262.png

 

That looks more like "somefunc" 🙂

 


 

 

Sebastian

Message 17 of 18

aclima
Contributor
Contributor

somefunc, of course.

silly mistake. 🙂 Beautiful!

Thanks!

0 Likes
Message 18 of 18

fpanUVCLZ
Observer
Observer
hello,
this LISP is good help for me. thank you for your sharing.

I'd like to make the following two changes: the command would not ask what the height of mtext, but it would use 200 height as default value. Also, the command would not ask what the precision of the value it displays, it would setting a precision of 3 d.p. as default value.
thanks.
0 Likes