我使用C#在autocad中创建了一个新的Mleader样式。我想在CAD中使用它;将Mleader风格分配给领导者。我不知道这个。我试过这段代码
public class test
{
public void drawMleaders(Transaction acTrans, Database acCurDb, Document acDoc, double scale, double gap, double[] pickPont)
{
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
//Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
DBDictionary mlStyles = (DBDictionary)acTrans.GetObject(acCurDb.MLeaderStyleDictionaryId, OpenMode.ForWrite);
// mlStyles.UpgradeOpen();
if (!mlStyles.Contains("MyLeaderStyle"))
{
MLeaderStyle dst = new MLeaderStyle();
// MText mt = new MText();
// mt.Contents = text;
//dst.Name="MyLeaderStyle";
dst.ArrowSymbolId = ObjectId.Null;
dst.ArrowSize = 0.5 * scale;
//dst.ContentType = 0;
//dst.DefaultMText = "";
dst.LandingGap = 0;
dst.EnableBlockRotation = true;
dst.MaxLeaderSegmentsPoints = 2;
dst.EnableLanding = true;
dst.PostMLeaderStyleToDb(acCurDb, "MyLeaderStyle");
acCurDb.MLeaderstyle = dst.ObjectId;
//dst1.Add(dst);
acTrans.AddNewlyCreatedDBObject(dst, true);
}
MLeader lead = new MLeader();
int i = lead.AddLeader();
lead.AddLeaderLine(i);
lead.AddFirstVertex(i, new Point3d(pickPont[0], pickPont[1], 0));
lead.AddLastVertex(i, new Point3d(pickPont[0] + 5, pickPont[1] + 5, 0));
//lead.MLeaderStyle = acCurDb.MLeaderstyle;
acBlkTblRec.AppendEntity(lead);
acTrans.AddNewlyCreatedDBObject(lead, true);
}
}
任何帮助都将不胜感激。
答案 0 :(得分:1)
您只需将leader.MLeaderStyle属性设置为MLeader样式ObjectId即可。 如果已存在,您可以从MLeaderStyle字典中获取它,如果创建它,可以从PostMLeaderStyleToDb返回值获取
ObjectId mlStyleId;
DBDictionary mlStyles = (DBDictionary)acTrans.GetObject(acCurDb.MLeaderStyleDictionaryId, OpenMode.ForRead);
if (mlStyles.Contains("MyLeaderStyle"))
{
mlStyleId = mlStyles.GetAt("MyLeaderStyle");
}
else
{
MLeaderStyle dst = new MLeaderStyle();
dst.ArrowSymbolId = ObjectId.Null;
dst.ArrowSize = 0.5 * scale;
dst.LandingGap = 0;
dst.EnableBlockRotation = true;
dst.MaxLeaderSegmentsPoints = 2;
dst.EnableLanding = true;
mlStyleId = dst.PostMLeaderStyleToDb(acCurDb, "MyLeaderStyle");
acTrans.AddNewlyCreatedDBObject(dst, true);
}
MLeader lead = new MLeader();
int i = lead.AddLeader();
lead.AddLeaderLine(i);
lead.AddFirstVertex(i, new Point3d(pickPont[0], pickPont[1], 0));
lead.AddLastVertex(i, new Point3d(pickPont[0] + 5, pickPont[1] + 5, 0));
lead.MLeaderStyle = mlStyleId;
acBlkTblRec.AppendEntity(lead);
acTrans.AddNewlyCreatedDBObject(lead, true);
acTrans.Commit();