zoukankan      html  css  js  c++  java
  • 添加和读取扩展数据

    1、添加扩展数据

      Private Sub 添加扩展数据(ByVal ent As Entity, ByVal DictName As String, ByVal TypedValue As TypedValue)
            If ent.ExtensionDictionary = Nothing Then
                ent.CreateExtensionDictionary()
            End If
            Using tr As Transaction = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction
                Dim xDict As DatabaseServices.DBDictionary = tr.GetObject(ent.ExtensionDictionary, OpenMode.ForWrite)
                If Not xDict.Contains(DictName) Then
                    xDict.UpgradeOpen()
                    Dim xrec As New Xrecord
                    Dim rb As New ResultBuffer
                    rb.Add(TypedValue)
                    xrec.Data = rb
                    xDict.SetAt(DictName, xrec)
                    tr.AddNewlyCreatedDBObject(xrec, True)
                End If
            End Using
        End Sub
    
        Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
            Dim CurOption As PromptSelectionOptions = New PromptSelectionOptions()
            With CurOption
                .MessageForAdding = "请选择一个图元:"
                .RejectObjectsOnLockedLayers = True
                .RejectPaperspaceViewport = True
            End With
            Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim prEntRes As PromptSelectionResult = doc.Editor.GetSelection(CurOption)
            If prEntRes.Status = PromptStatus.OK Then
                Using documentLock As Autodesk.AutoCAD.ApplicationServices.DocumentLock = doc.LockDocument()
                    Using db As Autodesk.AutoCAD.DatabaseServices.Database = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.WorkingDatabase
                        Using trans As Autodesk.AutoCAD.DatabaseServices.Transaction = db.TransactionManager.StartTransaction
                            Dim ent1 As Entity = CType(trans.GetObject(prEntRes.Value(0).ObjectId, DatabaseServices.OpenMode.ForWrite, False), Entity)
                            添加扩展数据(ent1, "WidthRevised", New TypedValue(DxfCode.Bool, True))
                            trans.Commit()
                        End Using
                    End Using
                End Using
            End If
        End Sub
     

    2、读取扩展数据

    Private Function 读取扩展数据(ByVal ent As Entity, ByVal DictName As String) As Object
            Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Using TR As Autodesk.AutoCAD.DatabaseServices.Transaction = doc.TransactionManager.StartTransaction
                If ent.ExtensionDictionary.IsNull Then
                    Return Nothing
                Else
                    Dim xDict As DBDictionary = CType(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.GetObject(ent.ExtensionDictionary, DatabaseServices.OpenMode.ForRead), DBDictionary)
                    If xDict.Contains(DictName) Then
                        Dim xRecId As ObjectId = xDict.GetAt(DictName)
                        Dim xRec As Xrecord = CType(TR.GetObject(xRecId, DatabaseServices.OpenMode.ForRead), Xrecord)
                        Return xRec.Data.AsArray(0).Value
                    Else
                        Return Nothing
                    End If
                End If
            End Using
        End Function
  • 相关阅读:
    bzoj3527: [Zjoi2014]力 fft
    bzoj3295: [Cqoi2011]动态逆序对 cdq分治
    快速读入fread
    km板子(二分图最大权匹配)
    spfa毒瘤算法
    牛客网暑期ACM多校训练营(第三场)DEncrypted String Matching fft
    P4173 残缺的字符串 fft
    圆和多边形交模板
    hdu多校2C
    Codeforces Round #449 (Div. 1)C
  • 原文地址:https://www.cnblogs.com/rf8862/p/12306121.html
Copyright © 2011-2022 走看看