Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C创建MleaderStyle Autocad#_C#_Plugins_Autocad - Fatal编程技术网

C# 使用C创建MleaderStyle Autocad#

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

我已在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构造函数来创建新的构造函数

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();
}