Author Topic: multileader  (Read 1546 times)

0 Members and 1 Guest are viewing this topic.

nekitip

  • Guest
multileader
« on: September 24, 2014, 03:09:57 AM »
has anyone some routine to get attribute refs from multileader?
I'm trying and have found some way to do it, but not sure if this is safe
Code - vb.net: [Select]
  1.  Dim t As MLeader = trans.GetObject(oid, OpenMode.ForRead)
  2.                         If t.HasContent Then
  3.                             Select Case t.ContentType
  4.                                 Case ContentType.MTextContent
  5.                                     'strange, has mtext, but mtext is not in db
  6.                                     'Dim mt As MText = trans.GetObject(t.MText.ObjectId, OpenMode.ForRead)
  7.                                     If t.MText.Text.Length > 2 Then (..do your things...)
  8.                                 Case ContentType.BlockContent
  9.                                     'blocktablerecord?                                                        
  10.                                     Dim btrb As BlockTableRecord = trans.GetObject(t.BlockContentId, OpenMode.ForRead)
  11.                                     For Each oho As ObjectId In btrb
  12.                                         Dim oclass = oho.ObjectClass.DxfName
  13.                                         If oclass = "ATTDEF" Then
  14.                                             Dim attd As AttributeDefinition = trans.GetObject(oho, OpenMode.ForRead)
  15.                                             Dim attr As AttributeReference = t.GetBlockAttribute(oho) '(and do your things with attr)
  16.                                         End If
  17.                                     Next
  18.                             End Select
  19.                         End If

so, i'm not sure if GetBlockAttribute is the right way to access it, since i'm paranoid about not seeing any transaction
also, is there a different way?

nekitip

  • Guest
Re: multileader
« Reply #1 on: September 24, 2014, 03:20:07 AM »
I've been trying to do this for hours, and finally found some blog
http://adndevblog.typepad.com/autocad/2012/06/traversing-through-attribute-references-in-mleader.html
so, as it looks, attreference can be get this way, but must be enclosed in "using"
Code - C#: [Select]
  1. foreach (ObjectId Id in record)
  2.         {
  3.             DBObject dbObj = Tx.GetObject(Id, OpenMode.ForRead) ;
  4.  
  5.             if (dbObj is AttributeDefinition)
  6.             {
  7.                 AttributeDefinition attDef =
  8.                                         dbObj as AttributeDefinition;
  9.                 using (AttributeReference attRef =
  10.                                       mleader.GetBlockAttribute(Id))
  11.                 {
  12.                     ed.WriteMessage("Reference text for tag " +
  13.                      attDef.Tag + " is " + attRef.TextString + "\n");
  14.                 }
  15.             }
  16.         }