LISP for creating MText from Hatch Area

LISP for creating MText from Hatch Area

griffinLGJJ2
Explorer Explorer
550 Views
9 Replies
Message 1 of 10

LISP for creating MText from Hatch Area

griffinLGJJ2
Explorer
Explorer

Hi,

Very new to LISP but after years of using AutoCAD I'm finding it's time to dive in.

I work with files that have many hatches and would love a routine that allows me to click on a hatch -> generates an MText object, the contents of which are that object's Area from its properties, placed somewhere near the hatch. That way I can always reference the text if I need to pull the area for something, instead of having to click and refer to the properties every time.

Is this even possible? 

P.S. I should mention my office uses AutoCAD for Mac, which, I'm finding, doesn't support many AutoLISP functions.

Thanks

0 Likes
551 Views
9 Replies
Replies (9)
Message 2 of 10

Sea-Haven
Mentor
Mentor

Can you try this simple bit of code please. Dont have a MAC version expects text style is standard and 0 height.

 

(defun c:wow ( / )
(vla-load-com)
(setq obj (vlax-ename->vla-object (car (entsel "\nPick hatch object ")))) 
(setq harea (vla-get-area obj))
(command "text" (getpoint "\nPick point for text") 2.5 0.0 (strcat (rtos harea 2 2) "m2"))
(princ)
)
(c:wow)

 

 

0 Likes
Message 3 of 10

griffinLGJJ2
Explorer
Explorer
I got this:
Exception has occurred.
no function definition: VLAX-ENAME->VLA-OBJECT
I believe VLAX-ENAME->VLA-OBJECT is only available in Windows unfortunately.
0 Likes
Message 4 of 10

Sea-Haven
Mentor
Mentor

Added Vl-load-com, can you try again, I did google MAC and VL.

0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@griffinLGJJ2 wrote:
.... I believe VLAX-ENAME->VLA-OBJECT is only available in Windows unfortunately.

If the (vl-load-com) thing doesn't work, are the (getpropertyvalue)/(setpropertyvalue) functions available?  If so, you can get the Area of a Hatch pattern without the VLA conversion, to use in the same way to populate the Text:

(getpropertyvalue theHatchPatternEntityName "Area")

Kent Cooper, AIA
0 Likes
Message 6 of 10

griffinLGJJ2
Explorer
Explorer

Same issue but now with the vla-load-com, that may also be available in Windows only

 

Screenshot 2025-01-20 at 9.38.48 PM.png

0 Likes
Message 7 of 10

Sea-Haven
Mentor
Mentor

Here is another a very old program no VL.

0 Likes
Message 8 of 10

Kent1Cooper
Consultant
Consultant

It's (vl-load-com)  [no a].  Try that.

Kent Cooper, AIA
0 Likes
Message 9 of 10

griffinLGJJ2
Explorer
Explorer

Seems like these are available! Now I just have to figure out how to incorporate that into the code...😂

0 Likes
Message 10 of 10

Sea-Haven
Mentor
Mentor

Thanks Kent I think my Bricscad always loads (vl-load-com). 

 

If you want mtext rather than Text need a slightly different version. I did not add the superscript 2 as I am not sure how the MAC version works.

 

(command "mtext" (setq pt (getpoint "\nPick ")) pt (strcat (rtos harea 2 2) "m2") "")

 

0 Likes