今天我们研究下读取drawing expolrer的第一层级:view
下面的图纸的层级目录示意图,我们今天需要获取所有的view
主要用到2个方法:
1# 获取第一个元素
2# 获取相邻的元素
Imports Aveva.ApplicationFramework.Presentation
Imports Aveva.Marine.Drafting
Imports Aveva.Marine.UI ' marAPI.dll
Imports Aveva.Marine.Utility ' marAPI.dll
Imports System.IO
Imports System.Reflection
Imports System.Windows.Forms
Public Class 读取DrawingExplorer
<MyAmFunctionAtt(NameOf(读取DrawingExplorer), NameOf(读取视图名称))>
Public Sub 读取视图名称(wm As WindowManager)
Try
Dim amEnv As New AmEnvironment()
'检查是否已经开了图纸
If Not amEnv.DraftApp.DwgCurrent() Then MsgBox("当前未开启任何图纸,结束命令!", MsgBoxStyle.Critical) : Exit Sub
'读取第一个view
Dim vh As MarElementHandle, index As Integer = 1
Try
vh = amEnv.DraftApp.ElementChildFirstGet()
amEnv.MarUI.MessageNoConfirm($"第{index}个view的名字是:" + amEnv.DraftApp.SubpictureNameGet(vh) + Environment.NewLine)
index += 1
Catch ex As Exception
MsgBox("图纸中无任何内容!", MsgBoxStyle.Critical) : Exit Sub
End Try
'读取第2个view
Dim nextVh As MarElementHandle
Try
nextVh = amEnv.DraftApp.ElementSiblingNextGet(vh)
amEnv.MarUI.MessageNoConfirm($"第{index}个view的名字是:" + amEnv.DraftApp.SubpictureNameGet(nextVh) + Environment.NewLine)
index += 1
Catch ex As Exception
MsgBox("图纸中无任何内容!", MsgBoxStyle.Critical) : Exit Sub
End Try
Dim errFlag As Boolean = True
Do
Try
nextVh = amEnv.DraftApp.ElementSiblingNextGet(nextVh)
amEnv.MarUI.MessageNoConfirm($"第{index}个view的名字是:" + amEnv.DraftApp.SubpictureNameGet(nextVh) + Environment.NewLine)
index += 1
Catch ex As Exception
errFlag = False
End Try
Loop While errFlag
Catch ex As Exception
MsgBox(ex.StackTrace)
End Try
End Sub
End Class
程序运行结果如下: