已解决如何获取当前数据库中的所有表格样式,并删除其中除了指定的样式ID或样式名外
本帖最后由 作者 于 2009-12-18 12:55:03 编辑已解决如何获取当前数据库中的所有表格样式,并删除其中除了指定的样式ID或样式名外的所有表格样式?RT <p>Database.TableStyleDictionaryId Property</p><p></p><p class="Element10">Accesses the object ID of the table style dictionary in named object dictionary.</p> <p>DBDictionary dbd = (DBDictionary)trans.GetObject(db.TableStyleDictionaryId, OpenMode.ForWrite);用这个吗?</p><p>这个的话该如何遍历呢?比如我要删除数据库中除了Id为 000 的TableStyle之外的所有TableStyle改怎么写C#代码</p> 组字典用过么,用法应该是类似的 汗,提问的时候着急了,结果问题问错了,我要问的是怎么获取所有表格样式,获取之后如何遍历,查询出其中与所给样式相同的ID,并把其余的删掉;用GetAt()方法只是获取ID,改如何遍历呢 组的遍历,参考下吧
foreach (DBDictionaryEntry obj in _gd)
{
Group g =
(Group)_tr.GetObject(
obj.Value,
OpenMode.ForRead,
false);
}
3Q已经解决了 附上代码
#region 删除图纸上多余的表格样式
/// <summary>
/// 删除图纸上多余的表格样式
/// </summary>
private void DelOtioseTableStyle()
{
List<string> idList = new List<string>();
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
TypedValue[] tableFilter = new TypedValue[] {
new TypedValue((int)DxfCode.Start,"ACAD_TABLE")
};
SelectionFilter filter = new SelectionFilter(tableFilter);
PromptSelectionResult res = ed.SelectAll(filter);
SelectionSet sSet = res.Value;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
ObjectId[] ids = sSet.GetObjectIds();
foreach (ObjectId id in ids)
{
Table table = (Table)trans.GetObject(id, OpenMode.ForWrite);
TableStyle ts = (TableStyle)trans.GetObject(table.TableStyle,OpenMode.ForWrite);
idList.Add(ts.Name);
}
DBDictionary dbd = (DBDictionary)trans.GetObject(db.TableStyleDictionaryId, OpenMode.ForWrite);
foreach (DBDictionaryEntry obj in dbd)
{
TableStyle ts = (TableStyle)trans.GetObject(obj.Value,OpenMode.ForWrite);
string s = ts.Name;
bool flag = true;
foreach (string name in idList)
{
if (s == name)
{
flag = false;
break;
}
}
if (flag)
{
if (s.Length > 21 && s.Substring(0, 21) == "GYCAD_Bom_TableStyle_")
{
dbd.Remove(s);
}
}
}
}
catch
{ }
trans.Commit();
trans.Dispose();
}
}
#endregion
页:
[1]