Esempio n. 1
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;
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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();
            }
        }
Esempio n. 6
0
 internal void close()
 {
     _ed.WriteMessage("\n[close connection]\n");
     _trans.Commit();
     _trans.Dispose();
     _ed.Regen();
 }
Esempio n. 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();
                }
            }
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
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 { }
        }
Esempio n. 10
0
        internal void CalcVolume(string raumBlockName, string areaAttName, string heightAttName, string volAttName)
        {
            RaumBlockName = raumBlockName;
            AreaAttName   = areaAttName;
            HeightAttName = heightAttName;
            VolAttName    = volAttName;

            if (!(CalcVolArgsOk))
            {
                return;
            }

            List <_AcDb.ObjectId> allRaumBlocks = SelectRaumBlocks();

            if (allRaumBlocks.Count == 0)
            {
                return;
            }

            using (_AcDb.Transaction myT = _TransMan.StartTransaction())
            {
                foreach (var oid in allRaumBlocks)
                {
                    _AcDb.BlockReference blockRef = _TransMan.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                    if (blockRef == null)
                    {
                        continue;
                    }

                    CalcVolume(blockRef);
                }

                myT.Commit();
            }
        }
Esempio n. 11
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();
                }
            }
        }
Esempio n. 12
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);
        }
Esempio n. 13
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();
            }
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
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();
            }
        }
        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)
            {
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
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();
                }
            }
        }
Esempio n. 20
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);
            }
        }
        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();
            }
        }
Esempio n. 22
0
 public static AcDb.DBObject GetObject(AcDb.ObjectId objectId)
 {
     AcDb.DBObject obj = null;
     using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
     {
         obj = tr.GetObject(objectId, AcDb.OpenMode.ForWrite);
         obj.Erase();
         tr.Commit();
     }
     return(obj);
 }
Esempio n. 23
0
        internal bool LayTrans(string fileName)
        {
            _Errors.Clear();
            var linfos = ExcelImport(fileName);

            foreach (var err in _Errors)
            {
                log.Warn(err);
            }

            var doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            var db  = doc.Database;

            using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction())
            {
                _AcDb.LayerTable layTb = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForWrite) as _AcDb.LayerTable;

                foreach (var linfo in linfos)
                {
                    CreateOrModifyLayer(linfo, doc, db, trans, layTb);
                }

                trans.Commit();
            }

            Dictionary <string, string> substDict = new Dictionary <string, string>();

            foreach (var linfo in linfos)
            {
                substDict[linfo.OldLayer.ToUpperInvariant()] = linfo.NewLayer;
            }

            using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction())
            {
                _AcDb.LayerTable layTb = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForWrite) as _AcDb.LayerTable;

                //foreach (var linfo in linfos)
                //{
                ReplaceLayerInEntities(substDict, trans, db);
                //}

                trans.Commit();
            }

            Plan2Ext.Globs.SetLayerCurrent("0");

            List <string> oldLayerNames = linfos.Select(x => x.OldLayer).ToList();

            Plan2Ext.Globs.PurgeLayer(oldLayerNames);


            return(true);
        }
Esempio n. 24
0
        public void TestTrans()
        {
            try
            {
                //System.Windows.Forms.MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "_test = {0}", _test));
                //_test = 0;



                _AcDb.Database           db      = _AcAp.Application.DocumentManager.MdiActiveDocument.Database;
                _AcDb.TransactionManager dbTrans = db.TransactionManager;
                using (_AcDb.Transaction trans = dbTrans.StartTransaction())
                {
                    // create a line
                    _AcDb.Line       ln = new _AcDb.Line(new _AcGe.Point3d(0.0, 0.0, 0.0), new _AcGe.Point3d(1.0, 1.0, 0.0));
                    _AcDb.BlockTable bt = dbTrans.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead, false) as _AcDb.BlockTable;
                    if (bt == null)
                    {
                        return;
                    }
                    //ObjectId id = bt[BlockTableRecord.ModelSpace];
                    _AcDb.BlockTableRecord btr = dbTrans.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForWrite, false) as _AcDb.BlockTableRecord;
                    if (btr == null)
                    {
                        return;
                    }
                    //Add it to the model space block table record.
                    btr.AppendEntity(ln);
                    //Make sure that the transaction knows about this new object.    tm.AddNewlyCreatedDBObject(line, True)
                    dbTrans.AddNewlyCreatedDBObject(ln, true);


                    //'Add some hyperlinks.    Dim hyper As New HyperLink()    hyper.Name = "www.autodesk.com"    line.Hyperlinks.Add(hyper)
                    _AcDb.HyperLink hyper = new _AcDb.HyperLink();
                    hyper.Name = "www.facebook.com";
                    ln.Hyperlinks.Add(hyper);
                    if (ln.Hyperlinks.Contains(hyper))
                    {
                        hyper.Name = "www.gotdotnet.com";
                    }
                    ln.Hyperlinks.Add(hyper);
                    foreach (var hl in ln.Hyperlinks)
                    {
                        System.Diagnostics.Debug.WriteLine(hl.ToString());
                    }
                    trans.Commit();
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Esempio n. 25
0
        public static void SetXData(AcDb.ObjectId objectId, AcDb.ResultBuffer valueXData)
        {
            AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument;

            using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction())
            {
                AcDb.DBObject obj = tr.GetObject(objectId, AcDb.OpenMode.ForWrite);
                AddRegAppTableRecord((string)valueXData.AsArray()[0].Value);
                obj.XData = valueXData;
                valueXData.Dispose();
                tr.Commit();
            }
        }
Esempio n. 26
0
        private void DeleteExplodedXrefEntities()
        {
            using (_AcDb.Transaction tr = _TransMan.StartTransaction())
            {
                foreach (var oid in _ExplodedXrefEntities)
                {
                    var ent = tr.GetObject(oid, _AcDb.OpenMode.ForWrite);
                    ent.Erase();
                }

                tr.Commit();
            }
        }
Esempio n. 27
0
        private List <_AcDb.ObjectId> GetFgAnz(_AcGe.Point3d minExt, _AcGe.Point3d maxExt, _AcDb.ObjectId elFG)
        {
            List <_AcDb.ObjectId> Ret = new List <_AcDb.ObjectId>();

            _AcEd.Editor          ed     = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] {
                new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "*POLYLINE"),
                new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName, _FgLayer)
            });
            _AcEd.PromptSelectionResult res = null;
            res = ed.SelectCrossingWindow(minExt, maxExt, filter);
            //res = ed.SelectAll(filter);
            if (res.Status != _AcEd.PromptStatus.OK)
            {
                // todo: logging: lot4net?
                return(Ret);
            }

#if BRX_APP
            _AcEd.SelectionSet ss = res.Value;
#else
            using (_AcEd.SelectionSet ss = res.Value)
#endif
            {
                _AcDb.ObjectId[]         idArray = ss.GetObjectIds();
                _AcDb.Database           db      = _AcAp.Application.DocumentManager.MdiActiveDocument.Database;
                _AcDb.TransactionManager tm      = db.TransactionManager;
                _AcDb.Transaction        myT     = tm.StartTransaction();
                try
                {
                    for (int i = 0; i < idArray.Length; i++)
                    {
                        _AcDb.ObjectId oid = idArray[i];
                        if (!oid.Equals(elFG))
                        {
                            if (PolyInPoly(tm, oid, elFG))
                            {
                                AddRbToRetCol(Ret, tm, oid);
                            }
                        }
                    }
                    myT.Commit();
                }
                finally
                {
                    myT.Dispose();
                }
            }

            return(Ret);
        }
Esempio n. 28
0
        public static bool Plan2RemoveHyperLinks(_AcDb.ResultBuffer rb)
        {
            var doc = _AcAp.Application.DocumentManager.MdiActiveDocument;

            _AcDb.Database           db      = _AcAp.Application.DocumentManager.MdiActiveDocument.Database;
            _AcDb.TransactionManager dbTrans = db.TransactionManager;
            _AcEd.Editor             ed      = doc.Editor;

            try
            {
                if (rb == null)
                {
                    ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
                    return(false);
                }

                var typedValues = rb.AsArray();
                if (typedValues == null || typedValues.Length != 1)
                {
                    ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
                    return(false);
                }

                if (typedValues[0].TypeCode != (short)_AcBrx.LispDataType.ObjectId)
                {
                    ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
                    return(false);
                }

                using (_AcDb.Transaction trans = dbTrans.StartTransaction())
                {
                    _AcDb.Entity ent = trans.GetObject((_AcDb.ObjectId)typedValues[0].Value, _AcDb.OpenMode.ForWrite) as _AcDb.Entity;
                    if (ent != null)
                    {
                        //ent.Hyperlinks.Clear(); // -> crashes
                        while (ent.Hyperlinks.Count > 0)
                        {
                            ent.Hyperlinks.RemoveAt(0);
                        }
                    }
                    trans.Commit();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
            }
            return(false);
        }
Esempio n. 29
0
 public static AcDb.ObjectId InsertObject(AcDb.Entity entityObject)
 {
     AcDb.ObjectId objectId;
     using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
     {
         AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
         btr.AppendEntity(entityObject);
         tr.AddNewlyCreatedDBObject(entityObject, true);
         objectId = entityObject.ObjectId;
         btr.Dispose();
         tr.Commit();
     }
     return(objectId);
 }
Esempio n. 30
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);
        }