Hello, do not speak English
Public Sub Tb_CrtStl()
Dim nombre As String = GetString("Nombre del estilo:")
Dim mrgVrt As Double = GetDouble("Margen celda Vertical.")
Dim mrgHrz As Double = GetDouble("Margen celda Horizontal:")
Dim alTxTl As Double = GetDouble("Altura del texto del titulo.")
Dim alTxCab As Double = GetDouble("Altura del texto de las cabeceras.")
Dim alTxDt As Double = GetDouble("Altura del texto de los datos.")
Try
Dim styleName As String = nombre
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using tr As Transaction = doc.TransactionManager.StartTransaction()
Dim tsId As ObjectId = ObjectId.Null
Dim sd As DBDictionary = DirectCast(tr.GetObject(db.TableStyleDictionaryId, _
OpenMode.ForRead), DBDictionary)
' Comprobar si existe
If sd.Contains(styleName) Then
Application.SetSystemVariable("CTABLESTYLE", nombre)
Return
Else
' si no existe lo crea
Dim ts As New TableStyle()
ts.VerticalCellMargin = mrgVrt
ts.HorizontalCellMargin = mrgHrz
ts.SetTextHeight(alTxCab, RowType.HeaderRow)
ts.SetTextHeight(alTxTl, RowType.TitleRow)
ts.SetTextHeight(alTxDt, RowType.DataRow)
ts.SetAlignment(CellAlignment.MiddleCenter, RowType.TitleRow)
ts.SetAlignment(CellAlignment.MiddleCenter, RowType.DataRow)
ts.SetAlignment(CellAlignment.MiddleCenter, RowType.HeaderRow)
sd.UpgradeOpen()
tsId = sd.SetAt(styleName, ts)
tr.AddNewlyCreatedDBObject(ts, True)
sd.DowngradeOpen()
tr.Commit()
End If
End Using
Application.SetSystemVariable("CTABLESTYLE", nombre)
Return
Catch ex As Exception
Return
End Try
End Sub