Option Explicit Dim acadApp As AutoCAD.AcadApplication Dim AcadDoc As AcadDocument '标注文字 Dim Styleobj As AcadTextStyle '汉字字体集合 Set AcadDoc = acadApp.ActiveDocument acadApp.Visible = acTrue Set Styleobj = AcadDoc.TextStyles.Add("黑体") Styleobj.fontFile = "c:\windows\fonts\simhei.ttf" Set Styleobj = AcadDoc.TextStyles.Add("仿宋") Styleobj.fontFile = "c:\windows\fonts\simfang.ttf" Set Styleobj = AcadDoc.TextStyles.Add("楷体") Styleobj.fontFile = "c:\windows\fonts\simkai.ttf" AcadDoc.ActiveTextStyle = AcadDoc.TextStyles.Add("仿宋") Dim addtext As AcadText Dim textpoint As Variant Dim textstring As String textpoint = returnpnt 'textpoint(1) = textpoint(1) + 0.5 Set addtext = AcadDoc.ModelSpace.addtext("你要写入到CAD的文字" , textpoint, 0.3) Set layerobj = acadApp.ActiveDocument.Layers.Add("dotdesign") '创建一个层为DOTDESIGN layerobj.color = acGreen '将创建的层指定为绿色 addtext.Update '指定对象到图层 Private Sub Form_Load() On Error Resume Next Set acadApp = GetObject(, "AutoCAD.Application") If Err Then Err.Clear Set acadApp = CreateObject("AutoCAD.Application") If Err Then End MsgBox ("你的系统未安装AutoCAD2004,请安装它才能使用本程序") Unload Me Exit Sub End If acadApp.WindowState = acMax acadApp.Visible = True Set AcadDoc = acadApp.ActiveDocument End Sub |