以前,一直用使用vba编程,最近刚刚学习.net,vs2010+AutoCAD2012
编制一个命令,文本内容批量加1000,结果调试错误
vs2010的信息是“在 System.AccessViolationException 中第一次偶然出现的“AcdbMgd.dll”类型的异常”
代码如下
-
- ' 加法Temp
- <CommandMethod("ADT")> Public Sub ADT()
- On Error Resume Next
- '定义过滤条件
- Dim value1 As TypedValue = New TypedValue(0, "TEXT")
- Dim values() As TypedValue = {value1}
- Dim sfilter As New SelectionFilter(values)
- '定义一个选择集交互类
- Dim optSel As New PromptSelectionOptions
- '选择操作时的提示文本
- optSel.MessageForAdding = "单行文本"
- Dim resSel As PromptSelectionResult = ed.GetSelection(optSel, sfilter)
- If resSel.Status = PromptStatus.Cancel Then Return
- '返回选择集的用户提示类
- Dim sSet As SelectionSet = resSel.Value
- '得到选择集中所有对象的objectId集合
- Dim ids As ObjectId() = sSet.GetObjectIds()
- Using trans As Transaction = db.TransactionManager.StartTransaction()
- '总和
- '遍历选择集
- For Each sSetEndId As ObjectId In ids
- Dim ent As DBText= trans.GetObject(sSetEndId, OpenMode.ForWrite)
- strK1 = ent.TextString
- dblK2 = Val(strK1)
- ent.TextString = CStr(Format(dblK2 + 1000, "#"))
- trans.Commit()
- Next
- End Using
- End Sub
貌似是第二遍提取ent的时候出错,不知原因,请高手赐教,非常感谢
|