Author Topic: iterating attributes  (Read 1171 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
iterating attributes
« on: September 12, 2011, 04:26:32 PM »
Found several examples but when I do it,
the Tag and the TextString stay the same during the loop.
The block has 5 attributes, all stirng values with different Tag names.

Count : 5
AR: PART# 2037248
AR: PART# 2037248
AR: PART# 2037248
AR: PART# 2037248
AR: PART# 2037248

Here's what the block attribute collection looks like (see attached image).

Code: [Select]
BlockReference TagBlkRef = (BlockReference)trans.GetObject(BlkRefIds[0], OpenMode.ForRead);
ObjectId TagId = TagBlkRef.AttributeCollection[0];
DBObject obj = trans.GetObject(TagId, OpenMode.ForRead);
AttributeReference ar = (AttributeReference)obj;
AttributeCollection abtr = TagBlkRef.AttributeCollection;         

                if (FileName == ar.TextString)
                {                   
                    foreach (ObjectId arId in abtr)                   
                    {                       
                        DBObject Aobj = trans.GetObject(arId, OpenMode.ForRead);
                        ar = obj as AttributeReference;

                        if (ar != null)
                        {
                            editor.WriteMessage("\nAR: " + ar.Tag + " " + ar.TextString);
                            editor.WriteMessage("\n Hey, not changing.");

« Last Edit: September 12, 2011, 04:40:43 PM by BillZndl »

BillZndl

  • Guest
Re: iterating attributes
« Reply #1 on: September 12, 2011, 04:54:50 PM »
Ooops, now it's working.

DBObject Aobj = trans.GetObject(arId, OpenMode.ForRead);

should be

obj = trans.GetObject(arId, OpenMode.ForRead);

as object was already declared.  :ugly:

< sigh >

Thanks anyways!



Jeff H

  • Needs a day job
  • Posts: 6149
Re: iterating attributes
« Reply #2 on: September 12, 2011, 04:55:38 PM »
I am not able to follow it with the code posted,
 
but guessing do you mean
Quote

DBObject Aobj = trans.GetObject(arId, OpenMode.ForRead);
Aobj = Aobj as AttributeReference;
instead of
Quote
ar = obj as AttributeReference;


 
********************************************Edit*********************************************
Nevermind looks like you caught it.

 
« Last Edit: September 12, 2011, 05:01:25 PM by Jeff H »

BillZndl

  • Guest
Re: iterating attributes
« Reply #3 on: September 13, 2011, 06:29:02 AM »
Don't know.
Everything looked okay to begin with.
Then didn't work as expected so I was debugging when I noticed the error.
Fixed that and everything worked.
Just trying to do too much in one day.

Thanks!