有相当多的代码(大约1500行),所以我认为不会发布所有的代码。
我没有调用任何lisp例程。我唯一想做的是将控件从VBA中释放出来,这是我在上面发布的插入操作,其中控件会立即传递到autocad命令提示符。
下面是包含insert命令的sub的代码:
- Sub InsertBlock(Optional thePath As String)
- Dim theScale As Variant
- 'set the dimscale
- If IsNumeric(UserForm1.TextBox1.Value) = False Or UserForm1.TextBox1.Value < 0 Then
- MsgBox "Please entera valid numeric default scale value."
- UserForm1.TextBox1.SetFocus
- Exit Sub
- End If
- If UserForm1.TextBox1.Value = 0 Then
- theScale = ThisDrawing.GetVariable("DIMSCALE")
- Else
- theScale = UserForm1.TextBox1.Value
- End If
- Dim objLayer As AcadLayer
- Dim FoundLayer As Boolean
- Dim OldLayer As String
- 'determine whether or not default layer exists
- 'if it does exist, set it as current layer
- 'if it doesn't exist, prompt the user and return to the userform.
- FoundLayer = False
- For Each objLayer In ThisDrawing.Layers
- If objLayer.Name = UserForm1.ComboBox1.Value Then
- FoundLayer = True
- Exit For
- End If
- Next
- If FoundLayer = False Then
- MsgBox "The default layer entered for this block does not exist on this drawing."
- UserForm1.ComboBox1.SetFocus
- Exit Sub
- Else
- OldLayer = ThisDrawing.ActiveLayer.Name
- ThisDrawing.ActiveLayer = ThisDrawing.Layers(UserForm1.ComboBox1.Value)
- End If
- If thePath = "" Then
- thePath = GetDefaultDirectory + UserForm1.ListBox1.Value + "" + UserForm1.ListBox2.Value + ".dwg"
- End If
- UserForm1.Hide
- 'insert with or without dynamic rotation
- If UserForm1.CheckBox2 = True Then
- ThisDrawing.SendCommand "-insert" & vbCr & thePath & vbCr & "S" & vbCr & theScale & vbCr
- Else
- ThisDrawing.SendCommand "-insert" & vbCr & thePath & vbCr & "S" & vbCr & theScale & vbCr & "R" & vbCr & "0" & vbCr
- End If
- 'expload last block entered
- If UserForm1.CheckBox3.Value = True Then
- ThisDrawing.SendCommand "Explode" & vbCr & "L" & vbCr & vbCr
- End If
- 'reset the original layer
- ThisDrawing.ActiveLayer = ThisDrawing.Layers(OldLayer)
- End Sub
我不能确定问题是否来自其他地方,但我确实知道,当这种情况发生时,没有其他VBA程序正在运行,而且在编写该程序之前,这个问题似乎从未发生过。
我还有一些其他的sub是从文本文件中读写信息的,尽管我怀疑这就是问题所在。 |