Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm working on a Simple program to change all text in a dwg file to a diferent text style based on the current scale of model Space. The text style comes with the prefix "TfL_m1-" and then the scale number. The program does work but it only change the style name, and I need to change also its properties.
The code is as following:
<CommandMethod("ChangeTextStyle")>
Public Sub SetTextStyle()
Dim TextDic As New Dictionary(Of String, TextStyleTableRecord)
Using tr As Transaction = m_Database.TransactionManager.StartTransaction()
'' Get the current Annotation Scale on the drawing
Dim scale As String = m_Database.Cannoscale.Name
Dim subscale As String = scale.Substring(scale.IndexOf(":") + 1, scale.IndexOf("(") - scale.IndexOf(":") - 1)
'' Create a dictionary with the text styles and names
Dim acTextStyleTable As TextStyleTable = tr.GetObject(m_Database.TextStyleTableId, OpenMode.ForRead)
ed.WriteMessage("la escala actual del modelSpace es:" + scale + vbCrLf)
ed.WriteMessage("el valor que nos atañe es: " + subscale + vbCrLf)
For Each id As ObjectId In acTextStyleTable
Dim Symbol As TextStyleTableRecord = tr.GetObject(id, OpenMode.ForRead)
TextDic.Add(Symbol.Name, Symbol)
'ed.WriteMessage("estilo de texto: " + Symbol.Name + vbCrLf)
Next
Dim keys As Dictionary(Of String, TextStyleTableRecord).KeyCollection = TextDic.Keys
Dim stri As String = "TfL_m1-" + subscale
ed.WriteMessage("el valor clave del diccionario sería: " + stri + " cuya longitud es: " + Str(stri.Length) + vbCrLf)
ed.WriteMessage("La escala a aplicar en este dibujo seria: {0} con un valor de id : {1}", stri, TextDic(stri).ToString + vbCrLf)
'Search for all text object in the current model space
Dim model = DirectCast(tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(m_Database), OpenMode.ForWrite), BlockTableRecord)
For Each obj As ObjectId In model
Select Case obj.ObjectClass.DxfName
Case "TEXT"
ed.WriteMessage("Hola")
Dim tx As DBText = tr.GetObject(obj, OpenMode.ForWrite)
tx.TextStyleId = TextDic(stri).ObjectId
Case "MTEXT"
ed.WriteMessage("Hola")
Dim tx As MText = tr.GetObject(obj, OpenMode.ForWrite)
tx.TextStyleId = TextDic(stri).ObjectId
Case Else
ed.WriteMessage("Not he encontrado ninguna entidad Decimal este tipo")
Exit Select
End Select
Next
tr.Commit()
ed.Regen()
End Using
End SubI would be very gratefull if someone could explain me where i am wrong.
regards,
Carlos.
Solved! Go to Solution.