Author Topic: How to place leader text in two lines  (Read 1548 times)

0 Members and 1 Guest are viewing this topic.

gvgbabu

  • Guest
How to place leader text in two lines
« on: April 30, 2014, 10:29:06 PM »
hi
I have 2 questions to know regarding dim leaders. Please guide me. how to do it

i)Is there any way to place leader text in two lines ie above and below the leader line in vb.net.
for example:

I have a  leader text 2-#12(st)+2-#16(ext)
I want to place 2-#12(st) on above the  line and +2-#16(ext) on below the leader line.
which property of the leader controls this type text arrangement.

ii) How to combine two leaders with one Mtext. is it possible using vb.net. if yes, please explain how to do it.


thanks
gvg
« Last Edit: April 30, 2014, 10:32:38 PM by gvgbabu »

fixo

  • Guest
Re: How to place leader text in two lines
« Reply #1 on: May 01, 2014, 08:15:06 AM »
 
Quote
1. Is there any way to place leader text in two lines ie above and below the leader line in vb.net.

Here is an aswer on your first question, just a quick shot though,
other than that you must to continue by yourself     
Code - vb.net: [Select]
  1.       <CommandMethod("mn", CommandFlags.UsePickSet)> _
  2.         Public Sub TestMleaderNET()
  3.  
  4.             Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
  5.  
  6.             Dim db As Database = doc.Database
  7.  
  8.             Dim ed As Editor = doc.Editor
  9.  
  10.             Dim dem As String = "+"
  11.  
  12.             Dim txtId As ObjectId = ObjectId.Null
  13.  
  14.             Dim mtx As MText
  15.  
  16.             Dim mlines As New List(Of String)()
  17.  
  18.             Dim opts As New PromptEntityOptions(vbLf & "Select a leader or mleader")
  19.  
  20.             opts.SetRejectMessage(vbLf & "Select leader or mleader only!")
  21.  
  22.             opts.AddAllowedClass(GetType(Autodesk.AutoCAD.DatabaseServices.Leader), False)
  23.  
  24.             opts.AddAllowedClass(GetType(Autodesk.AutoCAD.DatabaseServices.MLeader), False)
  25.  
  26.             Dim res As PromptEntityResult = ed.GetEntity(opts)
  27.  
  28.             If res.Status <> PromptStatus.OK Then
  29.  
  30.                 Return
  31.             End If
  32.             Try
  33.  
  34.                 Using tr As Transaction = db.TransactionManager.StartTransaction()
  35.                     Dim ent As Entity = TryCast(tr.GetObject(res.ObjectId, OpenMode.ForRead), Entity)
  36.  
  37.                     Dim lead As Leader = TryCast(ent, Leader)
  38.  
  39.                     If lead IsNot Nothing Then
  40.                         If lead.AnnoType = AnnotationType.MText Then
  41.                             txtId = lead.Annotation
  42.                             mtx = TryCast(DirectCast(tr.GetObject(txtId, OpenMode.ForRead), MText), MText)
  43.                             Dim cont As String = mtx.Text
  44.                             ' check if the string contains a desired delimiter (eg "+")
  45.                             If Not cont.Contains(dem) Then
  46.                                 Return
  47.                             End If
  48.                             mlines = New List(Of String)()
  49.                             mlines = cont.Split("+"c).ToList()
  50.  
  51.                             Dim sb As New StringBuilder()
  52.                             For Each st As String In mlines
  53.                                 sb.AppendLine(st)
  54.                             Next
  55.  
  56.                             mtx.UpgradeOpen()
  57.                             lead.UpgradeOpen()
  58.  
  59.                             ' new text string
  60.                             ' use other settings to place text below, see properties in the Intellisence drop down box
  61.                             mtx.Contents = sb.ToString()
  62.                         End If
  63.                     End If
  64.                     Dim mlead As MLeader = TryCast(ent, MLeader)
  65.  
  66.                     If mlead IsNot Nothing Then
  67.                         If mlead.ContentType = ContentType.MTextContent Then
  68.                             mtx = New MText()
  69.                             mtx = DirectCast(mlead.MText, MText)
  70.                             Dim cont As String = mtx.Contents
  71.                             ' check if the string contains a desired delimiter (eg "+")
  72.                             If Not cont.Contains(dem) Then
  73.                                 Return
  74.                             End If
  75.                             mlines = New List(Of String)()
  76.                             mlines = cont.Split("+"c).ToList()
  77.  
  78.                             Dim sb As New StringBuilder()
  79.                             For Each st As String In mlines
  80.                                 sb.AppendLine(st)
  81.                             Next
  82.  
  83.  
  84.                             mlead.UpgradeOpen()
  85.                             mtx.Contents = sb.ToString()
  86.                             ' new text string                    
  87.                             ' use other settings to place text below, see properties in the Intellisence drop down box
  88.  
  89.                             mlead.MText = mtx
  90.                         End If
  91.                     End If
  92.  
  93.                     tr.Commit()
  94.                 End Using
  95.             Catch ex As System.Exception
  96.                 Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message)
  97.                 'empty field
  98.             Finally
  99.             End Try
  100.         End Sub

edit:kdub ->formatting code=vbnet
« Last Edit: May 01, 2014, 09:37:39 AM by Kerry »

gvgbabu

  • Guest
Re: How to place leader text in two lines
« Reply #2 on: May 14, 2014, 10:15:41 PM »
fixo,
thank you very much for your reply.
its been so long after your reply.
i am trying to do it.
i did not understand what you mentioned in your post for placing the text below the leader line. please clarify.
use other settings to place text below, see properties in the Intellisence drop down box

thanks
gvg