Beispiel #1
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 #2
0
        private void InsertBlocks(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs, List <_AcDb.ObjectId> _BlockRefs)
        {
            log.Debug("InsertBlocks");
            using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (var oid in allXrefsInMs)
                {
                    var br = tr.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                    if (br != null)
                    {
                        var bd = (_AcDb.BlockTableRecord)tr.GetObject(br.BlockTableRecord, _AcDb.OpenMode.ForRead);
                        if (bd.IsFromExternalReference)
                        {
                            string name    = bd.PathName;
                            var    dwgPath = _AcAp.Application.GetSystemVariable("DWGPREFIX").ToString();
                            if (System.IO.Path.IsPathRooted(bd.PathName))
                            {
                                log.DebugFormat(string.Format(CultureInfo.CurrentCulture, "Füge Block '{0}' ein. XREF-Pfad: '{1}'.", br.Name + "_AS_BLOCK", bd.PathName));
                                var blockOid = Plan2Ext.Globs.InsertDwg(bd.PathName, br.Position, br.Rotation, br.Name + "_AS_BLOCK");
                                _BlockRefs.Add(blockOid);
                            }
                            else
                            {
                                log.DebugFormat(string.Format(CultureInfo.CurrentCulture, "Füge Block '{0}' ein. XREF-Pfad: '{1}'.", br.Name + "_AS_BLOCK", System.IO.Path.GetFullPath(dwgPath + bd.PathName)));
                                var blockOid = Plan2Ext.Globs.InsertDwg(System.IO.Path.GetFullPath(dwgPath + bd.PathName), br.Position, br.Rotation, br.Name + "_AS_BLOCK");
                                _BlockRefs.Add(blockOid);
                            }
                        }
                    }
                }

                tr.Commit();
            }
        }
Beispiel #3
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 #4
0
        //Konstruktor (damit kein Default Konstruktor generiert wird!)
        protected MyLayer()
        {
            //Datenbank
            try {
                _AcDb.Database    db  = _AcDb.HostApplicationServices.WorkingDatabase;
                _AcDb.Transaction myT = db.TransactionManager.StartTransaction();

                using (DocumentLock dl = _AcAp.Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    _AcDb.LayerTable layT = (_AcDb.LayerTable)myT.GetObject(db.LayerTableId, OpenMode.ForRead);

                    //Layernamen in Liste schreiben
                    foreach (ObjectId id in layT)
                    {
                        LayerTableRecord ltr = (LayerTableRecord)(myT.GetObject(id, OpenMode.ForRead));

                        m_lsLayerTableRecord.Add(ltr);
                    }
                }

                myT.Commit();
                myT.Dispose();
            }
            catch { }
        }
Beispiel #5
0
        public static void DetachRasterImage(LandRasterImage landRastr)
        {
            AcDb.Database curDb = AcApp.DocumentManager.MdiActiveDocument.Database;
            using (AcDb.Transaction tr = curDb.TransactionManager.StartTransaction())
            {
                AcDb.RasterImageDef rasterDef;
                //bool bRasterDefCreated = false;
                AcDb.ObjectId imgDefId;

                AcDb.ObjectId imgDctID = AcDb.RasterImageDef.GetImageDictionary(curDb);
                if (imgDctID.IsNull)
                {
                    imgDctID = AcDb.RasterImageDef.CreateImageDictionary(curDb);
                }

                AcDb.DBDictionary imgDict = tr.GetObject(imgDctID, AcDb.OpenMode.ForWrite) as AcDb.DBDictionary;

                if (imgDict.Contains(landRastr.ImageName))
                {
                    imgDefId  = imgDict.GetAt(landRastr.ImageName);
                    rasterDef = tr.GetObject(imgDefId, AcDb.OpenMode.ForWrite) as AcDb.RasterImageDef;
                    if (rasterDef.IsLoaded)
                    {
                        rasterDef.Unload(true);
                        imgDict.Remove(landRastr.ImageName);
                    }
                }
                tr.Commit();
            }
        }
Beispiel #6
0
 private static void GetAllFgsAbzsAndRbs(string rbName, string fgLayer, string afLayer, _AcDb.Database db, _AcDb.Transaction tr, List <_AcDb.Entity> fgs, List <_AcDb.Entity> azf, List <_AcDb.Entity> rbs)
 {
     _AcDb.BlockTable       bt  = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
     _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead);
     foreach (_AcDb.ObjectId objId in btr)
     {
         _AcDb.Entity ent  = (_AcDb.Entity)tr.GetObject(objId, _AcDb.OpenMode.ForRead);
         var          poly = ent as _AcDb.Polyline;
         if (poly != null)
         {
             if (string.Compare(poly.Layer, fgLayer, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 fgs.Add(ent);
             }
             else if (string.Compare(poly.Layer, afLayer, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 azf.Add(ent);
             }
         }
         else
         {
             var block = ent as _AcDb.BlockReference;
             if (block != null)
             {
                 if (string.Compare(block.Name, rbName, StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     rbs.Add(ent);
                 }
             }
         }
     }
 }
        public List <_AcDb.ObjectId> GetAllBlocksInModelSpaceWith(Func <_AcDb.BlockReference, bool> checkFunc, string blockName)
        {
            var oids = new List <_AcDb.ObjectId>();
            var doc  = Application.DocumentManager.MdiActiveDocument;
            var db   = doc.Database;

            using (_AcDb.Transaction tr = doc.TransactionManager.StartTransaction())
            {
                _AcDb.BlockTable       bt  = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead);

                foreach (var oid in btr)
                {
                    var blockRef = tr.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                    if (blockRef != null)
                    {
                        if (string.Compare(blockRef.Name, blockName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            if (checkFunc(blockRef))
                            {
                                oids.Add(oid);
                            }
                        }
                    }
                }
                tr.Commit();
            }

            return(oids);
        }
Beispiel #8
0
        private void GetAllMsXrefs(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs)
        {
            log.Debug("GetAllMsXrefs");
            using (_AcDb.Transaction tr = _TransMan.StartTransaction())
            {
                _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);

                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(_AcDb.SymbolUtilityServices.GetBlockModelSpaceId(db), _AcDb.OpenMode.ForRead);

                foreach (var oid in btr)
                {
                    var br = tr.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                    if (br != null)
                    {
                        var bd = (_AcDb.BlockTableRecord)tr.GetObject(br.BlockTableRecord, _AcDb.OpenMode.ForRead);
                        if (bd.IsFromExternalReference)
                        {
                            allXrefsInMs.Add(br.ObjectId);
                        }
                    }
                }

                tr.Commit();
            }
        }
Beispiel #9
0
        static public void DynamicBlockProps()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            _AcEd.Editor   ed  = doc.Editor;

            _AcEd.PromptStringOptions pso = new _AcEd.PromptStringOptions("\nEnter dynamic block name or enter to select: ");
            pso.AllowSpaces = true;
            _AcEd.PromptResult pr = ed.GetString(pso);

            if (pr.Status != _AcEd.PromptStatus.OK)
            {
                return;
            }

            _AcDb.Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                _AcDb.BlockReference br = null;
                // If a null string was entered allow entity selection
                if (pr.StringResult == "")
                {
                    // Select a block reference
                    _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions("\nSelect dynamic block reference: ");
                    peo.SetRejectMessage("\nEntity is not a block.");
                    peo.AddAllowedClass(typeof(_AcDb.BlockReference), false);

                    _AcEd.PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != _AcEd.PromptStatus.OK)
                    {
                        return;
                    }

                    // Access the selected block reference
                    br = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                }

                else
                {
                    // Otherwise we look up the block by name
                    _AcDb.BlockTable bt = tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable;
                    if (!bt.Has(pr.StringResult))
                    {
                        ed.WriteMessage("\nBlock \"" + pr.StringResult + "\" does not exist.");
                        return;
                    }

                    // Create a new block reference referring to the block
                    br = new _AcDb.BlockReference(new _AcGe.Point3d(), bt[pr.StringResult]);
                }

                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, _AcDb.OpenMode.ForRead);

                // Call our function to display the block properties
                DisplayDynBlockProperties(ed, br, btr.Name);

                // Committing is cheaper than aborting
                tr.Commit();
            }
        }
        public static void ManualInsertbAttribute(string nameBlock)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (!blockTable.Has(nameBlock))
                {
                    ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock);
                    return;
                }
                AcDb.BlockTableRecord curSpace       = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
                AcDb.BlockReference   blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock]);
                blockReference.TransformBy(ed.CurrentUserCoordinateSystem);
                curSpace.AppendEntity(blockReference);
                tr.AddNewlyCreatedDBObject(blockReference, true);

                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead);
                AcDb.DBText           text;
                foreach (AcDb.ObjectId id in btr)
                {
                    if (id.ObjectClass.Name == "AcDbAttributeDefinition")
                    {
                        AcDb.AttributeDefinition attDef =
                            (AcDb.AttributeDefinition)tr.GetObject(id, AcDb.OpenMode.ForRead);

                        text = new AcDb.DBText
                        {
                            TextString = "jig_test"
                        };

                        TextPlacementJig jig = new TextPlacementJig(text);

                        //PromptResult pr = ed.Drag(jig);

                        AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword;
                        while (stat == AcEd.PromptStatus.Keyword)
                        {
                            AcEd.PromptResult pr = ed.Drag(jig);
                            stat = pr.Status;
                            if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword)
                            {
                                return;
                            }
                        }

                        AcDb.AttributeReference attRef = new AcDb.AttributeReference();
                        attRef.SetAttributeFromBlock(attDef, blockReference.BlockTransform);
                        AcDb.ObjectId attId = blockReference.AttributeCollection.AppendAttribute(attRef);
                        tr.AddNewlyCreatedDBObject(attRef, true);


                        tr.Commit();
                        //if (pr.Status != PromptStatus.OK) blockReference.Erase();
                    }
                }

                //tr.Commit();
            }
        }
        public static void ReplaceAttributeBlock(AcDb.ObjectId idBlock,
                                                 string tag,
                                                 string newValue,
                                                 Boolean visible)
        {
            try
            {
                //using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                //{
                //    DBObject dbObj = tr.GetObject(idBlock, AcDb.OpenMode.ForRead) as DBObject;
                //    AcDb.BlockReference blockReference = dbObj as BlockReference;
                //    ReplaceAttributeBlock(blockReference, tag, newValue, visible);
                //}


                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.BlockTable acBlockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                    if (acBlockTable == null)
                    {
                        return;
                    }

                    AcDb.BlockTableRecord acBlockTableRecord = (AcDb.BlockTableRecord)
                                                               tr.GetObject(acBlockTable[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForRead);
                    if (acBlockTableRecord == null)
                    {
                        return;
                    }

                    //foreach (var blkId in acBlockTableRecord)
                    //{
                    AcDb.BlockReference acBlock = (AcDb.BlockReference)tr.GetObject(idBlock, AcDb.OpenMode.ForRead);
                    //if (acBlock == null) continue;
                    //if (!acBlock.Name.Equals(blockName, StringComparison.CurrentCultureIgnoreCase)) continue;
                    foreach (AcDb.ObjectId attId in acBlock.AttributeCollection)
                    {
                        AcDb.AttributeReference acAtt = (AcDb.AttributeReference)tr.GetObject(attId, AcDb.OpenMode.ForRead);
                        if (acAtt == null)
                        {
                            continue;
                        }

                        if (!acAtt.Tag.Equals(tag, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }

                        acAtt.UpgradeOpen();
                        acAtt.TextString = newValue;
                    }
                    //}
                    tr.Commit();
                }
            }
            catch //(System.Exception exc)
            {
            }
        }
Beispiel #12
0
        private static bool PlotInLayouts()
        {
            var ok = true;

            _AcAp.Application.SetSystemVariable("BACKGROUNDPLOT", 0);
            using (_Tr = _Db.TransactionManager.StartTransaction())
            {
                var layouts = _Tr.GetObject(_Db.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;
                foreach (var layoutDe in layouts)
                {
                    //_AcDb.ObjectId layoutId = layManager.GetLayoutId(layManager.CurrentLayout);
                    var layoutId  = layoutDe.Value;
                    var layoutObj = (_AcDb.Layout)_Tr.GetObject(layoutId, _AcDb.OpenMode.ForWrite);

                    var loNameUC = layoutObj.LayoutName.ToUpperInvariant();
                    if (string.Compare(loNameUC, "MODEL", StringComparison.OrdinalIgnoreCase) == 0 || loNameUC.StartsWith("X_", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var fileName = _Doc.Name;
                    var dwgName  = Path.GetFileNameWithoutExtension(fileName);
                    var dirName  = Path.GetDirectoryName(fileName);
                    //var dwfName = Path.Combine(dirName, dwgName + "_" + RemoveInvalidCharacters(lo.LayoutName) + ".dwf");
                    var dwfName = Path.Combine(dirName, RemoveInvalidCharacters(layoutObj.LayoutName) + ".dwf");
                    log.InfoFormat("Ausgabedateiname: {0}", dwfName);
                    var dwfNameUC = dwfName.ToUpperInvariant();
                    if (_LayoutNames.Contains(dwfNameUC))
                    {
                        var msg = string.Format("Dwf kann nicht exportiert werden, da dieses schon aus einer Zeichnung exportiert wurde! {0}", dwfName);
                        log.Warn(msg);
                        _Editor.WriteMessage("\n" + msg);
                        _MultipleLayoutNames = true;
                        ok = false;
                        continue;
                    }
                    else
                    {
                        _LayoutNames.Add(dwfNameUC);
                    }

                    if (layoutObj.TabSelected == false)
                    {
                        _AcDb.LayoutManager acLayoutMgr = _AcDb.LayoutManager.Current;
                        acLayoutMgr.CurrentLayout = layoutObj.LayoutName;
                    }

                    if (!PlotDwf(layoutObj, dwfName))
                    {
                        ok = false;
                    }
                }
                _Tr.Commit();
            }
            return(ok);
        }
Beispiel #13
0
        public _CONNECTION()
        {
            _doc   = _Ap.Application.DocumentManager.MdiActiveDocument;
            _db    = _doc.Database;
            _ed    = _doc.Editor;
            _trans = _db.TransactionManager.StartTransaction();

            _blockTable = _trans.GetObject(_db.BlockTableId, _Db.OpenMode.ForWrite) as _Db.BlockTable;
            _modelSpace = _trans.GetObject(_Db.SymbolUtilityServices.GetBlockModelSpaceId(_db), _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;
        }
Beispiel #14
0
        public _AcDb.ResultBuffer LayoutListSelected(_AcDb.ResultBuffer args)
        {
            if (args != null)
            {
                throw new TooFewArgsException();
            }

            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            //Editor ed = doc.Editor;
            //LayoutManager layoutMgr = LayoutManager.Current;
            List <string> layouts = new List <string>();

            _AcDb.ResultBuffer res = new _AcDb.ResultBuffer();

            using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                _AcDb.DBDictionary layoutDic =
                    (_AcDb.DBDictionary)tr.GetObject(db.LayoutDictionaryId, _AcDb.OpenMode.ForRead, openErased: false);

                foreach (_AcDb.DBDictionaryEntry entry in layoutDic)
                {
                    _AcDb.Layout layout =
                        (_AcDb.Layout)tr.GetObject(entry.Value, _AcDb.OpenMode.ForRead);

                    string layoutName = layout.LayoutName;

                    if (layout.TabSelected)
                    {
                        layouts.Add(layoutName);
                    }
                }

                tr.Commit();
            }

            layouts.Remove("Model");

            if (0 < layouts.Count)
            {
                layouts.Sort();

                foreach (string layoutName in layouts)
                {
                    res.Add(new _AcDb.TypedValue((int)(_AcBrx.LispDataType.Text), layoutName));
                }

                return(res);
            }

            else
            {
                return(null);
            }
        }
Beispiel #15
0
        public static void DrawOrder_MoveToTop(AcDb.ObjectIdCollection collection)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable       bt  = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(bt[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForWrite);

                AcDb.DrawOrderTable dot = (AcDb.DrawOrderTable)tr.GetObject(btr.DrawOrderTableId, AcDb.OpenMode.ForWrite);
                dot.MoveToTop(collection);
            }
        }
        public static void EditeAttributeBlock(string blockName, string tag, string newValue)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable acBlockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (acBlockTable == null)
                {
                    return;
                }

                AcDb.BlockTableRecord acBlockTableRecord = (AcDb.BlockTableRecord)tr.GetObject(acBlockTable[AcDb.BlockTableRecord.ModelSpace], AcDb.OpenMode.ForRead);
                if (acBlockTableRecord == null)
                {
                    return;
                }

                foreach (var blkId in acBlockTableRecord)
                {
                    try
                    {
                        AcDb.BlockReference acBlock = (AcDb.BlockReference)tr.GetObject(blkId, AcDb.OpenMode.ForRead);
                        if (acBlock == null)
                        {
                            continue;
                        }
                        if (!acBlock.Name.Equals(blockName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                        foreach (AcDb.ObjectId attId in acBlock.AttributeCollection)
                        {
                            var acAtt = tr.GetObject(attId, AcDb.OpenMode.ForRead) as AcDb.AttributeReference;
                            if (acAtt == null)
                            {
                                continue;
                            }

                            if (!acAtt.Tag.Equals(tag, StringComparison.CurrentCultureIgnoreCase))
                            {
                                continue;
                            }

                            acAtt.UpgradeOpen();
                            acAtt.TextString = newValue;
                        }
                    }
                    catch
                    {
                    }
                }

                tr.Commit();
            }
        }
Beispiel #17
0
        private bool getBlockFromMaster(ref List <string> missingBlocks)
        {
            _Db.Database sourceDb       = new _Db.Database(false, true);
            string       sourceFileName = @"C:\Brics_pealeehitus\master.dwg";

            if (!File.Exists(sourceFileName))
            {
                sourceFileName = @"C:\Users\aleksandr.ess\Dropbox\DMT\Brics_testimine\master.dwg";
                if (!File.Exists(sourceFileName))
                {
                    sourceFileName = @"C:\Users\Alex\Dropbox\DMT\Brics_testimine\master.dwg";
                }
            }

            sourceDb.ReadDwgFile(sourceFileName, System.IO.FileShare.Read, true, "");
            _Db.ObjectIdCollection blockIds = new _Db.ObjectIdCollection();


            using (_Db.Transaction sourceTrans = sourceDb.TransactionManager.StartTransaction())
            {
                _Db.BlockTable sourceBlockTable = sourceTrans.GetObject(sourceDb.BlockTableId, _Db.OpenMode.ForRead, false) as _Db.BlockTable;

                foreach (_Db.ObjectId sourceObject in sourceBlockTable)
                {
                    _Db.BlockTableRecord btr = sourceTrans.GetObject(sourceObject, _Db.OpenMode.ForRead, false) as _Db.BlockTableRecord;

                    if (!btr.IsAnonymous && !btr.IsLayout)
                    {
                        if (missingBlocks.Contains(btr.Name))
                        {
                            blockIds.Add(sourceObject);
                            missingBlocks.Remove(btr.Name);
                            write("[SETUP] " + btr.Name); // TODO REMOVE
                        }
                    }

                    btr.Dispose();
                }
            }

            if (missingBlocks.Count > 0)
            {
                return(false);
            }

            _Db.IdMapping mapping = new _Db.IdMapping();
            sourceDb.WblockCloneObjects(blockIds, _c.blockTable.Id, mapping, _Db.DuplicateRecordCloning.Replace, false);
            sourceDb.Dispose();

            write("[SETUP] Kõik puuduvad blockid on lisatud 'master' failist");
            return(true);
        }
Beispiel #18
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 #19
0
        /// <summary>
        /// Öffnen einer Dwg ohne Editor
        /// </summary>
        //[_AcTrx.CommandMethod("Plan2TestSideDb")]
        static public void Plan2TestSideDb()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcEd.Editor   ed  = doc.Editor;
            // Ask the user to select a file
            _AcEd.PromptResult res = ed.GetString("\nEnter the path of a DWG or DXF file: ");
            if (res.Status == _AcEd.PromptStatus.OK)
            {
                // Create a database and try to load the file
                _AcDb.Database db = new _AcDb.Database(false, true);
                using (db)
                {
                    try
                    {
                        db.ReadDwgFile(res.StringResult, System.IO.FileShare.Read, false, "");
                    }
                    catch (System.Exception)
                    {
                        ed.WriteMessage("\nUnable to read drawing file.");
                        return;
                    }

                    _AcDb.Transaction tr = db.TransactionManager.StartTransaction();
                    using (tr)
                    {
                        // Open the blocktable, get the modelspace
                        _AcDb.BlockTable       bt  = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                        _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead);

                        // Iterate through it, dumping objects
                        foreach (_AcDb.ObjectId objId in btr)
                        {
                            _AcDb.Entity ent = (_AcDb.Entity)tr.GetObject(objId, _AcDb.OpenMode.ForRead);

                            // Let's get rid of the standard namespace
                            const string prefix     = "Autodesk.AutoCAD.DatabaseServices.";
                            string       typeString = ent.GetType().ToString();
                            if (typeString.Contains(prefix))
                            {
                                typeString = typeString.Substring(prefix.Length);
                            }
                            ed.WriteMessage("\nEntity " + ent.ObjectId.ToString() + " of type " + typeString + " found on layer " +
                                            ent.Layer + " with colour " + ent.Color.ToString());
                        }
                    }
                }
            }
        }
Beispiel #20
0
        private static bool SetAttValues(_AcDb.Database db)
        {
            bool ok = true;

            try
            {
                using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                    foreach (var id in bt)
                    {
                        _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(id, _AcDb.OpenMode.ForRead);
                        if (btr.IsLayout)
                        {
                            foreach (var oid in btr)
                            {
                                var ent = tr.GetObject(oid, _AcDb.OpenMode.ForRead);
                                _AcDb.BlockReference bref = ent as _AcDb.BlockReference;
                                if (bref != null)
                                {
                                    bool sameName = false;
                                    try
                                    {
                                        sameName = (bref.Name == _BlockName);
                                    }
                                    catch (Exception)
                                    {
                                        log.WarnFormat("Invalid block with handle {0}!", bref.Handle);
                                    }
                                    if (sameName)
                                    {
                                        SetAttValues(bref, tr);
                                    }
                                }
                            }
                        }
                    }

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                log.Error(string.Format(CultureInfo.CurrentCulture, "Fehler beim Ändern der Attribute: {0}", ex.Message), ex);
                ok = false;
            }
            return(ok);
        }
Beispiel #21
0
        private void ExplodeBlocks(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs, List <_AcDb.ObjectId> newlyCreatedObjects, bool deleteRef, bool deleteBtr)
        {
            log.Debug("ExplodeXRefs");
            using (_AcDb.Transaction tr = _TransMan.StartTransaction())
            {
                _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);

                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(_AcDb.SymbolUtilityServices.GetBlockModelSpaceId(db), _AcDb.OpenMode.ForWrite);


                foreach (var oid in allXrefsInMs)
                {
                    _AcDb.DBObjectCollection objs  = new _AcDb.DBObjectCollection();
                    _AcDb.BlockReference     block = (_AcDb.BlockReference)tr.GetObject(oid, _AcDb.OpenMode.ForRead);
                    log.DebugFormat(CultureInfo.CurrentCulture, "Explode von Block '{0}'.", block.Name);
                    block.Explode(objs);
                    log.DebugFormat(CultureInfo.CurrentCulture, "Block enthält {0} Entities.", objs.Count);
                    _AcDb.ObjectId blockRefTableId = block.BlockTableRecord;


                    foreach (_AcDb.DBObject obj in objs)
                    {
                        _AcDb.Entity ent = (_AcDb.Entity)obj;
                        btr.AppendEntity(ent);
                        tr.AddNewlyCreatedDBObject(ent, true);

                        newlyCreatedObjects.Add(ent.ObjectId);
                    }

                    if (deleteRef)
                    {
                        log.DebugFormat(CultureInfo.CurrentCulture, "Lösche Block '{0}'.", block.Name);
                        block.UpgradeOpen();
                        block.Erase();
                    }

                    if (deleteBtr)
                    {
                        log.DebugFormat("DeleteBtr");
                        // funkt nicht -> xref würde gelöscht
                        var bd = (_AcDb.BlockTableRecord)tr.GetObject(blockRefTableId, _AcDb.OpenMode.ForWrite);
                        bd.Erase();
                        log.DebugFormat("Endof DeleteBtr");
                    }
                }
                tr.Commit();
            }
        }
Beispiel #22
0
        public static AcDb.ObjectId CreateFontStyle(String textStyleName, AcGi.FontDescriptor font)
        {
            AcDb.ObjectId txtStyleId = AcDb.ObjectId.Null;

            using (AcDb.Transaction tr = doc.Database.TransactionManager.StartTransaction())
            {
                AcDb.TextStyleTable newTextStyleTable = tr.GetObject(doc.Database.TextStyleTableId, AcDb.OpenMode.ForRead) as AcDb.TextStyleTable;

                if (!newTextStyleTable.Has(textStyleName))
                {
                    newTextStyleTable.UpgradeOpen();
                    AcDb.TextStyleTableRecord newTextStyleTableRecord = new AcDb.TextStyleTableRecord();
                    //newTextStyleTableRecord.FileName = "romans.shx";
                    newTextStyleTableRecord.Name = textStyleName;
                    newTextStyleTableRecord.Font = font;
                    newTextStyleTable.Add(newTextStyleTableRecord);
                    tr.AddNewlyCreatedDBObject(newTextStyleTableRecord, true);

                    txtStyleId = newTextStyleTable[textStyleName];
                }
                tr.Commit();
            }

            return(txtStyleId);
        }
Beispiel #23
0
        public static void ManualInsertMText(AcDb.MText oMText)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);

                oMText.Normal = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis;

                btr.AppendEntity(oMText);
                tr.AddNewlyCreatedDBObject(oMText, true);

                MTextPlacementJig pj = new MTextPlacementJig(oMText);

                AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword;
                while (stat == AcEd.PromptStatus.Keyword)
                {
                    AcEd.PromptResult res = ed.Drag(pj);
                    stat = res.Status;
                    if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword)
                    {
                        return;
                    }
                }
                tr.Commit();
                //return (MText)pj.Entity;
            }
        }
Beispiel #24
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 #25
0
        public static void SelectObjects(AcDb.ObjectIdCollection objectIds)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcEd.PromptSelectionResult psr = ed.GetSelection();
                if (psr.Status == AcEd.PromptStatus.OK)
                {
                    AcEd.SelectionSet SSet = psr.Value;
                    foreach (AcEd.SelectedObject SObj in SSet)
                    {
                        if (SObj != null)
                        {
                            AcDb.Entity entityObject = tr.GetObject(SObj.ObjectId, AcDb.OpenMode.ForWrite) as AcDb.Entity;

                            if (entityObject != null)
                            {
                                foreach (AcDb.ObjectId idObj in objectIds)
                                {
                                    if (idObj.Equals(entityObject.ObjectId))
                                    {
                                        entityObject.Highlight();
                                    }
                                }
                            }
                        }
                    }
                    // Save the new object to the database
                    tr.Commit();
                }
            }
        }
Beispiel #26
0
        public static void CreateLayout(string name)
        {
            _AcAp.Document acDoc   = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database acCurDb = acDoc.Database;

            using (_AcDb.Transaction trans = acCurDb.TransactionManager.StartTransaction())
            {
                // Reference the Layout Manager
                _AcDb.LayoutManager acLayoutMgr = _AcDb.LayoutManager.Current;

                // Create the new layout with default settings
                _AcDb.ObjectId objID = acLayoutMgr.CreateLayout(name);

                // Open the layout
                _AcDb.Layout layout = trans.GetObject(objID, _AcDb.OpenMode.ForRead) as _AcDb.Layout;

                // Set the layout current if it is not already
                if (layout.TabSelected == false)
                {
                    acLayoutMgr.CurrentLayout = layout.LayoutName;
                }

                // Output some information related to the layout object
                acDoc.Editor.WriteMessage("\nTab Order: " + layout.TabOrder +
                                          "\nTab Selected: " + layout.TabSelected +
                                          "\nBlock Table Record ID: " +
                                          layout.BlockTableRecordId.ToString());

                // Save the changes made
                trans.Commit();
            }
        }
Beispiel #27
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 #28
0
        static public void GetXData()
        {
            AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument;
            AcEd.Editor   ed  = doc.Editor;

            AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: ");
            AcEd.PromptEntityResult  res = ed.GetEntity(opt);

            if (res.Status == AcEd.PromptStatus.OK)
            {
                using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction())
                {
                    AcDb.DBObject     obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForRead);
                    AcDb.ResultBuffer rb  = obj.XData;
                    if (rb == null)
                    {
                        ed.WriteMessage("\nEntity does not have XData attached.");
                    }
                    else
                    {
                        int n = 0;
                        foreach (AcDb.TypedValue tv in rb)
                        {
                            ed.WriteMessage("\nTypedValue {0} - type: {1}, value: {2}", n++, tv.TypeCode, tv.Value);
                        }
                        rb.Dispose();
                    }
                }
            }
        }
Beispiel #29
0
        private static bool SetPlotterInLayouts()
        {
            var ok = true;

            using (_Tr = _Db.TransactionManager.StartTransaction())
            {
                var layManager = _AcDb.LayoutManager.Current;
                var plotSetVal = _AcDb.PlotSettingsValidator.Current;

                //_AcDb.DBDictionary layoutsEx = acTransEx.GetObject(acExDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;
                var layouts = _Tr.GetObject(_Db.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary;
                foreach (var layoutDe in layouts)
                {
                    //_AcDb.ObjectId layoutId = layManager.GetLayoutId(layManager.CurrentLayout);
                    var layoutId  = layoutDe.Value;
                    var layoutObj = (_AcDb.Layout)_Tr.GetObject(layoutId, _AcDb.OpenMode.ForWrite);
                    //ed.WriteMessage("Style sheet of current layout: " + layoutObj.CurrentStyleSheet + "\n");
                    plotSetVal.RefreshLists(layoutObj);
                    System.Collections.Specialized.StringCollection deviceList = plotSetVal.GetPlotDeviceList();
                    bool plotterExists = PlotterExists(deviceList);
                    if (!plotterExists)
                    {
                        ok = false;
                        break;
                    }
                    else
                    {
                        using (var ps = new _AcDb.PlotSettings(layoutObj.ModelType))
                        {
                            ps.CopyFrom(layoutObj);
                            if (_NoPlotterInModelSpace && layoutObj.LayoutName == "Model")
                            {
                                plotSetVal.SetPlotConfigurationName(ps, _NoPlotterName, null);
                            }
                            else
                            {
                                plotSetVal.SetPlotConfigurationName(ps, _PlotterName, null);
                            }
                            layoutObj.CopyFrom(ps);
                        }
                        _NrPlotters++;
                    }
                }
                _Tr.Commit();
            }
            return(ok);
        }
Beispiel #30
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();
                }
            }
        }