来一个VBA AI写的"新建文字样式"
- Public Sub CreateNewTextStyle()
- Dim acadApp As Object
- Dim acadDoc As Object
- Dim acadTextStyles As Object
- Dim newTextStyleName As String
-
- ' 连接到AutoCAD应用程序和文档
- On Error Resume Next
- Set acadApp = GetObject(, "AutoCAD.Application")
- If Err Then
- MsgBox "AutoCAD程序未运行"
- Exit Sub
- End If
- On Error GoTo 0
- Set acadDoc = acadApp.ActiveDocument
-
- ' 新文字样式的名称
- newTextStyleName = "MyNewTextStyle"
-
- ' 获取文字样式表
- Set acadTextStyles = acadDoc.TextStyleTable
-
- ' 检查样式是否已存在
- If Not acadTextStyles.Has(newTextStyleName) Then
- ' 创建新的文字样式
- With acadTextStyles.Add(newTextStyleName)
- ' 设置文字样式的属性
- .Font = "Arial"
- .BigFont = "Arial Bold"
- .Height = 4.2
- .Italic = acadFalse
- .Bold = acadFalse
- .CharSet = 1
- .IsLineType = acadFalse
- .IsVertical = acadFalse
- .IsBackward = acadFalse
- .IsReverse = acadFalse
- .IsSuperscript = acadFalse
- .IsSubscript = acadFalse
- .IsUnderline = acadFalse
- .IsStrikeOut = acadFalse
- .Rotation = 0
- .WidthFactor = 1
- .ObliquingAngle = 0
- .TrackingFactor = 1
- End With
- MsgBox "文字样式创建成功: " & newTextStyleName
- Else
- MsgBox "文字样式已存在: " & newTextStyleName
- End If
- End Sub
|