各位高手,本人使用2006版AutoCAD,在使用VBA定义新的AutoCAD图层时,使用TrueColor方法设置颜色,当只启动一个CAD时,颜色设置没有问题,但是当通过程序启动CAD之前,已经有一个AutoCAD打开了,则图层颜色不能设置,提示“对象 'TrueColor' 方法的 'IAcadLayre2' 失败”错误。 程序代码如下, Dim locLineLayer As AcadLayer Dim layColor As AcadAcCmColor Dim intPos1 As Integer Dim layerNames As String Dim entryLayer As AcadLayer layerNames = "" For Each entryLayer In DocHuawen1.Layers layerNames = layerNames + entryLayer.Name + vbCrLf Next intPos1 = InStr(1, layerNames, "locLineLayer", vbTextCompare) If intPos1 = 0 Then '如果不存在locLineLayer图层,则创建图层 Set locLineLayer = DocHuawen1.Layers.Add("locLineLayer") '添加locLineLayer图层 DocHuawen1.ActiveLayer = locLineLayer locLineLayer.Linetype = "Continuous" '设置 Set layColor = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.16") Call layColor.SetRGB(0, 255, 255) '设置标注颜色为 青色 locLineLayer.TrueColor = layColor ' 执行到该语句提示出错 End If 错误提示:Err.Number=-2147417851 Err.Description = 对象 'TrueColor' 方法的 'IAcadLayre2' 失败 请高手帮着分析一下原因,谢谢! |