C# 使用C创建MleaderStyle Autocad#
我已在C#中创建了MleaderStyle。没有错误,但在运行它时,出现以下错误。以下是用于此目的的部分代码以及autocad显示的错误 MLeaderStyle dst= (MLeaderStyle)acTrans.GetObject( acCurDb.DimStyleTableId, OpenMode.ForWrite) 错误强> 无法强制转换类型为的对象 “Autodesk.Autocad.DataBaseServices.DimStyleTable”至“Autodesk.Autocad.DataBaseServices.MleaderStyle” MLeaderStyle dst=(MLeaderStyle)acTrans.GetObject( acCurDb.DimStyleTableId,OpenMode.ForWrite) 不能将DimStyleTable强制转换为MLeaderStyle,必须使用其中一个MLeaderStyle构造函数来创建新的构造函数C# 使用C创建MleaderStyle Autocad#,c#,plugins,autocad,C#,Plugins,Autocad,我已在C#中创建了MleaderStyle。没有错误,但在运行它时,出现以下错误。以下是用于此目的的部分代码以及autocad显示的错误 MLeaderStyle dst= (MLeaderStyle)acTrans.GetObject( acCurDb.DimStyleTableId, OpenMode.ForWrite) 错误 无法强制转换类型为的对象 “Autodesk.Autocad.DataBaseServices.DimStyleTable”至“Autodesk.Autocad.Da
using (var tr = db.TransactionManager.StartTransaction())
{
// the newly created MText have to be disposed after using
using (MText mt = new MText())
{
mt.Contents = text;
// check if the MLeaderStyle dictionary does not already contains a style named "MyLeaderStyle"
DBDictionary mlStyles = (DBDictionary)tr.GetObject(db.MLeaderStyleDictionaryId, OpenMode.ForWrite);
if (!mlStyles.Contains("MyLeaderStyle"))
{
// create a new instance of MLeaderStyle (you can use the overloaded ctor to copy an existing style)
MLeaderStyle dst = new MLeaderStyle();
dst.ArrowSymbolId = ObjectId.Null;
dst.ArrowSize = 0.18 * scale;
dst.ContentType = 0;
dst.DefaultMText = mt;
dst.LandingGap = gap;
dst.EnableBlockRotation = true;
dst.MaxLeaderSegmentsPoints = 2;
// add the new MLeaderStyle to the database
dst.PostMLeaderStyleToDb(db, "MyLeaderStyle");
tr.AddNewlyCreatedDBObject(dst, true);
}
}
tr.Commit();
}
using (var tr = db.TransactionManager.StartTransaction())
{
// the newly created MText have to be disposed after using
using (MText mt = new MText())
{
mt.Contents = text;
// check if the MLeaderStyle dictionary does not already contains a style named "MyLeaderStyle"
DBDictionary mlStyles = (DBDictionary)tr.GetObject(db.MLeaderStyleDictionaryId, OpenMode.ForWrite);
if (!mlStyles.Contains("MyLeaderStyle"))
{
// create a new instance of MLeaderStyle (you can use the overloaded ctor to copy an existing style)
MLeaderStyle dst = new MLeaderStyle();
dst.ArrowSymbolId = ObjectId.Null;
dst.ArrowSize = 0.18 * scale;
dst.ContentType = 0;
dst.DefaultMText = mt;
dst.LandingGap = gap;
dst.EnableBlockRotation = true;
dst.MaxLeaderSegmentsPoints = 2;
// add the new MLeaderStyle to the database
dst.PostMLeaderStyleToDb(db, "MyLeaderStyle");
tr.AddNewlyCreatedDBObject(dst, true);
}
}
tr.Commit();
}