简体   繁体   English

.Net AutoCAD Mechanical OperateTransaction.Commit不起作用

[英].Net AutoCAD Mechanical OperateTransaction.Commit doesn't work

I create a new Layer and want user select an object which will belong the new Layer 我创建了一个新图层,希望用户选择一个属于新图层的对象

Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;

 using (Transaction OperateTransaction = acCurDb.TransactionManager.StartTransaction())
{
    using (LayerTable LayerList = OperateTransaction.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable)
    {
        LayerTableRecord NewLayer = new LayerTableRecord();
        NewLayer.Color = Autodesk.AutoCAD.Colors.Color.FromColor(Color.FromArgb(RandomNum.Next(255), RandomNum.Next(255), RandomNum.Next(255)));
        NewLayer.Name = NewLayerName;

        OperateTransaction.AddNewlyCreatedDBObject(NewLayer, true);
    }

    OperateTransaction.Commit();
}


PromptSelectionResult acSSPrompt = Application.DocumentManager.MdiActiveDocument.Editor.GetSelection();

 if (acSSPrompt.Status == PromptStatus.OK)
 {
     //... Assign object to new layer
 }

In AutoCAD 2013 & AutoCAD 2013 it work, when user select object he can see the new layer in AutoCAD, but in AutoCAD Mechanical 2016 it doesn't work, unless my .Net program is close. 在AutoCAD 2013和AutoCAD 2013中,当用户选择对象时,他可以在AutoCAD中看到新图层,但在AutoCAD Mechanical 2016中它不起作用,除非我的.Net程序已关闭。

I think you forgot to add the layer to the layer Table: 我想你忘了将图层添加到图层表:

using (LayerTable LayerList = OperateTransaction.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite) as LayerTable)
{
    LayerTableRecord NewLayer = new LayerTableRecord();
    NewLayer.Color = Autodesk.AutoCAD.Colors.Color.FromColor(Color.FromArgb(RandomNum.Next(255), RandomNum.Next(255), RandomNum.Next(255)));
    NewLayer.Name = NewLayerName;

    //add this
    LayerList.Add(NewLayer)

    OperateTransaction.AddNewlyCreatedDBObject(NewLayer, true);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM