Beispiel #1
0
        private void logic()
        {
            List <string> wrongNames = new List <string>();

            _Db.LayerTable lt = _c.trans.GetObject(_c.db.LayerTableId, _Db.OpenMode.ForRead) as _Db.LayerTable;

            foreach (_Db.ObjectId layerId in lt)
            {
                _Db.LayerTableRecord layer = _c.trans.GetObject(layerId, _Db.OpenMode.ForWrite) as _Db.LayerTableRecord;

                if (!layer.IsPlottable)
                {
                    if (ingoreLayers.Contains(layer.Name))
                    {
                        continue;
                    }

                    wrongNames.Add(layer.Name);
                }
            }

            write("No print layer count: " + wrongNames.Count.ToString());
            foreach (string name in wrongNames)
            {
                write(" - " + name);
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
            public LayerInfo(_AcDb.LayerTableRecord ltr, _AcDb.Transaction trans)
            {
                _Ltr           = ltr;
                OldLayer       = ltr.Name;
                NewLayer       = "";
                _ColorO        = ltr.Color;
                Color          = ColorToString();
                _LineTypeO     = ltr.LinetypeObjectId;
                _LineType      = GetNameFromLinetypeOid(ltr.LinetypeObjectId, trans);
                _LineWeightO   = ltr.LineWeight;
                LineWeight     = LineWeightToString();
                _TransparencyO = ltr.Transparency;
                if (_TransparencyO != default(_AcCm.Transparency))
                {
                    Transparency = AlphaToTransparenz(_TransparencyO.Alpha).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    Transparency = string.Empty;
                }
                if (ltr.IsPlottable)
                {
                    Plot = "Ja";
                }
                else
                {
                    Plot = "Nein";
                }

                Description = ltr.Description;
            }
Beispiel #4
0
            internal void ModifyLayer(_AcDb.LayerTableRecord ltr, _AcDb.Transaction trans, _AcDb.Database db)
            {
                if (_ColorO != null)
                {
                    ltr.Color = _ColorO;
                }

                if (_LineTypeO != null && !_LineTypeO.IsNull)
                {
                    ltr.LinetypeObjectId = _LineTypeO;
                }

                ltr.LineWeight = _LineWeightO;

                if (_TransparencyO != null && _TransparencyO != default(_AcCm.Transparency))
                {
                    ltr.Transparency = _TransparencyO;
                }
                else
                {
                    ltr.Transparency = default(_AcCm.Transparency);
                }

                if (!string.IsNullOrEmpty(Description))
                {
                    ltr.Description = Description;
                }

                ltr.IsPlottable = _IsPlottable;
            }
Beispiel #5
0
        private List <LayerInfo> GetLayerInfos()
        {
            List <LayerInfo> linfos = new List <LayerInfo>();
            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;
                    foreach (var ltrOid in layTb)
                    {
                        _AcDb.LayerTableRecord ltr = (_AcDb.LayerTableRecord)trans.GetObject(ltrOid, _AcDb.OpenMode.ForRead);
                        linfos.Add(new LayerInfo(ltr, trans));
                    }
                }
                finally
                {
                    trans.Commit();
                }
            }

            return(linfos);
        }
Beispiel #6
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);
                }
            }
        }
Beispiel #7
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();
                }
            }
        }
Beispiel #8
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();
                }
            }
        }
Beispiel #9
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);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Bulk-Befehl
        /// </summary>
        /// <param name="dwgFiles"></param>
        /// <returns></returns>
        private List <LayerInfo> GetLayerInfos(List <string> dwgFiles)
        {
            var layDict = new Dictionary <string, LayerInfo>();

            foreach (var fileName in dwgFiles)
            {
                int layerCount      = 0;
                int layerAddedCount = 0;
                var db = new _AcDb.Database(false, true);
                using (db)
                {
                    try
                    {
                        db.ReadDwgFile(fileName, System.IO.FileShare.Read, allowCPConversion: false, password: "");
                    }
                    catch (Exception ex)
                    {
                        log.WarnFormat("Fehler beim Öffnen der Zeichnung '{0}'!{1}", fileName, ex.Message);
                        continue;
                    }
                    using (_AcDb.Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            _AcDb.LayerTable layTb = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForRead) as _AcDb.LayerTable;
                            foreach (var ltrOid in layTb)
                            {
                                _AcDb.LayerTableRecord ltr = (_AcDb.LayerTableRecord)trans.GetObject(ltrOid, _AcDb.OpenMode.ForRead);
                                string layNameUC           = ltr.Name.ToUpperInvariant();
                                layerCount++;
                                if (!layDict.ContainsKey(layNameUC))
                                {
                                    layDict.Add(layNameUC, new LayerInfo(ltr, trans));
                                    layerAddedCount++;
                                }
                            }
                        }
                        finally
                        {
                            trans.Commit();
                        }
                    }
                }
                log.InfoFormat("{0}: {1} von {2} Layer hinzugefügt.", fileName, layerAddedCount, layerCount);
            }

            var linfos = layDict.Values.ToList();

            return(linfos);
        }
Beispiel #11
0
        private void createLayer(string layerName, _Db.LayerTable layerTable)
        {
            _Db.LayerTableRecord newLayer = new _Db.LayerTableRecord();

            newLayer.Name       = layerName;
            newLayer.Color      = _Cm.Color.FromColorIndex(_Cm.ColorMethod.None, 80);
            newLayer.LineWeight = _Db.LineWeight.LineWeight013;

            _Db.ObjectId layerId = layerTable.Add(newLayer);
            _c.trans.AddNewlyCreatedDBObject(newLayer, true);

            newLayer.Description = "Kõik mõõtjooned";
            _Db.LinetypeTable lineTypes = _c.trans.GetObject(_c.db.LinetypeTableId, _Db.OpenMode.ForWrite) as _Db.LinetypeTable;
            if (lineTypes.Has("Continuous") == true)
            {
                newLayer.LinetypeObjectId = lineTypes["Continuous"];
            }
        }
Beispiel #12
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);
     }
 }
Beispiel #13
0
        private void createLayer(string layerName, _Db.LayerTable layerTable)
        {
            _Db.LayerTableRecord newLayer = new _Db.LayerTableRecord();

            newLayer.Name = layerName;
            if (layerName == "Armatuur")
            {
                newLayer.Color = _Cm.Color.FromColorIndex(_Cm.ColorMethod.None, 30);
            }
            if (layerName == "_AUTO_KONTROLL_")
            {
                newLayer.Color = _Cm.Color.FromColorIndex(_Cm.ColorMethod.None, 1);
            }
            else
            {
                newLayer.Color = _Cm.Color.FromColorIndex(_Cm.ColorMethod.None, 6);
            }

            _Db.ObjectId layerId = layerTable.Add(newLayer);
            _c.trans.AddNewlyCreatedDBObject(newLayer, true);
        }
Beispiel #14
0
        private static void ImportNestedFilters(

            _AcLm.LayerFilter srcFilter,
            _AcLm.LayerFilter destFilter,
            _AcDb.Database srcDb,
            _AcDb.Database destDb,
            bool copyLayer,
            _AcEd.Editor ed)
        {
            using (_AcDb.Transaction tr = srcDb.TransactionManager.StartTransaction())
            {
                _AcDb.LayerTable lt = tr.GetObject(srcDb.LayerTableId, _AcDb.OpenMode.ForRead, false) as _AcDb.LayerTable;

                foreach (_AcLm.LayerFilter sf in srcFilter.NestedFilters)
                {
                    _AcDb.IdMapping idmap = new _AcDb.IdMapping();
                    if (copyLayer)
                    {
                        // Get the layers to be cloned to the dest db.
                        // Only those that are pass the filter
                        _AcDb.ObjectIdCollection layerIds = new _AcDb.ObjectIdCollection();
                        foreach (_AcDb.ObjectId layerId in lt)
                        {
                            _AcDb.LayerTableRecord ltr = tr.GetObject(layerId, _AcDb.OpenMode.ForRead, false) as _AcDb.LayerTableRecord;
                            if (sf.Filter(ltr))
                            {
                                layerIds.Add(layerId);
                            }
                        }

                        // clone the layers to the dest db
                        if (layerIds.Count > 0)
                        {
                            srcDb.WblockCloneObjects(
                                layerIds,
                                destDb.LayerTableId,
                                idmap,
                                _AcDb.DuplicateRecordCloning.Replace,
                                false);
                        }
                    }

                    // Find if a destination database already
                    // has a layer filter with the same name
                    _AcLm.LayerFilter df = null;
                    foreach (_AcLm.LayerFilter f in destFilter.NestedFilters)
                    {
                        if (f.Name.Equals(sf.Name))
                        {
                            df = f;
                            break;
                        }
                    }

                    if (df == null)
                    {
                        if (sf is _AcLm.LayerGroup)
                        {
                            // create a new layer filter group
                            // if nothing found
                            _AcLm.LayerGroup sfgroup = sf as _AcLm.LayerGroup;
                            _AcLm.LayerGroup dfgroup = new _AcLm.LayerGroup();
                            ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nImportiere Layerfilter-Gruppe {0}.", sf.Name));
                            dfgroup.Name = sf.Name;
                            df           = dfgroup;
                            if (copyLayer)
                            {
                                _AcLm.LayerCollection lyrs = sfgroup.LayerIds;
                                foreach (_AcDb.ObjectId lid in lyrs)
                                {
                                    if (idmap.Contains(lid))
                                    {
                                        _AcDb.IdPair idp = idmap[lid];

                                        dfgroup.LayerIds.Add(idp.Value);
                                    }
                                }
                            }
                            destFilter.NestedFilters.Add(df);
                        }
                        else
                        {
                            // create a new layer filter
                            // if nothing found
                            ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nImportiere Layerfilter {0}.", sf.Name));
                            df                  = new _AcLm.LayerFilter();
                            df.Name             = sf.Name;
                            df.FilterExpression = sf.FilterExpression;
                            destFilter.NestedFilters.Add(df);
                        }
                    }
                    // Import other filters
                    ImportNestedFilters(sf, df, srcDb, destDb, copyLayer, ed);
                }
                tr.Commit();
            }
        }