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

aveva,marine,vbnet,编程,系列,新建,图纸,创建,文字 · 浏览次数 : 10

小编点评

```vb.net Imports MarApi Imports Aveva.ApplicationFramework.PresentationImports Aveva.Marine.Drafting Public Class MyAmFunctionAtt(NameOf(绘图控制), NameOf(新建文字)) Public Sub 新建文字(wm As WindowManager) Dim draftApp As New MarDrafting Try If Not draftApp.DwgCurrent() Then MsgBox("未开启任何图纸无法创建文字", MsgBoxStyle.Critical, "错误提示") Return End If Dim tstr = InputBox("输入文字内容", "输入", DateTime.Now.ToString("yyyyMMdd-HHmmss")) Using t As New MarText(tstr) t.Position = New Aveva.Marine.Geometry.MarPointPlanar(0, 0) t.Height = 5.0 t.TextColour = New MarColour("Red") draftApp.TextNew(t) End Using Catch ex As Exception MsgBox(ex.StackTrace) Finally draftApp.Dispose() End Try End Sub Public Sub 新建多行文字(wm As WindowManager) Dim draftApp As New MarDrafting Try If Not draftApp.DwgCurrent() Then MsgBox("未开启任何图纸无法创建文字", MsgBoxStyle.Critical, "错误提示") Return End If Dim tstr = InputBox("输入文字内容", "输入", DateTime.Now.ToString("yyyyMMdd-HHmmss") + Environment.NewLine + "我是第二行") Using t As New MarText(tstr) t.Position = New Aveva.Marine.Geometry.MarPointPlanar(0, 0) t.Height = 5.0 t.TextColour = New MarColour("Red") draftApp.TextNew(t) End Using Catch ex As Exception MsgBox(ex.StackTrace) Finally draftApp.Dispose() End Try End Sub End Class ``` **使用方法:** 1. 将此代码复制到一个新的模块中。 2. 在 Visual Studio 中创建一个新的 Winforms 项目。 3. 将该模块添加为项目中的部分。 4. 在项目属性中设置以下设置: * 项目类型:Windows Forms * 启动项目:.NET Framework 的应用程序 * 页面模板:Windows Forms 5. 构建和运行项目。

正文

根据MarApi,创建图形文件,新建文字

Imports Aveva.ApplicationFramework.Presentation
Imports Aveva.Marine.Drafting ' marAPI.dll
Public Class 绘图控制

    <MyAmFunctionAtt(NameOf(绘图控制), NameOf(新建图纸))>
    Public Sub 新建图纸(wm As WindowManager)
        Dim draftApp As New MarDrafting
        Try
            'am是单文档模式。不可以同时开2个文件
            If draftApp.DwgCurrent() Then
                If Not draftApp.DwgIsModified() Then '图纸未改动直接退出
                    draftApp.DwgClose()
                Else
                    If MsgBox("检测到图纸有改动", MsgBoxStyle.Question, "是否保存当前图纸?") = MsgBoxResult.Ok Then
                        draftApp.DwgSave()
                    Else
                        draftApp.DwgClose()
                    End If
                End If
            End If
            draftApp.DwgNew(DateTime.Now.ToString("yyyyMMdd-HHmmss"))
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        Finally
            draftApp.Dispose()
        End Try

    End Sub

    <MyAmFunctionAtt(NameOf(绘图控制), NameOf(新建文字))>
    Public Sub 新建文字(wm As WindowManager)
        Dim draftApp As New MarDrafting
        Try
            If Not draftApp.DwgCurrent() Then
                MsgBox("未开启任何图纸无法创建文字", MsgBoxStyle.Critical, "错误提示")
                Return
            End If
            Dim tstr = InputBox("输入文字内容", "输入", DateTime.Now.ToString("yyyyMMdd-HHmmss"))
            Using t As New MarText(tstr)
                t.Position = New Aveva.Marine.Geometry.MarPointPlanar(0, 0)
                t.Height = 5.0
                t.TextColour = New MarColour("Red")
                draftApp.TextNew(t)
            End Using
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        Finally
            draftApp.Dispose()
        End Try
    End Sub
    <MyAmFunctionAtt(NameOf(绘图控制), NameOf(新建多行文字))>
    Public Sub 新建多行文字(wm As WindowManager)
        Dim draftApp As New MarDrafting
        Try
            If Not draftApp.DwgCurrent() Then
                MsgBox("未开启任何图纸无法创建文字", MsgBoxStyle.Critical, "错误提示")
                Return
            End If
            Dim tstr = InputBox("输入文字内容", "输入", DateTime.Now.ToString("yyyyMMdd-HHmmss") + Environment.NewLine + "我是第二行")
            Using t As New MarText(tstr)
                t.Position = New Aveva.Marine.Geometry.MarPointPlanar(0, 0)
                t.Height = 5.0
                t.TextColour = New MarColour("Red")
                draftApp.TextNew(t)
            End Using
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        Finally
            draftApp.Dispose()
        End Try
    End Sub
End Class

 

与Aveva Marine VBNET 编程系列-新建图纸,创建文字相似的内容:

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 编程系列-修改程序快捷键

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

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 编程系列===>读取drawing explorer的第一层级 view

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

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

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

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