.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Update Attribute prior to Insert
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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?
Tom
Re: Update Attribute prior to Insert
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.AttributeCollect ion attcoll = bref.AttributeCollection;
foreach (ObjectId id in attcoll)
{
AttributeReference atref = (AttributeReference)tr.GetObject(id, OpenMode.ForRead);
if (atref.Tag== atag.ToUpper())
atref.TextString=value;
}
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Update Attribute prior to Insert
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I have something like this:
try
{
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;
etc.In the BlockReference statement, what is the --What-- object.
Tom
Re: Update Attribute prior to Insert
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Next
Catch ex As Autodesk.AutoCAD.Runtime.Exception
tr.Abort()
Finally
tr.Commit()
End Try
