Issue With Attribute Visibility
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Guys i am having a weird problem With a Blocks Attribute.
at default a Certain Attribute is not visible because of the field being blank. i have a program with a checkbox to make the Attribute Visible. This seems to work fine only when the Battman command has been used on that drawing before, otherwise the checkbox doesn't work and does not activate the visibility state of that attribute. this is strange i am not sure if there is a system variable that also has to be changed. can someone please give some input?
Here is a snip of my code:
Class:
private void SetAttributeVisibility(Transaction tr, BlockReference blockRef, string attributeName, bool isVisible)
{
foreach (ObjectId attId in blockRef.AttributeCollection)
{
AttributeReference attRef = tr.GetObject(attId, OpenMode.ForWrite) as AttributeReference;
if (attRef != null && attRef.Tag == attributeName)
{
attRef.Visible = isVisible;
break;
}
}
}
public void HandleCheckboxVisibility(CheckBox checkBox, params string[] attributeNames)
{
// Get the visibility state based on the checkbox checked status
bool isVisible = checkBox.Checked;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (DocumentLock docLock = doc.LockDocument())
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
if (bt != null)
{
BlockTableRecord layout = tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForRead) as BlockTableRecord;
if (layout != null)
{
foreach (ObjectId objId in layout)
{
if (objId.ObjectClass.Name == "AcDbBlockReference")
{
BlockReference blockRef = tr.GetObject(objId, OpenMode.ForWrite) as BlockReference;
if (blockRef != null && blockRef.Name == BlockName)
{
foreach (string attributeName in attributeNames)
{
SetAttributeVisibility(tr, blockRef, attributeName, isVisible);
}
}
}
}
}
else
{
MessageBox.Show("The Titleblock is not loaded. Please ensure the Titleblock is loaded and try again.", "Titleblock Not Loaded", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
}
}
Civil 3D Certified Professional
Link copied