Link to home
Start Free TrialLog in
Avatar of BillPowell
BillPowell

asked on

Insert Mtext Using VBA with user defined location

I am writing a program that Prompts the user to select an object to measure the area.  When the user selects the object it will insert Mtext with the area values using this statment:

Thisdrawing.ModelSpace.AddMText

The only problem is that I want to allow the user to dynamically select the text placement point instead of specifying the coordinates ahead of time.  On a similar note I had toyed with the idea of having it insert the text using the centroid as the placement point.  Then I realized that Autocad closed polylines do not have centroids, unless you create one for it using a Map command.  Can you think of a way around this?
Avatar of norrin_radd
norrin_radd
Flag of United States of America image

hey bill,
are you using 2005?
Avatar of BillPowell
BillPowell

ASKER

I have both Map2004 and Map2005 installed
ASKER CERTIFIED SOLUTION
Avatar of norrin_radd
norrin_radd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think I got something working.

insertionPoint = ThisDrawing.Utility.GetPoint(, "PICK LOCATION: ")

This was the line of code I needed.  I have it working now except that I cant figure out how to specify the text height as Im adding it, or after Im adding it.  By default Autocad has a text height of 0.200 which is way too small for the drawings I do.

You should be able to set the text size before creating the Mtext.

ThisDrawing.SetVariable "TextSize", TextsizeValue

Also, you need to check the text size for the current text style.
If the text size defined in the text style is zero, then new text placed uses the "TextSize" variable.
If the text size defined in the text style is greater than zero, then any text created using that text style will ignore the "TextSize" variable.

I will confirm this in the morning.

haikle
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry bill I set a variable for the height but never implemented it with the thisdrawing.setvariable
I like haikles " MTextObj.height=TextSizeValue" that may work better.

just a little off topic but haikle mentioned text size being defined in the text style, I dont know about you guys but I always found that to cause problems, do you find alot of people do it that way? just curious.
Cant say that Ive ever changed the default size of a text style.
Thanks guys.
Stay tuned for my next question about how to reference object data for a selected entity.