Mtext object inside Dimension

Mtext object inside Dimension

john.uhden
Mentor Mentor
422 Views
3 Replies
Message 1 of 4

Mtext object inside Dimension

john.uhden
Mentor
Mentor

Anyone know how to get the object ID (or ename) of the mtext inside a dimension?

I was digging myself deeper into the ever-increasing dictionary caves when I figured I'd better stop digging or I'll never get out.

The purpose is that dimension Mtext is just like regular Mtext in that you can turn the Background fill on and off.

But I 'don't want to have to (nentsel) one dimension at a time, but rather operate on a selection set of dimensions.

No, do not suggest using wipeouts or exploding the dimensions.

John F. Uhden

0 Likes
Accepted solutions (1)
423 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

(setq

  edata (entget (car (entsel "\nSelect Dimension: ")))  

  ent (tblobjname "block" (cdr (assoc 2 edata)))

)

 

That gives you the Dimension as a Block table object.  Then you can (entnext) through the parts:

 

(setq ddata (entget (setq ent (entnext ent))))

 

and check what the entity type of that part is until one of them is MTEXT.  In a linear Dimension, it steps through all the line and arrow parts before it gets to the Mtext.  So depending on the type of Dimension, the Mtext will be a varying number of (entnext)'s in.  So wrap it in a test while stepping:

 

(while

  (/=

    (cdr (assoc 0 (setq ddata (entget (setq ent (entnext ent))))))

    "MTEXT"

  ); /=

); while

 

That leaves you [i.e. it left me, in a single test] with 'ent' as the entity name of the Mtext object.

Kent Cooper, AIA
Message 3 of 4

john.uhden
Mentor
Mentor

@Kent1Cooper 

I thought about that in my dreams last night.

Yep, each dimension is a unique anonymous block so (tblobjname) gets you right to it.

Your technique is admirable too.

Many thanks!

My BackgroundFill.lsp (BGF) will now handle dimensions as well.  Yay!

John F. Uhden

0 Likes
Message 4 of 4

michellem
Advocate
Advocate

Hello Kent;

 

That is a pretty neat trick to get the properties of the mtext nested inside of a dimension; however it does not seem to work for setting the nested mtext properties. 

I did a quick test and it failed to set the width of the dimension text (Mtext DXF code 41). This is what I did:

  • Created a dim
  • Manually edited the dim text to adjust the text width. Next typed a long text string and let it word wrap.
  • Used your code to get the entity list for the nested Mtext object. And then set DXF code 41 of that entity back to zero.
  • Once the code was done, no change was visible to the dim until I did a regen. Then the dim looked as expected.
  • Next, I double clicked on the dim to get into the editor. And lo and behold, the text width was back to what it was before I ran the code.

This seems to tell me that Autocad stores the text width info in some field associated with dim entity. The big question is where?

 

Does anyone know where the text width info is stored? (I am using Autocad 2023)

 

Sincerely;

Michelle

 

0 Likes