原因
lisp语句:
(setvar "dimtxt" 123) ;控制标注高度
当我们使用这些标注样式变量,会令标注出现<样式替代>,那么怎么去掉这个东西呢?
放弃<样式替代>
[CommandMethod("DimRestoreAndEnable_1")]
public static void DimRestoreAndEnable_1()
{
Database db = HostApplicationServices.WorkingDatabase;//当前的数据库
Editor ed = Acap.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage(Environment.NewLine + "****惊惊连盒-恢复标注替代样式");
db.Action(tr =>
{
var oldDimData = tr.GetObject(db.Dimstyle, OpenMode.ForRead) as DimStyleTableRecord;
db.SetDimstyleData(oldDimData);
});
}
获取<样式替代>并且设置新标注样式
[CommandMethod("DimRestoreAndEnable_1")]
public static void DimRestoreAndEnable_1()
{
Database db = HostApplicationServices.WorkingDatabase;//当前的数据库
Editor ed = Acap.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage(Environment.NewLine + "****惊惊连盒-恢复标注替代样式");
db.Action(tr =>
{
var currentDimData = db.GetDimstyleData();//临时样式的数据
var dt = tr.GetObject(db.DimStyleTableId, OpenMode.ForRead) as DimStyleTable;
dt.UpgradeOpen();
currentDimData = currentDimData.Clone() as DimStyleTableRecord; //需要与否
currentDimData.Name += "我是新标注样式"; //同时存在的样式,名字冲突了并不会覆盖,后者会变成空白名字在面板上
dt.Add(currentDimData);
tr.AddNewlyCreatedDBObject(currentDimData, true);
db.SetDimstyleData(currentDimData);
});
}
应用<样式替代>到当前标注上
生成一个差不多名称的-->设定为当前-->删除-->再改名
直接删除<样式替代>宿主,那么它会跑到设定的当前标注上
[CommandMethod("DimRestoreAndEnable_1")]
public static void DimRestoreAndEnable_1()
{
Database db = HostApplicationServices.WorkingDatabase;//当前的数据库
Editor ed = Acap.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage(Environment.NewLine + "****惊惊连盒-恢复标注替代样式");
db.Action(tr =>
{
// 记录当前标注样式名称
string oldDim = null;
var oldDimData = tr.GetObject(db.Dimstyle, OpenMode.ForRead) as DimStyleTableRecord;
oldDim = oldDimData.Name;
// 生成标注样式
var currentDimData = db.GetDimstyleData();//临时样式的数据
currentDimData = currentDimData.Clone() as DimStyleTableRecord;
var dt = tr.GetObject(db.DimStyleTableId, OpenMode.ForRead) as DimStyleTable;
dt.UpgradeOpen();
dt.Add(currentDimData);
currentDimData.Name += "我是临时的临时标注"; //同时存在的样式,名字冲突了并不会覆盖,后者会变成空白名字在面板上
tr.AddNewlyCreatedDBObject(currentDimData, true);
db.SetDimstyleData(currentDimData);
db.Dimstyle = currentDimData.ObjectId;//设定为当前标注样式
// 删除旧的_这个时候一定不是当前
oldDimData.UpgradeOpen();
oldDimData.Erase();
oldDimData.Dispose();
//设置名字回去
if (oldDim != null)
{
currentDimData.Name = oldDim;
}
});
}
(完)