- 积分
- 132
- 明经币
- 个
- 注册时间
- 2016-4-10
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本人机械设计人员,想自己做点二次开发自己用,用的vs2012中的vb.net。
新建项目后添加引用,然后复制到本地=fasle。代码如下,运行时报错如图。
本人电脑win7x64,cpu选anycpu、anycpu优先x86、x86、x64都不行。
启用vs承载进程选与不选也都不行。
引用的文件确实存在,路径正确。
求各位二次开发高手、vb.net高手指点。
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Colors
Public Class Form1
Dim acadapp As AutoCAD.AcadApplication
Dim acaddat As AutoCAD.AcadDatabase
Dim acaddoc As AutoCAD.AcadDocument
Dim pro() As System.Diagnostics.Process '搜索进程用
Dim acLyrTbl As Autodesk.AutoCAD.DatabaseServices.LayerTable
Dim acLyrTblRec As Autodesk.AutoCAD.DatabaseServices.LayerTableRecord
Dim acBlkTbl As Autodesk.AutoCAD.DatabaseServices.BlockTable
Dim acBlkTblRec As Autodesk.AutoCAD.DatabaseServices.BlockTableRecord
Private Sub Form1_Load() Handles MyBase.Load
'*****以下检测cad是否启动,不启动则启动,启动不了则报错。*****
pro = System.Diagnostics.Process.GetProcessesByName("acad")
If pro.Length <= 0 Then
On Error Resume Next
acadapp = GetObject(, "AutoCAD.acadApplication")
acadapp.Visible = True
acadapp.WindowState = AutoCAD.AcWindowState.acMax
AppActivate(acadapp.Caption)
If Err.Number Then
Err.Clear()
acadapp = CreateObject("AutoCAD.Application")
If Err.Number Then
MessageBox.Show("不能运行AutoCAD,请检查是否安装了AutoCAD")
Exit Sub
End If
End If
End If
'*****以上检测cad是否启动,不启动则启动,启动不了则报错。*****
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
acaddoc = acadapp.DocumentManager.MdiActiveDocument
MessageBox.Show("1")
acaddat = acaddoc.Database
MessageBox.Show("2")
Using acTrans As Transaction = acaddat.TransactionManager.StartTransaction()
MessageBox.Show("3")
acLyrTbl = acTrans.GetObject(acaddat.LayerTableId, OpenMode.ForRead)
MessageBox.Show("4")
If acLyrTbl.Has("mjh") = False Then
acLyrTblRec = New LayerTableRecord()
acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 251)
acLyrTblRec.Name = "mjh"
acLyrTbl.UpgradeOpen()
acLyrTbl.Add(acLyrTblRec)
acTrans.AddNewlyCreatedDBObject(acLyrTblRec, True)
End If
acBlkTbl = acTrans.GetObject(acaddat.BlockTableId, OpenMode.ForRead)
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
acTrans.Commit()
End Using
End Sub
End Class
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|