Message 1 of 2
After adding BlockRefernce there are not attributes to edit

Not applicable
01-18-2010
07:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In a drawing I have a block with editable attributes.
the following code adds it to any layout required.
private static void ProcessSpaceForRevBlockAttributeUpdate(Layout acLayout, Transaction acTrans, string blockName, List attributes)
{
BlockTable acBlkTbl = acTrans.GetObject(acLayout.Database.BlockTableId,
OpenMode.ForRead) as BlockTable;
BlockTableRecord acLayoutBlkTblRec = acTrans.GetObject(acLayout.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord;
//Get any offset values from Configuration.
double yValue = 0;
double initialOffset = Convert.ToDouble(cs.GetSetting("//RevisionBlocks/RevisionBlock[@name='" + blockName + "']", "initialOffset"));
double offset = Convert.ToDouble(cs.GetSetting("//RevisionBlocks/RevisionBlock[@name='" + blockName + "']", "offset")); ;
foreach (ObjectId acObjId in acLayoutBlkTblRec)
{
DBObject acObject = acTrans.GetObject(acObjId, OpenMode.ForWrite);
//get the highest of the existing blocks
if (acObject.GetType().ToString() == "Autodesk.AutoCAD.DatabaseServices.BlockReference")
{
BlockReference acBlockRef = acObject as BlockReference;
if (acBlockRef.Name == blockName)
if (acBlockRef.Position.Y > yValue) yValue = acBlockRef.Position.Y;
}
}
//if no current blocks, get a new insertion
if (yValue == 0) yValue = initialOffset;
//increment for new block
yValue = yValue + offset;
//Get a point for insertion
Autodesk.AutoCAD.Geometry.Point3d p3d = new Autodesk.AutoCAD.Geometry.Point3d(0, yValue, 0);
BlockReference acRevBlockRef = new BlockReference(p3d, acBlkTbl[blockName]);
acRevBlockRef.ScaleFactors = new Autodesk.AutoCAD.Geometry.Scale3d(1);
acRevBlockRef.SetDatabaseDefaults();
acLayoutBlkTblRec.AppendEntity(acRevBlockRef);
acTrans.AddNewlyCreatedDBObject(acRevBlockRef, true);
AttributeCollection attColl = acRevBlockRef.AttributeCollection;
foreach (ObjectId attObjectId in attColl)
{
AttributeReference attRef = (AttributeReference)acTrans.GetObject(attObjectId, OpenMode.ForWrite);
foreach (ACADInterface.Attribute at in attributes)
if (at.Name == attRef.Tag)
attRef.TextString = at.Value;
}
return;
}
The block does get added to all layouts and model space, but in the code it doesnt find any attributes.
And in Autocad if I try attedit on the block, it also has not editable attributes.
But if I add the block in Acad via Insert, attributes edit fine, so I'm reasonably certian its not an issue with the block definition.
I think its something pretty simple I'm missing, but cant see it.
the following code adds it to any layout required.
private static void ProcessSpaceForRevBlockAttributeUpdate(Layout acLayout, Transaction acTrans, string blockName, List
{
BlockTable acBlkTbl = acTrans.GetObject(acLayout.Database.BlockTableId,
OpenMode.ForRead) as BlockTable;
BlockTableRecord acLayoutBlkTblRec = acTrans.GetObject(acLayout.BlockTableRecordId, OpenMode.ForWrite) as BlockTableRecord;
//Get any offset values from Configuration.
double yValue = 0;
double initialOffset = Convert.ToDouble(cs.GetSetting("//RevisionBlocks/RevisionBlock[@name='" + blockName + "']", "initialOffset"));
double offset = Convert.ToDouble(cs.GetSetting("//RevisionBlocks/RevisionBlock[@name='" + blockName + "']", "offset")); ;
foreach (ObjectId acObjId in acLayoutBlkTblRec)
{
DBObject acObject = acTrans.GetObject(acObjId, OpenMode.ForWrite);
//get the highest of the existing blocks
if (acObject.GetType().ToString() == "Autodesk.AutoCAD.DatabaseServices.BlockReference")
{
BlockReference acBlockRef = acObject as BlockReference;
if (acBlockRef.Name == blockName)
if (acBlockRef.Position.Y > yValue) yValue = acBlockRef.Position.Y;
}
}
//if no current blocks, get a new insertion
if (yValue == 0) yValue = initialOffset;
//increment for new block
yValue = yValue + offset;
//Get a point for insertion
Autodesk.AutoCAD.Geometry.Point3d p3d = new Autodesk.AutoCAD.Geometry.Point3d(0, yValue, 0);
BlockReference acRevBlockRef = new BlockReference(p3d, acBlkTbl[blockName]);
acRevBlockRef.ScaleFactors = new Autodesk.AutoCAD.Geometry.Scale3d(1);
acRevBlockRef.SetDatabaseDefaults();
acLayoutBlkTblRec.AppendEntity(acRevBlockRef);
acTrans.AddNewlyCreatedDBObject(acRevBlockRef, true);
AttributeCollection attColl = acRevBlockRef.AttributeCollection;
foreach (ObjectId attObjectId in attColl)
{
AttributeReference attRef = (AttributeReference)acTrans.GetObject(attObjectId, OpenMode.ForWrite);
foreach (ACADInterface.Attribute at in attributes)
if (at.Name == attRef.Tag)
attRef.TextString = at.Value;
}
return;
}
The block does get added to all layouts and model space, but in the code it doesnt find any attributes.
And in Autocad if I try attedit on the block, it also has not editable attributes.
But if I add the block in Acad via Insert, attributes edit fine, so I'm reasonably certian its not an issue with the block definition.
I think its something pretty simple I'm missing, but cant see it.