Active Contributor
Posts: 34
Registered: ‎09-09-2011
Message 1 of 4 (160 Views)

Update Attribute prior to Insert

160 Views, 3 Replies
05-29-2012 12:06 PM

I have a routine that will change attribute text when the block is in the dwg. My problem is that I would like to set the attribute text prior to insertion. Every example that I have found uses promptentityoptions which returns a result.ObjectId. as shown below.


BlockReference br = (BlockReference)tr.GetObject(result.ObjectId, OpenMode.ForRead);                  

AttributeCollection attCol = br.AttributeCollection;


What do I use in place of result.ObjectId?




*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 4 (154 Views)

Re: Update Attribute prior to Insert

05-29-2012 12:51 PM in reply to: tomg

Shortly do something like this:

                          string atag=ed.Getstring("\nEnter a tag: ").StringResult;
                          string value=ed.Getstring("\nEnter a new attribute value: ").StringResult;

                          // Then after the block was inserted
                           //Get visible attributes from BlockReference object
                            Autodesk.AutoCAD.DatabaseServices.AttributeCollection attcoll = bref.AttributeCollection;

                            foreach (ObjectId id in attcoll)
                                AttributeReference atref = (AttributeReference)tr.GetObject(id, OpenMode.ForRead);
                               if (atref.Tag== atag.ToUpper())



Active Contributor
Posts: 34
Registered: ‎09-09-2011
Message 3 of 4 (142 Views)

Re: Update Attribute prior to Insert

05-29-2012 01:37 PM in reply to: Hallex

I have something like this:


     BlockTable bt = (BlockTable)tr.GetObject(sourceDb.BlockTableId,
                            OpenMode.ForRead, false);
     foreach (ObjectId btrId in bt)
        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead, false);
        BlockReference br = (BlockReference)tr.GetObject(--What--, OpenMode.ForRead, false);
        AttributeCollection attCol = br.AttributeCollection;


 In the BlockReference statement, what is the --What-- object.



New Member
Posts: 1
Registered: ‎05-29-2012
Message 4 of 4 (120 Views)

Re: Update Attribute prior to Insert

05-29-2012 09:30 PM in reply to: tomg

For Each attID As ObjectId In RefBTR

                attEnt = tr.GetObject(attID, OpenMode.ForRead)

                If TypeOf attEnt Is AttributeDefinition Then

                    Dim attDef As AttributeDefinition = attEnt

                    Dim attRef As AttributeReference = New AttributeReference()

                    attRef.SetAttributeFromBlock(attDef, br.BlockTransform)

                    If attRef.Tag = sTagName Then

                        attRef.TextString = sValue

                        Exit Sub

                    End If

                End If


        Catch ex As Autodesk.AutoCAD.Runtime.Exception




        End Try

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.