Mtext to MLeader?

Mtext to MLeader?

john.uhden
Mentor Mentor
1,155 Views
19 Replies
Message 1 of 20

Mtext to MLeader?

john.uhden
Mentor
Mentor

I was building my own today, but there's probably already one out there.

But the exercise is good because I'm learning how to transfer common object properties from one object to the next;  no dxf substs or entmods required.

John F. Uhden

0 Likes
1,156 Views
19 Replies
Replies (19)
Message 2 of 20

ronjonp
Mentor
Mentor
0 Likes
Message 3 of 20

john.uhden
Mentor
Mentor

Thanks, but I don't think I belong to TheSwamp.

I'm having fun anyway.

John F. Uhden

0 Likes
Message 4 of 20

ronjonp
Mentor
Mentor

@john.uhden wrote:

Thanks, but I don't think I belong to TheSwamp.

I'm having fun anyway.


Everyone belongs at TheSwamp 🙂 .. attached is the code I referenced.

0 Likes
Message 5 of 20

dbroad
Mentor
Mentor

John,

My actual code is more complex and translates existing polyline leaders into points and does other things but this is the basic framework, using an example set of points in a fashion that doesn't require safearrays.  There is good sample code on the AutoCAD ActiveX reference site, reachable by using help from vlide.

(setq tob (vlax-ename->vla-object (car (entsel))) ;assumes eligible text/mtext object picked
      spc (vla-objectidtoobject		;spc can be any layout block, not just modelspace
	    (vla-get-document tob)
	    (vla-get-ownerid tob)
	    )
      )
(vla-startundomark (vla-get-document tob))
(setq mlo (vlax-invoke spc 'addmleader '(0.0 0.0 0.0 12.0 12.0 0.0) 0)) ;example 3d flat list
(vla-put-textstring mlo (vla-get-textstring tob))
(vla-put-stylename mlo "YourMleaderStyle") ;Assumes style exists, otherwise requires more Prep.
(vla-put-layer mlo (vla-get-layer tob))
;....
(vla-delete tob);clean up after transferring properties
(vla-endundomark (vla-get-document mlo))

 

I didn't include point list creation, vl-catch-all-apply code, or localize variables but you get the idea. 

Use vla-addleaderlineex to add leader lines to existing mleaders.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 6 of 20

john.uhden
Mentor
Mentor
Hi, @Anonymous,
I was having fun attempting to slam the new MLEADER object with all the
applicable (translated) properties from the original MTEXT object.
Everything was great except for dealing with annotation scales. I'll play
with it more once I digest your contribution.
Oh, there are two properties I'm not sure about...
MLEADER "TextDirection" is MTEXT what? _______________
MLEADER "TextJustify" is MTEXT what? _______________

John F. Uhden

0 Likes
Message 7 of 20

dbroad
Mentor
Mentor

TextJustify:  Where the leader is attached by default. It would be reasonable to defer to the mleader style setting.  Those will be overwritten though if the leader points location conflict with the textjustify IMO.

TextDirection: I'd leave it set to acByStyle.  It's not as if you can change it to just anything.  acLeftToRight generally won't error out. Could be language related.  For English speakers we usually read left to right and top to bottom.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 8 of 20

john.uhden
Mentor
Mentor
Why thank you again @Anonymous.
Right now I'm not trying to transfer those properties and most things work
fine except for the text height due to annotation scale, so I will leave
those two out of the conversion.

BTW, since apparently can't depend on LTSCALE or DIMSCALE these days, does
this make sense to you?...
(setq scale (apply '/ (reverse (mapcar 'read (@str2list (getvar
"cannoscale") "=")))))

It turns "1\" = 20" into 20

@str2list is my version of separating out pieces of a string based on a
delimiter. There are probably hundreds of professional and homemade
versions out there all by different names.

John F. Uhden

0 Likes
Message 9 of 20

ronjonp
Mentor
Mentor

If you want some help with this, post a sample drawing and the code you have started. I've messed with this in the past and it's a bit of a rabbit hole task from my experience.

0 Likes
Message 10 of 20

john.uhden
Mentor
Mentor
Thanks, Ron.
Do you mean help with the CANNOSCALE?
My biggest problem with that is interpreting whether annotation governs.
Around here, using C3D, we hit the little scale button on the bottom of the
screen all the time to temporarily make Cogo points smaller or larger.
It's not as though we decide on a scale and never change it. But I guess I
should be smart enough to glean from the MTEXT what scale and height I
should be using. I had naively thought that transferring all the common
properties from the MTEXT to the MLEADER would create a perfect clone.
Maybe there are one or more MLEADER properties that are needed that aren't
getting transferred.
BTW, when I say "common" I know they don't use exactly the same name so I
included a translate function.
Time to go home. Maybe I'll post something tomorrow.

John F. Uhden

0 Likes
Message 11 of 20

dbroad
Mentor
Mentor

Sounds like a waste of coding.  You don't need to do anything as long as the multileader style you want is marked annotative.  Transfer the string, delete the mtext and change the style.  All the other settings such as text height are handled by the mleaderstyle settings and the current annotation scale.

BTW, if you need annotation scaling calculations for some reason, use cannoscalevalue. For example, 3/4"=1'-0" cannoscale is also 0.0625 cannoscalevalue. (1/16).  If anything, you might want to set the textwidth to match the previous mtext.  I generally just select and set the width manually after conversion.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 12 of 20

Sea-Haven
Mentor
Mentor

Hi John is it something that a CIV3D style will do ? They are a pain to make but very usefull once created.

 

I sent you a PM did you get it stuff for CIV3d.

0 Likes
Message 13 of 20

john.uhden
Mentor
Mentor

Hmm, not that we ever work in architectural mode, but your fractional scale intrigued me, so...

(defun @distof (str)(distof str 4))
(setq scale (apply '/ (reverse (mapcar '@distof (@str2list (getvar "cannoscale") "=")))))

John F. Uhden

0 Likes
Message 14 of 20

dbroad
Mentor
Mentor

Again, waste of effort and abstruse. Try:

(setq scale (/ 1 (getvar "cannoscalevalue")))

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 15 of 20

john.uhden
Mentor
Mentor
@Anonymous
I love learning and you're a good teacher.

John F. Uhden

0 Likes
Message 16 of 20

john.uhden
Mentor
Mentor

@ronjonp 

Attached is a sample DWG and my code under construction.  It probably has more in it then it needs and I have yet to duplicate the existing mtext leader if it exists, but at least I know how to find it if one is attached (and probably more than one).  At least I was able to use it today.

John F. Uhden

0 Likes
Message 17 of 20

ronjonp
Mentor
Mentor

@john.uhden  That code 'c:mt2ml' does not do anything in AutoCAD 2021.

0 Likes
Message 18 of 20

john.uhden
Mentor
Mentor
Oh, crap. That's because it calls functions in my Uhden.lsp. I'll have to
copy'n'paste them in to make it nondependent. Not right now, though, I'm
actually working.

John F. Uhden

0 Likes
Message 19 of 20

john.uhden
Mentor
Mentor

@ronjonp 

I cleaned up the lisp file (attached).

John F. Uhden

0 Likes
Message 20 of 20

ronjonp
Mentor
Mentor

I'll take a look next week. Enjoy your weekend! 🍻

0 Likes