cq_starsea 发表于 2015-7-9 08:55:00

为什么不能获取属性值?

我用.net的方法读取块里的属性
Private Function DbxGetBlocksData(btr As BlockTableRecord, doc As Document) As Dictionary(Of String, String)
      Dim dic As New Dictionary(Of String, String)
      Dim db As Database = doc.Database
      Using trans As Transaction = db.TransactionManager.StartTransaction
            For Each obj_id As ObjectId In btr
                Dim ent As Entity = trans.GetObject(obj_id, OpenMode.ForRead)
                If ent.GetType.Name = "AttributeDefinition" Then
                  Dim adf As AttributeDefinition = ent
                  dic.Add(adf.Tag, adf.TextString)
                  daf.Tag可以获取属性名称,但是daf.TextString的值始终是"",请问一下是为什么?
                End If
            Next
      End Using
      Return dic
    End Function

cq_starsea 发表于 2015-7-9 10:58:00

搞定了,贴上来,免得以后忘了。
    Dim brf_ids As ObjectIdCollection = btr.GetBlockReferenceIds(True, False)
                Dim br As BlockReference
                For Each brf_id As ObjectId In brf_ids
                  Dim obj As Object = brf_id.GetObject(OpenMode.ForRead)
                  If obj.GetType.Name = "BlockReference" Then
                        br = obj
                        If br.Name.StartsWith("股份公司-") Then
                            For Each att_id As ObjectId In br.AttributeCollection
                              Dim att As AttributeReference = att_id.GetObject(OpenMode.ForRead)
                              If att.Tag.StartsWith("名称{") Then
                                    dObj.PaperName = att.TextString
                              End If
                              If att.Tag.StartsWith("图号{") Then
                                    dObj.PaperCode = att.TextString
                              End If
                            Next
                            Exit For
                        End If                  End If
                Next
页: [1]
查看完整版本: 为什么不能获取属性值?