明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 195|回复: 0

[运行时] 坐标标注编组

[复制链接]
发表于 2024-6-12 10:11 | 显示全部楼层 |阅读模式

只是最后一组坐标编成组,其它的没变.


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '坐标标注
    Dim docLock As DocumentLock = Core.Application.DocumentManager.MdiActiveDocument.LockDocument() '“非模态窗口,要锁定文档”

    NativeMethods.SetFocus(Core.Application.DocumentManager.MdiActiveDocument.Window.Handle) 'CAD获得焦点

    Dim entYId As ObjectId
    Dim entXId As ObjectId
   
    Dim psr As PromptSelectionResult '请求在图形区域选择对象

    psr = ed.GetSelection() '屏幕选取

    Dim SetA As SelectionSet

    If psr.Status = PromptStatus.OK Then '如果提示状态OK,表示对象已选
        SetA = psr.Value
        For Each obj In SetA
            Using cTrans As Transaction = db.TransactionManager.StartTransaction() '开启事务处理

                Dim entity As Entity = CType(cTrans.GetObject(obj.ObjectId, OpenMode.ForWrite, True), Entity)

                Select Case entity.GetType.Name
                    Case "DBPoint"
                        Dim Poline As DBPoint = CType(cTrans.GetObject(obj.ObjectId, OpenMode.ForRead, True), DBPoint) '获取点实体对象
                        ' MsgBox(666)
                        Dim XYZ As Point3d = Poline.Position

                        Dim entX As New DBText With {
                            .TextString = XYZ.Y,     'X 文本
                            .Position = XYZ,   '三维点
                            .ColorIndex = 3,
                            .Rotation = 0,     '文字旋转角度
                            .Height = 0.3      '文字高度
                        }
                        entXId = AppendEntity(entX) '显示X

                        Dim entY = New DBText With {
                            .TextString = XYZ.X,'Y 文本
                            .Position = XYZ,    '三维点
                            .ColorIndex = 6,
                            .Rotation = 0,      '文字旋转角度
                            .Height = 0.3,     '文字高度
                            .VerticalMode = TextVerticalMode.TextTop,  '对齐
                            .AlignmentPoint = XYZ   '设置对齐点
                        }
                        entYId = AppendEntity(entY) '显示X


                        '========组===================================================================

                        Dim groupName As String = "MyGroup"

                        Using Trans As Transaction = db.TransactionManager.StartTransaction

                            Dim gp As New Group(groupName, True)

                            Dim dict As DBDictionary = Trans.GetObject(db.GroupDictionaryId, OpenMode.ForWrite)

                            dict.SetAt(groupName, gp)

                            Dim ids As New ObjectIdCollection From {
                                entXId,
                                entYId
                            }
                            gp.Append(ids)

                            Trans.AddNewlyCreatedDBObject(gp, True)
                            Trans.Commit()
                        End Using
                        '===========================================================================
                    Case Else

                End Select
                cTrans.Commit()
            End Using
        Next
    End If

    docLock.Dispose()
End Sub

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-6-18 21:45 , Processed in 0.274965 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表