Olhado_ 发表于 2022-7-6 15:24:05

切换窗口

我正在尝试找到在不同窗口中操作数据的最佳方式(或任何方式)。
 
我基本上已经创建了一个新的DWG文件,它也是活动窗口,现在我想保存它。我不能只是使用
 

ThisDrawing.SaveAs Filename

 
因为它将保存原始图形。我知道新的绘图将成为活动窗口,因此如果有办法切换到活动窗口,那也将很好。
 
清楚了吗?我所要求的可能吗?
 
谢谢

rocheey 发表于 2022-7-6 16:01:26

 
你不需要“活动窗口”的东西;这不是脚本。
“ThisDrawing”很简单,是默认值,但在处理多个图形时,您可以并且应该使用自己的变量名。
 
 
创建新的DWG文件时,应为其设置一个变量,并使用该变量对其进行引用;类似这样:
 


Sub main()

   Dim FirstDwg As AcadDocument
   Dim SecondDwg As AcadDocument

   ' set the variable "FirstDwg" to some drawing you opened from disk:
   Set FirstDwg = Application.Documents.Open("c:\MyTestDwg.dwg", False)

   ' set the variable "SecondDwg" to a drawing you create new:
   Set SecondDwg = Application.Documents.Add()

   ' activate the first drawing and zoom extents
   FirstDwg.Activate: ZoomExtents

   ' Pop up the name of the active layer, in the second drawing, withoutactivating it
    MsgBox SecondDwg.ActiveLayer.Name

   'clear the Object variables before leaving the sub
   Set FirstDwg = Nothing
   Set SecondDwg = Nothing

End Sub

Olhado_ 发表于 2022-7-6 16:41:43

谢谢你的帮助。在这种情况下,我试着遵循你的规则;但我似乎无法选择活动窗口。你能帮我决定下一行是什么来保存弹出的窗口吗?
 
我还附上了该项目,以防你需要看到它。
 

Private Sub ImportButton_Click()

   ThisDrawing.SendCommand "filedia" & vbCr & "0" & vbCr
   ' Set filedia to 0
   ThisDrawing.SendCommand "import" & vbCr & "C:\Test.dgn" & vbCr & "" & vbCr & "" & vbCr & "" & vbCr
   'Import File dgn file

   ThisDrawing.SendCommand "filedia" & vbCr & "1" & vbCr
   ' Set filedia to 1
End
'Close Window
End Sub

 
再次感谢。
导入测试。拉链
页: [1]
查看完整版本: 切换窗口