Тема: Пример создания табличного стиля
Может кому пригодится.
Предложения по улучшению кода приветствуются.
Option Explicit
Private Function MakeTableStyleForSpec() As String
Dim objTableStyle As AcadTableStyle
Dim objTextStyle As AcadTextStyle
Dim objDictTableStyle As AcadDictionary
Dim strTableStyleName As String
Dim strTextStyleName As String
Set objDictTableStyle = ThisDrawing.Dictionaries.Item("ACAD_TABLESTYLE")
strTableStyleName = "Spec"
On Error Resume Next
Set objTableStyle = objDictTableStyle.AddObject(strTableStyleName, "AcDbTableStyle")
strTextStyleName = "Spec"
Set objTextStyle = ThisDrawing.TextStyles.Add(strTextStyleName)
On Error GoTo 0
objTextStyle.SetFont "Arial", False, False, 0, 34
objTableStyle.SetTextStyle AcRowType.acDataRow + AcRowType.acHeaderRow _
+ AcRowType.acTitleRow + AcRowType.acUnknownRow, strTextStyleName
objTableStyle.SetTextHeight AcRowType.acDataRow + AcRowType.acUnknownRow, 2.5
objTableStyle.SetTextHeight AcRowType.acHeaderRow + AcRowType.acTitleRow, 3
objTableStyle.SetAlignment AcRowType.acHeaderRow + AcRowType.acTitleRow, acMiddleCenter
objTableStyle.SetAlignment AcRowType.acDataRow + AcRowType.acUnknownRow, acMiddleLeft
objTableStyle.HorzCellMargin = 1.5
objTableStyle.VertCellMargin = 1
objTableStyle.SetGridLineWeight AcGridLineType.acHorzBottom + AcGridLineType.acHorzInside + AcGridLineType.acHorzTop _
+ AcGridLineType.acVertInside + AcGridLineType.acVertLeft + AcGridLineType.acVertRight, _
AcRowType.acTitleRow + AcRowType.acHeaderRow, AcLineWeight.acLnWt050
objTableStyle.SetGridLineWeight AcGridLineType.acHorzBottom + AcGridLineType.acHorzTop + _
AcGridLineType.acVertInside + AcGridLineType.acVertLeft + AcGridLineType.acVertRight, _
AcRowType.acDataRow + AcRowType.acUnknownRow, AcLineWeight.acLnWt050
objTableStyle.SetGridLineWeight AcGridLineType.acHorzInside, _
AcRowType.acDataRow + AcRowType.acUnknownRow, AcLineWeight.acLnWt025
Dim color As New AcadAcCmColor
color.SetRGB 255, 0, 0
objTableStyle.SetColor AcRowType.acDataRow + AcRowType.acHeaderRow _
+ AcRowType.acTitleRow + AcRowType.acUnknownRow, color
MakeTableStyleForSpec = strTableStyleName
End Function
Public Sub TestTableStyle()
Dim objTable As AcadTable
Dim varPt As Variant
Dim i As Integer
varPt = ThisDrawing.Utility.GetPoint
Set objTable = ThisDrawing.ModelSpace.AddTable(varPt, 2, 5, 8, 10)
objTable.RegenerateTableSuppressed = True
objTable.SetText 0, 0, "Specification"
objTable.SetText 1, 0, "Poz"
objTable.SetColumnWidth 0, 15
objTable.SetText 1, 1, "Oboznachenie"
objTable.SetColumnWidth 1, 70
objTable.SetText 1, 2, "Naimenovanie"
objTable.SetColumnWidth 2, 70
objTable.SetText 1, 3, "Kol"
objTable.SetColumnWidth 3, 15
objTable.SetText 1, 4, "Massa"
objTable.SetColumnWidth 4, 20
For i = 2 To 101
objTable.InsertRows i, 8, 1
objTable.SetText i, 0, i
objTable.SetText i, 1, "Obozn" & i
objTable.SetText i, 2, "Naimen" & i
objTable.SetText i, 3, i
objTable.SetText i, 4, i
Next
objTable.RegenerateTableSuppressed = False
objTable.StyleName = MakeTableStyleForSpec
End Sub
Комментарии все удалил, т.к. вставляется абра-кадабра) ((((
Может завтра с работы получится вставить с коментами.