MText使用相关
MText使用起来是有点复杂,特别是格式的解析下面是个生成堆叠的示例,也许有必要写个专门的格式解析类
效果图:
public enum ScriptType
{
Fraction,
Italic,
Tolerance
}
public static string MakeScript(string baseTextString, string superScript, string subScript, ScriptType scriptType, double scale)
{
string[] scriptTypStrings = new string[]{"/", "#", "^"};
return
string.Format
(
"\\A1;{0}{1}\\H{2:0.#}x;\\S{3}{4}{5};{6}",
baseTextString,
"{",
scale,
superScript,
scriptTypStrings[(int)scriptType],
subScript,
"}"
);
}
public static void Test()
{
var db = HostApplicationServices.WorkingDatabase;
var doc = Application.DocumentManager.GetDocument(db);
var ed = doc.Editor;
using(Transaction tr = db.TransactionManager.StartTransaction())
{
MText mt =
new MText
{
Contents = MakeScript("123", "+0.01", "-0.01", ScriptType.Tolerance, 0.5)
};
mt.SetDatabaseDefaults();
var btr = db.CurrentSpaceId.GetObject(OpenMode.ForWrite);
btr.AppendEntity(mt);
tr.AddNewlyCreatedDBObject(mt, true);
tr.Commit();
}
}
飞狐老师,能不能请教下,如何用C#实现最简单的文字替换~弄了半天弄不出来 2008去除格式,直接:
string content=MText.Text
MText.Text=content 在写入多行文本时,怎么让文本自动
? 另外贴两个去除MText格式的函数
public static string GetMTextContents(string str)
{
string[] strs =
str.Split(
new string[] { "\\\" },
StringSplitOptions.None);
for (int i = 0; istack = new Stack();
while (str.Length > 0)
{
int n = (str == '\\') ? 2 : 1;
if (n == 1 && str == '}')
{
Stack substack = new Stack();
while (stack.Peek() != "{")
{
substack.Push(stack.Pop());
}
stack.Pop();
Queue queue = GetRtfTextUnFormatString(substack);
while (queue.Count > 0)
{
stack.Push(queue.Dequeue());
}
}
else
{
stack.Push(str.Substring(0, n));
}
str = str.Substring(n);
}
string res = "";
foreach (string s in stack)
{
if (s.Length == 1)
{
res = s + res;
}
else
{
res = s.Substring(1) + res;
}
}
return res;
}
private static Queue
GetRtfTextUnFormatString(Stack stack)
{
Queue queue = new Queue();
while (stack.Count > 0)
{
string str = stack.Pop();
if (str.Length == 1)
{
queue.Enqueue(str);
}
else
{
switch (str.Substring(1).ToUpper())
{
case '\\':
case '{':
case '}':
case 'U':
queue.Enqueue(str);
break;
case 'A':
case 'C':
case 'F':
case 'H':
case 'Q':
case 'T':
case 'W':
while (stack.Pop() != ";") ;
break;
case 'S':
string s = "";
queue.Enqueue("(");
while ((s = stack.Peek()) != ";")
{
if (s == "^" || s == "#")
{
stack.Pop();
queue.Enqueue("/");
}
else
{
queue.Enqueue(stack.Pop());
}
if (stack.Count == 0)
{
break;
}
}
queue.Enqueue(")");
if (stack.Count > 0)
{
stack.Pop();
}
break;
}
}
}
return queue;
} 飞狐出品,必是精品!顶一个!呵呵!
请问版主,怎么设置MText的基点为文本中心呢?
mt.Attachment = AttachmentPoint.MiddleCenter;
如何判断已经存在的MText是否为斜体? 如果使用替换文字编辑器,则通过输入格式代码应用格式。可为文字加下划线、删除线和创建堆叠文字。用户可以修改颜色、字体和文字高度,还可以修改文字字符间距或增加字符本身宽度。要应用格式,请使用下表中列出的格式代码:
段落格式代码
格式代码
作用
输入...
要生成 ...
\0...\o
打开和关闭
下划线
Autodesk \OAutoCAD\o
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex001v.png
\L...\l
打开和关闭
下划线
Autodesk \LAutoCAD\l
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex002v.png
\~
插入不间断
空格
Autodesk AutoCAD\~LT
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex003v.png
\\
插入反斜杠
Autodesk \\AutoCAD
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex004v.png
\{...\}
插入左大括号和右大括号
Autodesk \{AutoCAD\}
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex005v.png
\Cvalue;
修改为
指定的颜色
Autodesk \C2;AutoCAD
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex006v.png
\ File name;
修改为
指定的字体文件
Autodesk \Ftimes; AutoCAD
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex007v.png
\Hvalue;
修改为
以图形单位表示的
指定文字高度
Autodesk \H2;AutoCAD
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex008v.png
\Hvaluex;
将文字高度修改为
当前样式文字高度的
数倍
Autodesk \H3x;AutoCAD
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex009v.png
\S...^...;
堆叠 \、# 或 ^ 符号后的文字
1.000\S+0.010^-0.000;
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex010v.png
\Tvalue;
调整字符之间的间距。有效值范围为字符间原始间距的 0.75 倍到字符间原始间距的 4 倍。
\T2;Autodesk
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex011v.png
\Qangle;
修改倾斜角度
\Q20;Autodesk
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex012v.png
\Wvalue;
修改宽度因子生成宽字
\W2;Autodesk
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex013v.png
\A
设置对齐方式值,有效值为:0、1、2
(底端对正、居中对正、顶端对正)
\A1;1\S1/2
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex014v.png
\P
结束段落
Autodesk\PAutoCAD
mkMSITStore:\Program%20Files\AutoCAD%202008\help\acad_aug.chm::/images/PTDCPM/Spago-AUG/Simplified_Chinese/mtex015v.png
大括号最多可以嵌套八层。
也可以使用控制代码添加特殊的字符,例如公差和标注符号。请参见 。
页:
[1]
2