frostrap 发表于 2022-7-6 14:47:36

filedia设置为零。。。

大师您好,
 
我正在用VBA编写一个块管理器程序,似乎有一个错误,AutoCAD中的filedia变量被设置为0。
 
问题是代码中没有引用filedia变量,所以我不知道是什么改变了这个变量的值。
 
在程序的一部分中,我使用以下代码调用insert命令(这是项目中唯一使用sendcommand启动autocad命令的地方):
 

ThisDrawing.SendCommand "-insert" & vbCr & thePath & vbCr & "S" & vbCr & theScale & vbCr

 
(我选择以这种方式插入块,而不是通过编程,因为我希望用户在选择插入点和旋转时能够在屏幕上看到图像的预览。)
 
这可能是filedia问题的原因吗?这个问题发生在其他人身上了吗?思想?
 
谢谢
 

LCE 发表于 2022-7-6 14:56:45

你能把完整的代码贴出来吗。显然,它不在您发布的代码中,因此可能在其他地方。
你是在调用任何lisp例程,还是完全从你的应用程序中分离出来?

frostrap 发表于 2022-7-6 15:10:30

有相当多的代码(大约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是从文本文件中读写信息的,尽管我怀疑这就是问题所在。

NBC 发表于 2022-7-6 15:15:12

 
嗨,乔,
 
您的对话框被抑制的原因是您正在使用命令行版本的insert;例如,您正在使用-insert,而不是insert。
注意命令开头的减号。在命令开头使用减号时,告诉命令仅使用命令行。

frostrap 发表于 2022-7-6 15:23:00

这就是我所怀疑的。
 
使用命令行版本是有意的,因为这是我所知道的唯一一种通过编程与insert命令的部分交互的方式,同时允许命令的其他部分保持用户控制。
 
例如,我想通过编程设置x、y和z比例,但我希望用户能够在屏幕上动态选择旋转。
 
你知道没有使用sendcommand“-insert”…,有什么方法可以做到这一点吗。。。?

Rankine16 发表于 2022-7-6 15:36:52

当FILEDIA设置为1时,下拉列表仍然无法工作,我遇到了一个问题。当我点击文件然后打开时,工具栏消失了,什么也没有发生。在命令行中,它说“打开”,但什么也不做。当我单击“打开”按钮时,也会发生同样的情况。我将FILEDIA和CMDDIA都更改为0,并从0更改为1,关闭AutoCAD并完全重新启动,但仍然没有任何更改。当FILEDIA设置为0时,我可以键入文件名,但设置为1不会启动对话框。

CmdrDuh 发表于 2022-7-6 15:44:25

这听起来像是你的对话框在屏幕上浮动,只是不可见。试着点击alt enter或alt space并选择move,点击箭头键一次或两次,然后将鼠标移动到屏幕中央,查看对话框是否在移动

Rankine16 发表于 2022-7-6 15:52:46

成功了!非常感谢你。我使用两个监视器,当其中一个出现故障时,问题就开始了。
 
再次感谢。
页: [1]
查看完整版本: filedia设置为零。。。