在 autocad VBA ide 中调试未显示错误所在
Debugging in autocad VBA ide is not displaying where the error is
每当我尝试调试或 运行 程序时,如果它遇到错误,VBE (Autocad) 不会显示错误所在的行,这与其他 IDE 不同,它过去常常出现在那条线上并用黄色突出显示。另外,卷轴不起作用。我知道我应该安装插件,但我无能为力。
Option Explicit
Sub Test()
'Declarations
'Opened Document
Dim acDocu As AcadDocument
Set acDocu = ThisDrawing.Application.ActiveDocument
'Select on screen
Dim acSelectionSet As AcadSelectionSet
Set acSelectionSet = ThisDrawing.SelectionSets.Add("SjjEffffT")
acSelectionSet.SelectOnScreen
'Manipulating in loops for finding group names having objects selected
Dim entity As AcadEntity
Dim entityhandle() As String
Dim Grp As AcadGroup
Dim groupname() As String
Dim i As Integer
i = 0
Dim j As Integer
j = 0
Dim temp As Integer
temp = 0
Dim GrpEnt As AcadEntity
Dim grpenthandle As String
Dim entity_count As Integer
'Dim entity_array As Variant
entity_count = acSelectionSet.Count
ReDim entityhandle(entity_count)
ReDim groupname(entity_count)
For Each entity In acSelectionSet
'entity_array = entity
entityhandle(i) = entity.Handle
For Each Grp In ThisDrawing.groups
For Each GrpEnt In Grp
grpenthandle = GrpEnt.Handle
If entityhandle(i) = grpenthandle Then
If temp = 0 Then
groupname(j) = Grp.Name
Debug.Print "Group in selection:" & groupname(j)
j = j + 1
End If
End If
temp = temp + 1
Next
temp = 0
Next
i = i + 1
Next
'Copying the objects and pasting into new drawing
Dim acDocto As AcadDocument
Dim file_name As String
'file_name = InputBox("Enter the file name along with full path and extension")
file_name = "D:\PI_Tool_files_3223\D00440023new.DWG"
Set acDocto = Documents.Open(file_name)
Dim acObject As AcadObject
Dim retvalue As Variant
retvalue = acDocu.CopyObjects(entityhandle, acDocto.ModelSpace)
acSelectionSet.Delete
End Sub
上面写了代码。但我认为问题出在加载项上,因为我无法调试。
VBA IDE 相当古老(1998 年)并且调试能力有限。你应该停止使用它,它是一种过时的技术,Microsoft/Autodesk 不再积极支持。
对于某些错误,它无法定位到发生错误的行,并且留下模糊的错误代码和无用的消息。
您是否尝试过在第一行设置断点? (设置 acDocu = ThisDrawing.Application.ActiveDocument)
然后逐步查看有问题的 object/property/method。
它并不总是有效。
你可以将代码加载到模块中,而不是 "ThisDrawing",然后调试吗?
每当我尝试调试或 运行 程序时,如果它遇到错误,VBE (Autocad) 不会显示错误所在的行,这与其他 IDE 不同,它过去常常出现在那条线上并用黄色突出显示。另外,卷轴不起作用。我知道我应该安装插件,但我无能为力。
Option Explicit
Sub Test()
'Declarations
'Opened Document
Dim acDocu As AcadDocument
Set acDocu = ThisDrawing.Application.ActiveDocument
'Select on screen
Dim acSelectionSet As AcadSelectionSet
Set acSelectionSet = ThisDrawing.SelectionSets.Add("SjjEffffT")
acSelectionSet.SelectOnScreen
'Manipulating in loops for finding group names having objects selected
Dim entity As AcadEntity
Dim entityhandle() As String
Dim Grp As AcadGroup
Dim groupname() As String
Dim i As Integer
i = 0
Dim j As Integer
j = 0
Dim temp As Integer
temp = 0
Dim GrpEnt As AcadEntity
Dim grpenthandle As String
Dim entity_count As Integer
'Dim entity_array As Variant
entity_count = acSelectionSet.Count
ReDim entityhandle(entity_count)
ReDim groupname(entity_count)
For Each entity In acSelectionSet
'entity_array = entity
entityhandle(i) = entity.Handle
For Each Grp In ThisDrawing.groups
For Each GrpEnt In Grp
grpenthandle = GrpEnt.Handle
If entityhandle(i) = grpenthandle Then
If temp = 0 Then
groupname(j) = Grp.Name
Debug.Print "Group in selection:" & groupname(j)
j = j + 1
End If
End If
temp = temp + 1
Next
temp = 0
Next
i = i + 1
Next
'Copying the objects and pasting into new drawing
Dim acDocto As AcadDocument
Dim file_name As String
'file_name = InputBox("Enter the file name along with full path and extension")
file_name = "D:\PI_Tool_files_3223\D00440023new.DWG"
Set acDocto = Documents.Open(file_name)
Dim acObject As AcadObject
Dim retvalue As Variant
retvalue = acDocu.CopyObjects(entityhandle, acDocto.ModelSpace)
acSelectionSet.Delete
End Sub
上面写了代码。但我认为问题出在加载项上,因为我无法调试。
VBA IDE 相当古老(1998 年)并且调试能力有限。你应该停止使用它,它是一种过时的技术,Microsoft/Autodesk 不再积极支持。
对于某些错误,它无法定位到发生错误的行,并且留下模糊的错误代码和无用的消息。
您是否尝试过在第一行设置断点? (设置 acDocu = ThisDrawing.Application.ActiveDocument) 然后逐步查看有问题的 object/property/method。 它并不总是有效。
你可以将代码加载到模块中,而不是 "ThisDrawing",然后调试吗?