Author Topic: Exploding multileaders but preserving the leaders?  (Read 19548 times)

0 Members and 1 Guest are viewing this topic.

yarnstormer

  • Guest
Exploding multileaders but preserving the leaders?
« on: August 22, 2013, 09:16:18 AM »
Ok I know it's a bad bad idea to explode multileaders but I am giving my civil 3d dwgs to a microstation user for conversion and he has asked that I explode them. He has also asked that I pedit the leaders back into polylines - which turn into separate entities when you explode the multileaders. He is ok with the resulting multiline text from exploding the multileaders.

Any ideas? I am not a programmer at all.

I know I can do my own dgn conversion but we are providing these files to the dot and would prefer that they are clean and tested and there are no problems. It's just easier to have this fellow do the conversion.

I just got my boss sold on using multileaders so I need a cool fix for this! I do of course copy my drawing to another name before I do the massive cleanup necessary before I send it out to be converted.

Thanks for any suggestions you might have!

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Exploding multileaders but preserving the leaders?
« Reply #1 on: August 22, 2013, 09:18:00 AM »
Are the resulting MLeader components all on the same layer?

If so, isolate the layer, then:

PEDIT > M > Select all Exploded MLeaders > J > Enter > Enter
« Last Edit: August 22, 2013, 09:22:51 AM by Lee Mac »

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Exploding multileaders but preserving the leaders?
« Reply #2 on: August 22, 2013, 09:35:21 AM »
Try exporting to DGN and send him a test file to see if it's up to par with what he wants.  That may save you a ton of time.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Exploding multileaders but preserving the leaders?
« Reply #3 on: August 22, 2013, 10:00:32 AM »
Kinda off topic here .. but has anyone found a way to access the mtext object within an mleader without exploding?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Exploding multileaders but preserving the leaders?
« Reply #4 on: August 22, 2013, 10:33:43 AM »
Kinda off topic here .. but has anyone found a way to access the mtext object within an mleader without exploding?

As far as I know, the MText content of an MLeader is not stored as a separate MText entity, but rather defined by the various DXF groups enclosed within the (300 . "CONTEXT_DATA{") section of the MLeader DXF data. I would assume that the MText entity is automatically generated using this data when the EXPLODE command is used.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Exploding multileaders but preserving the leaders?
« Reply #5 on: August 22, 2013, 11:15:08 AM »
Cool ... thanks Lee.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

yarnstormer

  • Guest
Re: Exploding multileaders but preserving the leaders?
« Reply #6 on: August 22, 2013, 11:18:16 AM »
Are the resulting MLeader components all on the same layer?

If so, isolate the layer, then:

PEDIT > M > Select all Exploded MLeaders > J > Enter > Enter

ok that helps - a little buggy but it got it done with a little doctoring up after.
Where there are multiple leaders it get a little confused.
I don't export dgns. We are paying this guy to "make" our dgns that we will then send to the dot...I know I know...I just does what I'm told.

BlackBox

  • King Gator
  • Posts: 3770
Re: Exploding multileaders but preserving the leaders?
« Reply #7 on: August 22, 2013, 01:25:03 PM »
Kinda off topic here .. but has anyone found a way to access the mtext object within an mleader without exploding?

Kinda off topic here .. but has anyone found a way to access the mtext object within an mleader without exploding?

As far as I know, the MText content of an MLeader is not stored as a separate MText entity, but rather defined by the various DXF groups enclosed within the (300 . "CONTEXT_DATA{") section of the MLeader DXF data. I would assume that the MText entity is automatically generated using this data when the EXPLODE command is used.

FWIW -

Stemming from my work on this... There is actually a separate MText Property Object within an MLeader Typed entity (given ContentType == ContentType.MTextContent enum), it just has not been exposed to LISP... Which is where my appreciation for an MLeader's TextString Property stems from, as the code-behind this Property handles the necessary Transaction to access, and get/set the MText Object's TextString Property, without any additional end-user code... Just as compared to the same in .NET API get/set the string... It's really quite elegant.

Here's a small snippet from the linked project (which accepts DBText, MLeader, MText, etc., hence the switch case):

Code - C#: [Select]
  1. // <snip>
  2.  
  3.             try
  4.             {
  5.                 using (DocumentLock docLock = doc.LockDocument())
  6.                 {
  7.                     using (Transaction tr =
  8.                         db.TransactionManager.StartOpenCloseTransaction())
  9.                     {
  10.  
  11.                         foreach (ObjectId id in ids)
  12.                         {
  13.                             switch (id.ObjectClass.Name)
  14.                             {
  15.                                 case "AcDbMLeader":
  16.                                     mleader =
  17.                                         (MLeader)tr.GetObject(id, OpenMode.ForWrite);
  18.  
  19.                                     ContentType contentType = mleader.ContentType;
  20.  
  21.                                     if (contentType == ContentType.MTextContent)
  22.                                     {
  23.                                         mtext = mleader.MText;
  24.  
  25.                                         // use the texteditor where possible
  26.                                         if (strCase.Equals((int)StringCase.Lower) |
  27.                                                 strCase.Equals((int)StringCase.Upper)
  28.                                             )
  29.                                             ChangeCaseUsingTextEditor(mtext, strCase);
  30.  
  31.                                         // texteditor does not support sentence, title, or toggle
  32.                                         else
  33.                                             mtext.Contents = mtext.Contents.ToCase(strCase);
  34.                                        
  35.                                         mleader.MText = mtext;
  36.                                     }
  37.  
  38.                                     //// nested block attributes:
  39.                                     //else if (contentType == ContentType.BlockContent)
  40.                                     //{
  41.                                     //}
  42.  
  43.                                     break;
  44.  
  45.                                 case "AcDbMText":
  46.                                     mtext =
  47.                                         (MText)tr.GetObject(id, OpenMode.ForWrite);
  48.  
  49.                                     // use the texteditor where possible
  50.                                     if (strCase.Equals((int)StringCase.Lower) |
  51.                                             strCase.Equals((int)StringCase.Upper)
  52.                                         )
  53.                                         ChangeCaseUsingTextEditor(mtext, strCase);
  54.  
  55.                                     // texteditor does not support sentence, title, or toggle
  56.                                     else
  57.                                         mtext.Contents = mtext.Contents.ToCase(strCase);
  58.  
  59.                                     break;
  60.  
  61.                                 case "AcDbText":
  62.                                     text =
  63.                                         (DBText)tr.GetObject(id, OpenMode.ForWrite);
  64.  
  65.                                     text.TextString = text.TextString.ToCase(strCase);
  66.  
  67.                                     break;
  68.  
  69.                                 default:
  70.                                     break;
  71.                             }
  72.  
  73.                         }
  74.  
  75.                         tr.Commit();
  76.                     }
  77.                 }
  78.             }
  79.             catch
  80.             {
  81.             }
  82.  
  83. // <snip>
  84.  

For those who may be interested... The System.String Extension Methods used above can be found here.

Cheers



/OffTopic
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Exploding multileaders but preserving the leaders?
« Reply #8 on: August 22, 2013, 01:29:27 PM »
Are the resulting MLeader components all on the same layer?

If so, isolate the layer, then:

PEDIT > M > Select all Exploded MLeaders > J > Enter > Enter

ok that helps - a little buggy but it got it done with a little doctoring up after.
Where there are multiple leaders it get a little confused.
I don't export dgns. We are paying this guy to "make" our dgns that we will then send to the dot...I know I know...I just does what I'm told.

I think it's silly that exploding an MLeader (with Mtext content) results in an MText entity, and exploded Leader(s), frankly.

You might consider looking into an MLeader's GetLeaderLineVertices Method, to essentially recreate an actual Leader entity, rather than just joining the resultant linework, etc.

HTH
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Exploding multileaders but preserving the leaders?
« Reply #9 on: August 22, 2013, 01:51:02 PM »
Are the resulting MLeader components all on the same layer?

If so, isolate the layer, then:

PEDIT > M > Select all Exploded MLeaders > J > Enter > Enter

ok that helps - a little buggy but it got it done with a little doctoring up after.
Where there are multiple leaders it get a little confused.
I don't export dgns. We are paying this guy to "make" our dgns that we will then send to the dot...I know I know...I just does what I'm told.

I think it's silly that exploding an MLeader (with Mtext content) results in an MText entity, and exploded Leader(s), frankly.

You might consider looking into an MLeader's GetLeaderLineVertices Method, to essentially recreate an actual Leader entity, rather than just joining the resultant linework, etc.

HTH

Here's a quickly written sub-function, to extract the vertices for each of the two possible Leader indices (0 == All Leaders on Left, 1 == All Leaders on Right), and returns a list of pairs, where ((<LeaderLineIndex> <LeaderLineVertices>)):

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun bbox:GetLeaderLineVertices (mleader / indexes vertices)
  3.   ;; Example:
  4.   ;;    (bbox:GetLeaderLineVertices mleader)
  5.   ;;
  6.   ;; Return:
  7.   ;;    ((<LeaderLineIndex> <LeaderLineVertices>))
  8.   (foreach i '(0 1)
  9.     (if (setq indexes (vlax-invoke mleader 'getleaderlineindexes i))
  10.       (foreach index indexes
  11.         (setq vertices
  12.                (cons
  13.                  (cons
  14.                    index
  15.                    (vlax-invoke
  16.                      mleader
  17.                      'getleaderlinevertices
  18.                      index
  19.                    )
  20.                  )
  21.                  vertices
  22.                )
  23.         )
  24.       )
  25.     )
  26.   )
  27.   (reverse vertices)
  28. )
  29.  

... You should be able to use this to iterate a selection of one or more MLeaders, extract their respective LeaderLineVertices, create a Leader object for each, and/or explode the MLeader (being sure to catch and delete all resultant Line, and Solid entities), or simply create a new MText entity in the same placement and delete the MLeader itself.

Again, HTH
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Exploding multileaders but preserving the leaders?
« Reply #10 on: August 22, 2013, 04:57:28 PM »
Ok I know it's a bad bad idea to explode multileaders but I am giving my civil 3d dwgs to a microstation user for conversion and he has asked that I explode them. He has also asked that I pedit the leaders back into polylines - which turn into separate entities when you explode the multileaders. He is ok with the resulting multiline text from exploding the multileaders.

Here's a brute force routine which combines what you're already doing (exploding the MLeaders), with Lee's original advice to use PEDIT:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:FOO (/ ss e ss2)
  2.  
  3.   (if (setq ss (ssget "_:L" '((0 . "MULTILEADER"))))
  4.     (progn
  5.       (command "._undo" "begin")
  6.       (setq e (entlast))
  7.       (command "._explode" ss)
  8.       (setq ss2 (ssadd))
  9.       (while (and (setq e (entnext e))
  10.                   (= "LINE" (cdr (assoc 0 (entget e))))
  11.              )
  12.         (setq ss2 (ssadd e ss2))
  13.       )
  14.       (command "._pedit" "multiple" ss2 "" "join" 0.0 "")
  15.       (command "._undo" "end")
  16.     )
  17.   )
  18.   (princ)
  19. )
  20.  



Inspired by this thread, I've also refined my earlier sub-function to return LeaderLine pairs, where the second element is a list of individual point lists, rather than the single list of coordinates. I have also started but have not yet finished a routine to effectively 'Burst Mleaders' into MText & (associated) Leader(s), but will post when done.

Cheers
« Last Edit: August 22, 2013, 05:27:42 PM by BlackBox »
"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Exploding multileaders but preserving the leaders?
« Reply #11 on: August 22, 2013, 05:23:30 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:FOO (/ ss e ss2)
  2.  
  3.   (if (setq ss (ssget "_:L" '((0 . "MULTILEADER"))))
  4.     (progn
  5.       (command "._undo" "begin")
  6.       (setq e (entlast))
  7.       (command "._explode" ss)
  8.       (setq ss2 (ssadd))
  9.       (while (setq e (entnext e)) (setq ss2 (ssadd e ss2)))
  10.       (command "._pedit" "multiple" ss2 "" "join" 0.0 "")
  11.       (command "._undo" "end")
  12.     )
  13.   )
  14.   (princ)
  15. )
  16.  

Be careful when (entlast) is an attributed block or 2D/3D polyline.

BlackBox

  • King Gator
  • Posts: 3770
Re: Exploding multileaders but preserving the leaders?
« Reply #12 on: August 22, 2013, 05:25:54 PM »

Be careful when (entlast) is an attributed block or 2D/3D polyline.

Good catch; been a while since I did brute force Command calls.

... It (the code) should filter for "LINE" in this case. Code revised.

Cheers, mate.
"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Exploding multileaders but preserving the leaders?
« Reply #13 on: August 22, 2013, 05:42:45 PM »

Be careful when (entlast) is an attributed block or 2D/3D polyline.

Good catch; been a while since I did brute force Command calls.

... It (the code) should filter for "LINE" in this case. Code revised.

Cheers, mate.

Cheers - though, not so fast - what if the first entity added to the database following the explode is not a LINE...

BlackBox

  • King Gator
  • Posts: 3770
Re: Exploding multileaders but preserving the leaders?
« Reply #14 on: August 22, 2013, 07:46:10 PM »

Be careful when (entlast) is an attributed block or 2D/3D polyline.

Good catch; been a while since I did brute force Command calls.

... It (the code) should filter for "LINE" in this case. Code revised.

Cheers, mate.

Cheers - though, not so fast - what if the first entity added to the database following the explode is not a LINE...

In addition to that, has anyone tried using (command "._explode" ss) on a selection set of multiple MLeaders, where at least one has BlockContent (instead of MText)?

Not sure if it's something here with my ADN license, but MText ContentTypes are exploding, and Block is/are not... Curious too that there is no Explode Method available (which would make identifying only what entities have been added really simple).
"How we think determines what we do, and what we do determines what we get."