/// <summary>
/// 修改字体样式
/// </summary>
/// <param name="doc"></param>
/// <param name="textStyleName">字体样式名(STANDARD)</param>
/// <param name="cassLayersName">要改变的图层名</param>
public void SelectFont(Document doc, string textStyleName, List<string>
cassLayersName)
{
Transaction trans = null;
DocumentLock docLock = null;
try
{
trans = doc.TransactionManager.StartTransaction();
docLock = doc.LockDocument();
TextStyleTable st = trans.GetObject(doc.Database.TextStyleTableId,
OpenMode.ForRead) as TextStyleTable;
ObjectId styleID = ObjectId.Null;
//查询是否包含样式
if (st.Has(textStyleName))
{
styleID = st[textStyleName];
}
else
{
return;
}
Editor ed = doc.Editor;
foreach (string cassLayerName in cassLayersName)
{
TypedValue[] tvs = new TypedValue[]
{
new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.LayerName,cassLayerName),
new TypedValue((int)DxfCode.Start, "TEXT"),//单行文字,多行文字为MTEXT
new TypedValue((int)DxfCode.Operator, "and>")
};
SelectionFilter sf = new SelectionFilter(tvs);
PromptSelectionResult psr = ed.SelectAll(sf);
if (psr.Status == PromptStatus.OK)
{
SelectionSet SS = psr.Value;
ObjectId[] idArray = SS.GetObjectIds();
for (int i = 0; i < idArray.Length; i++)
{
DBText ent = trans.GetObject(idArray[i], OpenMode.ForWrite) as
DBText;
ent.TextStyleId = styleID;
}
}
}
trans.Commit();
}
catch (Exception ex)
{
}
finally
{
if (trans != null)
trans.Dispose();
if (docLock != null)
docLock.Dispose();
}
}
网友评论