- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#region "Add prefix and suffix to the text or mtext multiply"
[CommandMethod("PSUF")]
public static void UpdateMultipleTexts()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
string pref = GetstringDflt(ed, "Enter a Prefix: ", "A-");
string suff = GetstringDflt(ed, "Enter a Suffix: ", "-B");
using (tr)
{
try
{
Entity ent;
PromptEntityResult per;
ObjectId id;
do
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect Text >>");
peo.SetRejectMessage("\nMust be selected a Text or Mtext only!");
peo.AddAllowedClass(typeof(DBText),false);
peo.AddAllowedClass(typeof(MText),false);
per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
{
break;
}
id = per.ObjectId;
ent = id.GetObject(OpenMode.ForRead) as Entity;
ed.WriteMessage("\nObject Selected:\t{0}", ent.GetRXClass().DxfName);
if ((!(ent is DBText)) && (!(ent is MText)))
{
ed.WriteMessage("\nNot a Text or MText");
continue;
}
DBText txt= ent as DBText;
if (txt!= null)
{
txt.UpgradeOpen();
string text = txt.TextString;
txt.TextString = pref + text+ suff;
txt.DowngradeOpen();
}
MText mtxt = ent as MText;
if (mtxt != null)
{
mtxt.UpgradeOpen();
string text = mtxt.Contents;
mtxt.Contents = pref + text + suff;
mtxt.DowngradeOpen();
}
db.TransactionManager.QueueForGraphicsFlush();
}
while (per.Status == PromptStatus.OK);
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage("\n" + ex.StackTrace + "\n" + ex.Message);
}
}
}
#region "Helpers"
public static string GetstringDflt(Editor ed, string msg, string dflt)
{
string answer = string.Empty;
PromptStringOptions pso = new PromptStringOptions("\n" + msg);
if (dflt != string.Empty)
{
pso.DefaultValue = dflt;
}
pso.AllowSpaces = true;
PromptResult pr = ed.GetString(pso);
if (pr.Status == PromptStatus.OK)
{
answer = pr.StringResult;
}
return answer;
}
#endregion
#endregion |
|