田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 4 48
 123456
78910111213
14151617181920
21222324252627
282930


站点统计

最新评论



只能在模块中定义扩展方法 Autodesk.AutoCAD.Windows.ContextMenuExtension
未知 vb.net get group extents   [ 日期:2021-02-01 ]   [ 来自:本站原创 ]  HTML
Imports System.Collections.Generic
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Namespace GroupExtents
    Public Shared Class TransactionExtensions
        ' A simple extension method that aggregates the extents of any entities
        ' passed in (via their ObjectIds)
        <System.Runtime.CompilerServices.Extension> _
        Public Shared Function GetExtents(tr As Transaction, ids As ObjectId()) As Extents3d
            Dim ext As New Extents3d()
            For Each id As Object In ids
                Dim ent As Object = TryCast(tr.GetObject(id, OpenMode.ForRead), Entity)
                If ent IsNot Nothing Then
                    ext.AddExtents(ent.GeometricExtents)
                End If
            Next
            Return ext
        End Function
    End Class
    Public Class Commands
        <CommandMethod("GE")> _
        Public Sub GroupExtents()
            Dim doc As Object = Application.DocumentManager.MdiActiveDocument
            Dim db As Object = doc.Database
            Dim ed As Object = doc.Editor
            Using tr As Object = db.TransactionManager.StartTransaction()
                ' Get the group dictionary from the drawing
                Dim gd As DBDictionary = CType(tr.GetObject(db.GroupDictionaryId, OpenMode.ForRead), DBDictionary)
                If gd.Count = 0 Then
                    ed.WriteMessage(vbLf & "No groups found in drawing.")
                Else
                    ' List the groups in the drawing with an index
                    Dim groupNames As New List(Of String)(gd.Count)
                    ed.WriteMessage(vbLf & "Groups:")
                    Dim i As Integer = 0
                    For Each entry As Object In gd
                        i += 1
                        ed.WriteMessage(vbLf & "{0}. {1}", i, entry.Key)
                        groupNames.Add(entry.Key)
                    Next
                    ' Ask the user to select a group number
                    Dim pio As New PromptIntegerOptions(vbLf & "Enter group index")
                    pio.AllowNegative = False
                    pio.AllowZero = False
                    pio.DefaultValue = 1
                    pio.LowerLimit = 1
                    pio.UpperLimit = i
                    Dim pir As Object = ed.GetInteger(pio)
                    If pir.Status = PromptStatus.OK Then
                        ' Get the selected group
                        Dim grp As Object = TryCast(tr.GetObject(CType(gd(groupNames(pir.Value - 1)), ObjectId), OpenMode.ForRead), Group)
                        If grp IsNot Nothing Then
                            ' Call our extension method to get the extents of the group's
                            ' referenced objects
                            Dim ext As Object = tr.GetExtents(grp.GetAllEntityIds())
                            ' Print the information for the user
                            ed.WriteMessage(vbLf & "Group's extents are from {0} to {1}.", ext.MinPoint, ext.MaxPoint)
                        End If
                    End If
                End If
                ' Commit the transaction
                tr.Commit()
            End Using
        End Sub
    End Class
End Namespace



暂时没有评论
发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:2*2=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©