Aveva Marine VBNET 编程系列====>读取drawing explorer的第2层级 Sub views

aveva,marine,vbnet,编程,系列,读取,drawing,explorer,层级,sub,views · 浏览次数 : 41

小编点评

**读取子视图名称** 该代码读取当前视图的子视图名称,并打印到消息框中。 **步骤:** 1. **获取当前视图的父级第一个子级视图的句柄** `vh`。 2. **读取第 2 个子视图** `nextVh` 的句柄。 3. **循环读取所有子视图** `subViews` 并将每个子视图的名称打印到消息框中。 4. **循环读取所有子视图的子视图** `sv` 并将其名称打印到消息框中。 5. **显示完成的通知**。 **代码:** ```python class DrawingExpolrerEx: # ...其他方法省略 ... # 获取当前子视图的全部组件的句柄 def SubViewComponents(self, draftApp, subviewHandle): # ...其他方法省略 ... # 获取当前图纸的全部视图的句柄 def DrawingViews(self, draftApp): # ...其他方法省略 ... ``` **使用示例:** ```python # 获取当前视图的子视图名称 subviews = drawing_explorer.ViewSubViews(drawing_app, view_handle) # 打印子视图名称 for subview in subviews: drawing_explorer.MarUI.MessageNoConfirm(f"第 {i} 个subview的名称是:{subview}") ``` **输出:** ``` 第 1 个subview的名称是:我的第一个子视图 第 2 个subview的名称是:我的第二个子视图 ... 第 10 个subview的名称是:我的第10个子视图 ```

正文

接上期的内容,此次读取view的下一层几subview

主要用到下面的方法获取view的第一个子级

一个封装的类

Public Class DrawingExpolrerEx
    Public Shared Function DrawingHasViews(draftApp As MarDrafting) As Boolean
        Dim vh As MarElementHandle
        Try
            vh = draftApp.ElementChildFirstGet()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    ''' <summary>
    '''  获取当前视图的全部的子视图的句柄
    ''' </summary>
    ''' <param name="draftApp">MarDrafting对象</param>
    ''' <param name="viewHandle">视图的句柄</param>
    ''' <returns>子视图句柄的list集合</returns>
    Public Shared Function ViewSubViews(draftApp As MarDrafting, viewHandle As MarElementHandle) As List(Of MarElementHandle)
        If Not draftApp.ElementIsView(viewHandle) Then
            Return Nothing
        End If
        Dim rtns As New List(Of MarElementHandle)
        Try
            Dim subvh As MarElementHandle
            subvh = draftApp.ElementChildFirstGet(viewHandle)
            rtns.Add(subvh)
            '读取第2个view
            Dim nextsubVh As MarElementHandle
            Try
                nextsubVh = draftApp.ElementSiblingNextGet(subvh)
                rtns.Add(nextsubVh)
            Catch ex As Exception
            End Try
            Dim errFlag As Boolean = True
            Do
                Try
                    nextsubVh = draftApp.ElementSiblingNextGet(nextsubVh)
                    rtns.Add(nextsubVh)
                Catch ex As Exception
                    errFlag = False
                End Try
            Loop While errFlag
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        End Try
        Return rtns
    End Function

    ''' <summary>
    ''' 获取当前子视图的全部的组件的句柄
    ''' </summary>
    ''' <param name="draftApp">MarDrafting对象</param>
    ''' <param name="subviewHandle">子视图的句柄</param>
    ''' <returns>组件句柄的list集合</returns>
    Public Shared Function SubViewComponents(draftApp As MarDrafting, subviewHandle As MarElementHandle) As List(Of MarElementHandle)
        If Not draftApp.ElementIsSubview(subviewHandle) Then
            Return Nothing
        End If
        Dim rtns As New List(Of MarElementHandle)
        Try
            Dim compovh As MarElementHandle
            compovh = draftApp.ElementChildFirstGet(subviewHandle)
            rtns.Add(compovh)
            '读取第2个view
            Dim nextcompobVh As MarElementHandle
            Try
                nextcompobVh = draftApp.ElementSiblingNextGet(compovh)
                rtns.Add(nextcompobVh)
            Catch ex As Exception
            End Try
            Dim errFlag As Boolean = True
            Do
                Try
                    nextcompobVh = draftApp.ElementSiblingNextGet(nextcompobVh)
                    rtns.Add(nextcompobVh)
                Catch ex As Exception
                    errFlag = False
                End Try
            Loop While errFlag
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        End Try
        Return rtns
    End Function

    ''' <summary>
    ''' 获取当前图纸的全部的视图的句柄
    ''' </summary>
    ''' <param name="draftApp">MarDrafting对象</param>
    ''' <returns>视图句柄的list集合</returns>
    Public Shared Function DrawingViews(draftApp As MarDrafting) As List(Of MarElementHandle)
        Dim rtns As New List(Of MarElementHandle)
        Try
            If Not DrawingHasViews(draftApp) Then MsgBox("当前未开启任何图纸,结束命令!", MsgBoxStyle.Critical) : Return Nothing
            '读取第一个view
            Dim vh As MarElementHandle
            vh = draftApp.ElementChildFirstGet()
            rtns.Add(vh)
            '读取第2个view
            Dim nextVh As MarElementHandle
            Try
                nextVh = draftApp.ElementSiblingNextGet(vh)
                rtns.Add(nextVh)
            Catch ex As Exception
            End Try
            Dim errFlag As Boolean = True
            Do
                Try
                    nextVh = draftApp.ElementSiblingNextGet(nextVh)
                    rtns.Add(nextVh)
                Catch ex As Exception
                    errFlag = False
                End Try
            Loop While errFlag
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        End Try
        Return rtns
    End Function


End Class

 

主函数,也就文章刚开始看到的结果

  <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
            Dim views = DrawingExpolrerEx.DrawingViews(amEnv.DraftApp)
            If views Is Nothing Then MsgBox("图纸中无任何内容!", MsgBoxStyle.Critical) : Exit Sub
            Dim i As Integer = 1
            For Each item As MarElementHandle In views
                amEnv.MarUI.MessageNoConfirm($"<------第 {i} 个view的名称是:{amEnv.DraftApp.SubpictureNameGet(item)},开始读取其子视图------> ")
                Dim subViews = DrawingExpolrerEx.ViewSubViews(amEnv.DraftApp, item)
                If subViews IsNot Nothing Then
                    Dim j As Integer = 1
                    For Each sv As MarElementHandle In subViews
                        amEnv.MarUI.MessageNoConfirm($"第 {j} 个subview的名称是:{amEnv.DraftApp.SubpictureNameGet(sv)} ")
                        j += 1
                    Next
                    amEnv.MarUI.MessageNoConfirm($"<-------第 {i} 个view的读取其子视图完成------>")
                End If
                i += 1
            Next
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        End Try

    End Sub

 

与Aveva Marine VBNET 编程系列====>读取drawing explorer的第2层级 Sub views相似的内容:

Aveva Marine VBNET 编程系列====>读取drawing explorer的第2层级 Sub views

接上期的内容,此次读取view的下一层几subview 主要用到下面的方法获取view的第一个子级 一个封装的类 Public Class DrawingExpolrerEx Public Shared Function DrawingHasViews(draftApp As MarDrafting

Aveva Marine VBNET 编程系列===>读取drawing explorer的第一层级 view

今天我们研究下读取drawing expolrer的第一层级:view 下面的图纸的层级目录示意图,我们今天需要获取所有的view 主要用到2个方法: 1# 获取第一个元素 MarDrafting.ElementChildFirstGet Method () 2# 获取相邻的元素 MarDrafti

Aveva Marine VBNET 编程系列-修改程序快捷键

修改HullDesign程序的主题以及菜单项的快捷键 引用的dll文件 下面的是代码和快捷键配置文件: https://files.cnblogs.com/files/NanShengBlogs/AMShortCut.HullDesign.zip?t=1695908179&download=true

Aveva Marine VBNET 编程系列-新建图纸,创建文字

根据MarApi,创建图形文件,新建文字 Imports Aveva.ApplicationFramework.Presentation Imports Aveva.Marine.Drafting ' marAPI.dll Public Class 绘图控制

Aveva Marine VBNET 编程系列-创建曲线

显现的效果 代码实现: Public Sub 新建曲线(wm As WindowManager) Dim draftApp As New MarDrafting Dim ui As New MarUi 'Im

Aveva Marine VBNET 编程系列-封装一个类

由于AM的marapi的大部分类实现了IDisposable接口,所有避免内存过大,用了一般需要dispose下 微软官方的解释: https://learn.microsoft.com/zh-cn/dotnet/api/system.idisposable?view=net-7.0 以下是MarD

Aveva Marine VBNET 编程系列   获取文字

此系列的教程,暂时不更新,因为没多少人愿意加入一起学习的行列,有需要学习的可以加我微信或者QQ讨论 电话:17607170146(微信同号) QQ:442024898 提取图纸中的文字, Public S

Aveva Marine VBNET 编程系列-搭建开发框架

引用的Dll Aveva.ApplicationFramework.dll Aveva.ApplicationFramework.Presentation 菜单展示效果 创建Attribute,用于反射来动态创建菜单,不用每次都去写command Public Class MyAmFunctionA

C# AVEVA MARINE 二次开发 读取分段

快速读取和筛选分段元素 [MyAmFunctionAtt(nameof(测试功能), nameof(读取分段))] public void 读取分段(WindowManager wm) { try { foreach (var item in wm.Windows) { if (item is Do

c# aveva marine 批量导出图纸到dxf格式

获取图纸数据库 查看代码 public static Dictionary