Exemplo n.º 1
0
        public static AcDb.ObjectId CreateLayer(String layerName)
        {
            AcDb.ObjectId layerId;
            AcDb.Database db = CurrentCAD.Database;

            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.LayerTable layerTable = (AcDb.LayerTable)tr.GetObject(db.LayerTableId, AcDb.OpenMode.ForWrite);

                if (layerTable.Has(layerName))
                {
                    layerId = layerTable[layerName];
                }
                else
                {
                    AcDb.LayerTableRecord layerTableRecord = new AcDb.LayerTableRecord
                    {
                        Name = layerName
                    };
                    layerId = layerTable.Add(layerTableRecord);
                    tr.AddNewlyCreatedDBObject(layerTableRecord, true);
                }
                tr.Commit();
            }
            return(layerId);
        }
Exemplo n.º 2
0
        private void CreateOrModifyLayer(LayerInfo layerInfo, _AcAp.Document doc, _AcDb.Database db, _AcDb.Transaction trans, _AcDb.LayerTable layTb)
        {
            if (layTb.Has(layerInfo.NewLayer))
            {
                var oid = layTb[layerInfo.NewLayer];
                _AcDb.LayerTableRecord ltr = (_AcDb.LayerTableRecord)trans.GetObject(oid, _AcDb.OpenMode.ForWrite);
                layerInfo.ModifyLayer(ltr, trans, db);
            }
            else
            {
                using (_AcDb.LayerTableRecord ltr = new _AcDb.LayerTableRecord())
                {
                    // Assign the layer a name
                    ltr.Name = layerInfo.NewLayer;

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


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

                    layerInfo.ModifyLayer(ltr, trans, db);
                }
            }
        }
Exemplo n.º 3
0
        private void LayerOnAndThaw(string layerName)
        {
            log.DebugFormat(CultureInfo.CurrentCulture, "Layer '{0}' ein und tauen.", layerName);
            var doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            var db  = doc.Database;

            using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction())
            {
                try
                {
                    _AcDb.LayerTable layTb = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForRead) as _AcDb.LayerTable;
                    if (layTb.Has(layerName))
                    {
                        var layId = layTb[layerName];
                        _AcDb.LayerTableRecord ltr = trans.GetObject(layId, _AcDb.OpenMode.ForRead) as _AcDb.LayerTableRecord;
                        log.InfoFormat("Taue und schalte Layer {0} ein.", ltr.Name);
                        ltr.UpgradeOpen();
                        ltr.IsOff = false;
                        if (string.Compare(_AcAp.Application.GetSystemVariable("CLAYER").ToString(), ltr.Name, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            ltr.IsFrozen = false;
                        }
                    }
                }
                finally
                {
                    trans.Commit();
                }
            }
        }
Exemplo n.º 4
0
        private void layerSetup()
        {
            _Db.LayerTable layerTable = _c.trans.GetObject(_c.db.LayerTableId, _Db.OpenMode.ForWrite) as _Db.LayerTable;

            if (!layerTable.Has(layerName))
            {
                createLayer(layerName, layerTable);
            }
        }
Exemplo n.º 5
0
        public void initLayers(List <string> layerNames)
        {
            _Db.LayerTable layerTable = _c.trans.GetObject(_c.db.LayerTableId, _Db.OpenMode.ForWrite) as _Db.LayerTable;

            foreach (string layerName in layerNames)
            {
                if (!layerTable.Has(layerName))
                {
                    createLayer(layerName, layerTable);
                }
            }
        }
Exemplo n.º 6
0
        public void initLayer(string layerName)
        {
            _Db.LayerTable layerTable = _c.trans.GetObject(_c.db.LayerTableId, _Db.OpenMode.ForWrite) as _Db.LayerTable;

            if (!layerTable.Has(layerName))
            {
                _Db.LayerTableRecord newLayer = new _Db.LayerTableRecord();
                newLayer.Name  = layerName;
                newLayer.Color = _Cm.Color.FromColorIndex(_Cm.ColorMethod.None, 1);

                _Db.ObjectId layerId = layerTable.Add(newLayer);
                _c.trans.AddNewlyCreatedDBObject(newLayer, true);
            }
        }
Exemplo n.º 7
0
        public static bool MaketLayer(String layerName)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.LayerTable layerTable = (AcDb.LayerTable)tr.GetObject(db.LayerTableId, AcDb.OpenMode.ForWrite);

                if (layerTable.Has(layerName))
                {
                    db.Clayer = layerTable[layerName];
                    tr.Commit();
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 8
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);
     }
 }