- [CommandMethod("t4")]
- public void Test4()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- SelectionFilter selectFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "Text") });
- PromptSelectionOptions selectOptions = new PromptSelectionOptions();
- selectOptions.MessageForAdding="\n框选求和文字";
- selectOptions.MessageForRemoval = "\n框选求和文字";
- PromptSelectionResult selectResult = ed.GetSelection(selectOptions, selectFilter);
- if (selectResult.Status != PromptStatus.OK) return;
- Transaction tr=doc.TransactionManager.StartTransaction();
- double sumNumber = 0;
- using (tr)
- {
- foreach (ObjectId textId in selectResult.Value.GetObjectIds())
- {
- DBText selectText = tr.GetObject(textId, OpenMode.ForRead) as DBText;
- string selectString = selectText.TextString;
- System.Text.RegularExpressions.MatchCollection mc =System.Text.RegularExpressions.Regex.Matches(selectString, @"\d+\.\d+|\d+");
- if (mc.Count > 0)
- {
- foreach (System.Text.RegularExpressions.Match m in mc)
- {
- sumNumber += double.Parse(m.ToString());
- }
- }
- }
- ed.WriteMessage(sumNumber.ToString());
- }
- }
|