- 积分
- 150
- 明经币
- 个
- 注册时间
- 2015-8-26
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
c#开发插件 出现 错误 5 “Autodesk.AutoCAD.DatabaseServices.MText”不包含“TextStyle”的定义,并且找不到可接受类型为“Autodesk.AutoCAD.DatabaseServices.MText”的第一个参数的扩展方法“TextStyle”(是否缺少 using 指令或程序集引用?) 代码:
//控制文字长度
[CommandMethod("hg11")]
public void wztkdbl()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
ed.WriteMessage("\n通过修改文字高宽比控制文字长度");
//Wch2.FilterType dbmextType = Wch2.FilterType.Text;
//Wch2.FilterType mtextType = Wch2.FilterType.MText;
Wch2.FilterType[] Types = new Wch2.FilterType[3];
Types[0] = Wch2.FilterType.Text;
Types[1] = Wch2.FilterType.MText;
Types[2] = Wch2.FilterType.Dimension;
DBObjectCollection EntityCollection = Wch2.GetS(Types);
if (EntityCollection == null)
return;
PromptDistanceOptions xzkd = new PromptDistanceOptions("\n文字限制宽度");
PromptDoubleResult kdjg = ed.GetDistance(xzkd);
if (kdjg.Status != PromptStatus.OK)
return;
double k = kdjg.Value;
using (Transaction tran = db.TransactionManager.StartTransaction())
{
foreach (DBObject odb in EntityCollection)
{
ObjectId odbid = odb.Id;
Entity ent = tran.GetObject(odbid, OpenMode.ForWrite) as Entity;
if (ent is DBText)
{
DBText dbt = (DBText)ent;
TextStyleTableRecord tstr = (TextStyleTableRecord)tran.GetObject(dbt.TextStyle, OpenMode.ForRead);//读取当前字体
double zkbl = tstr.XScale;//当前字体高宽比
double cd;
double jd = dbt.Rotation;
int n = 0;
do
{
dbt.WidthFactor = zkbl - 0.01 * n;
dbt.Rotation = 0;
Extents3d wzd = dbt.GeometricExtents;
cd = wzd.MaxPoint.X - wzd.MinPoint.X;
n++;
} while (cd > k);
dbt.Rotation = jd;
}
if (ent is MText)
{
MText mtt = (MText)ent;
TextStyleTableRecord tstr = (TextStyleTableRecord)tran.GetObject(mtt.TextStyle, OpenMode.ForRead);//读取当前字体
double zkbl = tstr.XScale;//当前字体高宽比
double zk;
string wznr = mtt.Text;
int n = 0;
do
{
mtt.Contents = "{\\W" + (zkbl - n * 0.01) + ";" + wznr + "}";
zk = mtt.ActualWidth;
n++;
} while (zk > k);
}
if (ent is Dimension)
{
Dimension dim = (Dimension)ent;
MText mte = new MText();
mte.TextStyle = dim.Dimtxsty;
mte.TextHeight = dim.Dimtxt;
string str;
string str1;
string str2;
string str3;
TextStyleTableRecord tstr = (TextStyleTableRecord)tran.GetObject(mte.TextStyle, OpenMode.ForRead);//读取当前字体
double zkbl = tstr.XScale;//当前字体高宽比
if (dim.DimensionText != "" && !dim.DimensionText.Contains("<>"))
{
str = dim.DimensionText;
mte.Contents = str;
str2 = mte.Text;
}
else
{
double bznr = Math.Round(dim.Measurement, dim.Dimdec);
str = bznr.ToString();
mte.Contents = str;
str2 = "<>";
}
str1 = mte.Text;
double zk;
int n = 0;
do
{
str3 = "{\\W" + (zkbl - n * 0.01) + ";";
mte.Contents = str3 + str1 + "}";
zk = mte.ActualWidth;
n++;
} while (zk > k);
dim.DimensionText = str3 + str2 + "}";
}
}
|
|