예제 #1
0
        private _AcDb.ObjectId CreateNewLayer(_AcAp.Document doc, _AcDb.Database db)
        {
            using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction())
            {
                try
                {
                    string           layerName = "MyTest";
                    _AcDb.LayerTable layTb     = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForRead) as _AcDb.LayerTable;
                    using (_AcDb.LayerTableRecord acLyrTblRec = new _AcDb.LayerTableRecord())
                    {
                        // Assign the layer a name
                        acLyrTblRec.Name = layerName;

                        // Upgrade the Layer table for write
                        layTb.UpgradeOpen();


                        // Append the new layer to the Layer table and the transaction
                        layTb.Add(acLyrTblRec);
                        trans.AddNewlyCreatedDBObject(acLyrTblRec, true);


                        int transparenz = 10;

                        Byte alpha            = TransparenzToAlpha(transparenz);
                        _AcCm.Transparency tr = new _AcCm.Transparency(alpha);
                        acLyrTblRec.Transparency = tr;

                        _AcCm.Color col = _AcCm.Color.FromColorIndex(_AcCm.ColorMethod.ByColor, 2);
                        //_AcCm.Color col = _AcCm.Color.FromRgb(10, 20, 30);
                        acLyrTblRec.Color = col;

                        _AcDb.ObjectId ltOid = GetLinetypeFromName("Continuous", trans, db);
                        if (!ltOid.IsNull)
                        {
                            acLyrTblRec.LinetypeObjectId = ltOid;
                        }

                        _AcDb.LineWeight lw = _AcDb.LineWeight.LineWeight030;
                        acLyrTblRec.LineWeight = lw;

                        // ???
                        //acLyrTblRec.PlotStyleName = "hugo";

                        acLyrTblRec.Description = "My new Layer";

                        return(acLyrTblRec.ObjectId);
                    }
                }
                finally
                {
                    trans.Commit();
                }
            }
        }
예제 #2
0
 internal void CreateNewLayer()
 {
     _AcDb.LayerTable lt = (_AcDb.LayerTable)_Tr.GetObject(_Db.LayerTableId, _AcDb.OpenMode.ForRead, false);
     if (!lt.Has(_NewLayer))
     {
         _AcDb.LayerTableRecord ltRec = new _AcDb.LayerTableRecord();
         ltRec.Name = _NewLayer;
         lt.UpgradeOpen();
         lt.Add(ltRec);
         ltRec.LinetypeObjectId = GetLinetypeFromName(_NewLineType, _Tr, _Db);
         if (ltRec.LinetypeObjectId == default(_AcDb.ObjectId))
         {
             log.WarnFormat("Linientyp '{0}' existiert nicht und wird daher Layer '{1}' nicht zugeordnet!", _NewLineType, _NewLayer);
         }
         ltRec.Color = _ColorO;
         _Tr.AddNewlyCreatedDBObject(ltRec, true);
     }
 }