public static void SetPropertyFromPropertyTable(Transaction tr, BlockReference blockRef, string value, string propertyName = "Lang")
{
if (blockRef == null) return;
if (value == null) return;
try
{
var blockDef = tr.GetObject(blockRef.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
DBDictionary extDic = tr.GetObject(blockDef.ExtensionDictionary, OpenMode.ForRead) as DBDictionary;
// Открываем словарь ENHANCEDBLOCK
Autodesk.AutoCAD.Internal.DatabaseServices.EvalGraph graph = tr.GetObject(extDic.GetAt("ACAD_ENHANCEDBLOCK"), OpenMode.ForRead) as EvalGraph;
var nodeIds = graph.GetAllNodes();
foreach (uint nodeId in nodeIds)
{
DBObject node = graph.GetNode(nodeId, OpenMode.ForRead, tr);
if (!(node is BlockPropertiesTable)) continue;
var table = node as BlockPropertiesTable;
Dictionary<string, string> props = new Dictionary<string, string>();
for (int i = 0; i < table.Rows.Count; i++)
{
var par = table.Columns[0].Parameter;
if (par == null)
break;
if (par.Name != propertyName)
break;
var tapedValue = (TypedValue)table.Rows[i][0].AsArray().GetValue(0); //RU-EN
if (tapedValue.TypeCode == (int)DxfCode.Text)
{
if (value != (string)tapedValue.Value)
{
continue;
}
}
for (int j = 1; j < table.Columns.Count; j++)
{
var lableAttrName = table.Columns[j].Parameter.Name;
var lableValTV = (TypedValue)table.Rows[i][j].AsArray().GetValue(0);
if (lableValTV.TypeCode == (int)DxfCode.Text)
{
var lableVal = (string)lableValTV.Value;
props.Add(lableAttrName, lableVal);
}
}
}
SetParam(tr, blockRef, props);
break;
}
}
catch(System.Exception ex)
{
//log
}
}