Пример #1
0
        private static bool Correction(_AcDb.Entity ent, string suffix, bool isContinuous)
        {
            if (ent.Layer.EndsWith(suffix, StringComparison.OrdinalIgnoreCase))
            {
                return(false);                                                                // already handled
            }
            var ltr = (_AcDb.LayerTableRecord)_Tr.GetObject(ent.LayerId, _AcDb.OpenMode.ForRead);
            var li  = new LayerInfo(ltr, _Tr);

            if (isContinuous)
            {
                li.NewLineType = "Continuous";
            }
            li.NewLayer = ent.Layer + suffix;
            li.CreateNewLayer();
            li.UnlockOldLayer();
            ent.UpgradeOpen();
            ent.Layer = li.NewLayer;



            //const string prefix = "Autodesk.AutoCAD.DatabaseServices.";
            //string typeString = ent.GetType().ToString();
            //if (typeString.Contains(prefix)) typeString = typeString.Substring(prefix.Length);
            //log.Info("\nEntity " + ent.ObjectId.ToString() + " of type " + typeString + " found on layer " +
            //                    ent.Layer + " with colour " + ent.Color.ToString());



            return(true);
        }
Пример #2
0
        private static bool CorrectionRest(_AcDb.Entity ent)
        {
            string suffix = "";

            var ltr = (_AcDb.LayerTableRecord)_Tr.GetObject(ent.LayerId, _AcDb.OpenMode.ForRead);
            var li  = new LayerInfo(ltr, _Tr);

            if (IsActuallyContintuous(ent, li))
            {
                suffix         = "_L";
                li.NewLineType = "Continuous";
            }
            else
            {
                suffix         = "_V";
                li.NewLineType = "Verdeckt";
            }

            if (ent.Layer.EndsWith(suffix, StringComparison.OrdinalIgnoreCase))
            {
                return(false);                                                                // already handled
            }
            li.NewLayer = ent.Layer + suffix;
            li.CreateNewLayer();

            li.UnlockOldLayer();
            ent.UpgradeOpen();
            ent.Layer      = li.NewLayer;
            ent.LinetypeId = LayerInfo.GetLinetypeFromName("ByLayer", _Tr, _Db);

            return(true);
        }
 protected void AssignTraits(_OdDb.Entity entity)
 {
     entity.UpgradeOpen();
     entity.Layer    = _layer;
     entity.Color    = _color;
     entity.Material = _material;
     entity.DowngradeOpen();
 }
Пример #4
0
        //[_AcTrx.CommandMethod("SaveView")]
        //public static void SaveView()
        //{
        //    Globs.SaveView("Test");
        //}
        //[_AcTrx.CommandMethod("RestoreView")]
        //public static void RestoreView()
        //{
        //    Globs.RestoreView("Test");
        //}

        //[_AcTrx.CommandMethod("TestMakeLayer")]
        public void TestMakeLayer()
        {
            var doc      = _AcAp.Application.DocumentManager.MdiActiveDocument;
            var db       = doc.Database;
            var layerOid = CreateNewLayer(doc, db);

            using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction())
            {
                _AcDb.BlockTable blkTable = (_AcDb.BlockTable)trans.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                foreach (var id in blkTable)
                {
                    _AcDb.BlockTableRecord btRecord = (_AcDb.BlockTableRecord)trans.GetObject(id, _AcDb.OpenMode.ForRead);
                    //if (!btRecord.IsLayout)
                    //{
                    //Access to the block (not model/paper space)
                    System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Block: {0}", btRecord.Name));
                    //MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nBlock name: {0}", btRecord.Name));

                    btRecord.UpgradeOpen();

                    foreach (var entId in btRecord)
                    {
                        _AcDb.Entity entity = (_AcDb.Entity)trans.GetObject(entId, _AcDb.OpenMode.ForRead);

                        entity.UpgradeOpen();

                        //Access to the entity
                        //MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nHandle: {0}", entity.Handle));
                        //System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Handle: {0}, Layer: {1}", entity.Handle, entity.Layer));
                        entity.Layer = "MyTest";

                        _AcDb.BlockReference block = entity as _AcDb.BlockReference;
                        if (block != null)
                        {
                            foreach (var att in block.AttributeCollection)
                            {
                                _AcDb.ObjectId           attOid = (_AcDb.ObjectId)att;
                                _AcDb.AttributeReference attrib = trans.GetObject(attOid, _AcDb.OpenMode.ForWrite) as _AcDb.AttributeReference;
                                if (attrib != null)
                                {
                                    //attrib.UpgradeOpen();
                                    attrib.Layer = "MyTest";
                                }
                            }
                        }
                    }

                    //}
                }

                // Layouts iterieren
                _AcDb.DBDictionary layoutDict = (_AcDb.DBDictionary)trans.GetObject(db.LayoutDictionaryId, _AcDb.OpenMode.ForRead);
                foreach (var loEntry in layoutDict)
                {
                    if (loEntry.Key.ToUpperInvariant() == "MODEL")
                    {
                        continue;
                    }
                    _AcDb.Layout lo = (_AcDb.Layout)trans.GetObject(loEntry.Value, _AcDb.OpenMode.ForRead, false);
                    if (lo == null)
                    {
                        continue;
                    }
                    System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Layout: {0}", lo.LayoutName));

                    _AcDb.BlockTableRecord btRecord = (_AcDb.BlockTableRecord)trans.GetObject(lo.BlockTableRecordId, _AcDb.OpenMode.ForRead);
                    foreach (var entId in btRecord)
                    {
                        _AcDb.Entity entity = (_AcDb.Entity)trans.GetObject(entId, _AcDb.OpenMode.ForRead);

                        entity.UpgradeOpen();

                        //Access to the entity
                        //MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nHandle: {0}", entity.Handle));
                        //System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Handle: {0}, Layer: {1}", entity.Handle, entity.Layer));
                        entity.Layer = "MyTest";

                        _AcDb.BlockReference block = entity as _AcDb.BlockReference;
                        if (block != null)
                        {
                            foreach (var att in block.AttributeCollection)
                            {
                                _AcDb.ObjectId           attOid = (_AcDb.ObjectId)att;
                                _AcDb.AttributeReference attrib = trans.GetObject(attOid, _AcDb.OpenMode.ForWrite) as _AcDb.AttributeReference;
                                if (attrib != null)
                                {
                                    //attrib.UpgradeOpen();
                                    attrib.Layer = "MyTest";
                                }
                            }
                        }
                    }
                }



                trans.Commit();
            }
        }