cad文字求和 如何用c#来实现
cad文字求和 如何用c#来实现 哪位大哥能给点提示?谢谢了 读取内容,转换成数字,然后计算,然后写入文字中 能给点代码提示么?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());
}
} 可以把你要求和的文字放在一个图层内,然后对这个图层内的所有文字进行求和。 System.Text.RegularExpressions.MatchCollection mc =System.Text.RegularExpressions.Regex.Matches(selectString, @"\d+\.\d+|\d+");
这句话怎么理解? 正则表达式
页:
[1]