示例#1
0
        private ObjectIdCollection AddToModelSpace(params Entity[] list)
        {
            ObjectIdCollection ids = new ObjectIdCollection();

            _AcDb.TransactionManager manager = database.TransactionManager;
            using (Transaction action = manager.StartTransaction())
            {
                BlockTable blockTable =
                    action.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
                if (blockTable == null)
                {
                    throw new NullReferenceException("blockTable == null");
                }

                BlockTableRecord blockTableRecord =
                    action.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                if (blockTableRecord == null)
                {
                    throw new System.NullReferenceException("blockTableRecord == null");
                }

                foreach (Entity ent in list)
                {
                    ids.Add(blockTableRecord.AppendEntity(ent));
                    action.AddNewlyCreatedDBObject(ent, true);
                }
                action.Commit();
            }
            return(ids);
        }
 private static _AcDb.Extents3d GetExtents(_AcDb.TransactionManager tm, _AcDb.ObjectId oid)
 {
     using (_AcDb.DBObject dbobj = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false))
     {
         _AcDb.Entity ent = dbobj as _AcDb.Entity;
         return(ent.GeometricExtents);
     }
 }
示例#3
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);
            }
        }
示例#4
0
        public ErrorStatus RoundHeight(int digits)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            _AcDb.TransactionManager myTm       = db.TransactionManager;
            Transaction          myT            = db.TransactionManager.StartTransaction();
            Editor               ed             = Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectContextManager conTextManager = db.ObjectContextManager;
            ErrorStatus          es             = ErrorStatus.KeyNotFound;

            if (this.HöheOrg != null)
            {
                if (MyString.Precision(this.HöheOrg) >= digits)
                {
                    try
                    {
                        using (DocumentLock dl = Application.DocumentManager.MdiActiveDocument.LockDocument())
                        {
                            BlockTable bt = (BlockTable)myT.GetObject(db.BlockTableId, OpenMode.ForRead);
                            ObjectId   id = bt[BlockTableRecord.ModelSpace];

                            AttributeCollection col = _blkRef.AttributeCollection;

                            foreach (ObjectId attId in col)
                            {
                                AttributeReference attRef = (AttributeReference)myT.GetObject(attId, OpenMode.ForWrite);

                                switch (attRef.Tag)
                                {
                                case "height":
                                    double Höhe = Convert.ToDouble(this.HöheOrg, CultureInfo.InvariantCulture);
                                    attRef.TextString = Höhe.ToString("F" + digits.ToString());
                                    attRef.Dispose();
                                    _Hdigits = digits;
                                    es       = ErrorStatus.OK;
                                    break;
                                }
                            }
                        }
                    }

                    catch { }

                    finally
                    {
                        myT.Commit();
                        myT.Dispose();
                        ed.Regen();
                    }
                }
            }
            return(es);
        }
        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);
        }
示例#6
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);
        }
示例#7
0
        private void performanceTest()
        {
            Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                if (database == null)
                {
                    throw new NullReferenceException("database is null");
                }

                _AcDb.TransactionManager manager = database.TransactionManager;

                if (manager == null)
                {
                    throw new NullReferenceException("manager is null");
                }

                using (Transaction action = manager.StartTransaction())
                {
                    int              countEnts        = 0;
                    Stopwatch        sw               = Stopwatch.StartNew();
                    BlockTableRecord blockTableRecord = action.GetObject
                                                            (database.CurrentSpaceId, OpenMode.ForRead, false) as BlockTableRecord;

                    if (blockTableRecord == null)
                    {
                        throw new NullReferenceException("blockTableRecord is null");
                    }

                    foreach (ObjectId entityId in blockTableRecord)
                    {
                        Entity entity = action.GetObject(entityId, OpenMode.ForRead, false) as Entity;
                        if (entity == null)
                        {
                            throw new NullReferenceException("entity is null");
                        }

                        countEnts++;
                    }
                    editor.WriteMessage("\n{0} Entities found in {1} Milliseconds", countEnts, sw.ElapsedMilliseconds);
                    action.Commit();
                }
            }
            catch (System.Exception ex)
            {
                _LoggingService.WriteWithInner(ex, true, string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace));
            }
        }
        private void AddRbToRetCol(List <_AcDb.ObjectId> Ret, _AcDb.TransactionManager tm, _AcDb.ObjectId elFG)
        {
            _AcDb.Extents3d ext    = GetExtents(tm, elFG);
            _AcGe.Point3d   minExt = new _AcGe.Point3d(ext.MinPoint.X - ABSTANDTEXT, ext.MinPoint.Y - ABSTANDTEXT, ext.MinPoint.Z);
            _AcGe.Point3d   maxExt = new _AcGe.Point3d(ext.MaxPoint.X + ABSTANDTEXT, ext.MaxPoint.Y + ABSTANDTEXT, ext.MaxPoint.Z);

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

#if BRX_APP
            _AcEd.SelectionSet ss = res.Value;
#else
            using (_AcEd.SelectionSet ss = res.Value)
#endif
            {
                _AcDb.ObjectId[] idArray = ss.GetObjectIds();
                for (int i = 0; i < idArray.Length; i++)
                {
                    _AcDb.ObjectId oid = idArray[i];
                    using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false))
                    {
                        using (_AcDb.Entity entElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false) as _AcDb.Entity)
                        {
                            if (pEntity is _AcDb.BlockReference)
                            {
                                _AcDb.BlockReference br = pEntity as _AcDb.BlockReference;
                                if (AreaEngine.InPoly(br.Position, entElFG))
                                {
                                    Ret.Add(oid);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#9
0
        public void HeightVisible(bool visible)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            _AcDb.TransactionManager myTm       = db.TransactionManager;
            Transaction          myT            = db.TransactionManager.StartTransaction();
            Editor               ed             = Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectContextManager conTextManager = db.ObjectContextManager;

            try
            {
                using (DocumentLock dl = Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    BlockTable bt = (BlockTable)myT.GetObject(db.BlockTableId, OpenMode.ForRead);
                    ObjectId   id = bt[BlockTableRecord.ModelSpace];

                    AttributeCollection col = _blkRef.AttributeCollection;

                    foreach (ObjectId attId in col)
                    {
                        AttributeReference attRef = (AttributeReference)myT.GetObject(attId, OpenMode.ForWrite);

                        switch (attRef.Tag)
                        {
                        case "height":
                            attRef.Visible = visible;
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            catch { }

            finally
            {
                myT.Commit();
                myT.Dispose();
                ed.Regen();
            }
        }
示例#10
0
        private void addLayer()
        {
            Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                LayerTableRecord myLayer = new LayerTableRecord();
                myLayer.Name  = "CoolLayer";
                myLayer.Color = Teigha.Colors.Color.FromRgb(255, 0, 255);

                _AcDb.TransactionManager manager = database.TransactionManager;

                using (Transaction action = manager.StartTransaction())
                {
                    LayerTable layerTable =
                        action.GetObject(database.LayerTableId, OpenMode.ForWrite) as LayerTable;

                    if (layerTable == null)
                    {
                        throw new System.NullReferenceException("LayerTable == null");
                    }

                    if (!layerTable.Has(myLayer.Name))
                    {
                        layerTable.Add(myLayer);
                    }

                    action.AddNewlyCreatedDBObject(myLayer, true);
                    action.Commit();
                }
            }
            catch (System.Exception ex)
            {
                _LoggingService.WriteWithInner(ex, true, string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace));
            }
        }
示例#11
0
        public static bool Plan2AddHyperLink(_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
            {
                _AcDb.ObjectId oid;
                string         description, name, sublocation;
                if (rb == null)
                {
                    ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)");
                    return(false);
                }

                var typedValues = rb.AsArray();
                if (typedValues == null || typedValues.Length != 4)
                {
                    ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)");
                    return(false);
                }

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

                oid = (_AcDb.ObjectId)typedValues[0].Value;

                if (typedValues[1].TypeCode != (short)_AcBrx.LispDataType.Text)
                {
                    ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)");
                    return(false);
                }
                description = typedValues[1].Value.ToString();

                if (typedValues[2].TypeCode != (short)_AcBrx.LispDataType.Text)
                {
                    ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)");
                    return(false);
                }
                name = typedValues[2].Value.ToString();

                if (typedValues[3].TypeCode != (short)_AcBrx.LispDataType.Text)
                {
                    ed.WriteMessage("Aufruf: (Plan2AddHyperLink el description name sublocation)");
                    return(false);
                }
                sublocation = typedValues[3].Value.ToString();


                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)
                    {
                        _AcDb.HyperLink hyperLink = new _AcDb.HyperLink();
                        hyperLink.Description = description;
                        hyperLink.Name        = name;
                        hyperLink.SubLocation = sublocation;

                        ent.Hyperlinks.Add(hyperLink);
                    }
                    trans.Commit();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
            }
            return(false);
        }
示例#12
0
        internal bool SelectFgAndRb(List <_AcDb.ObjectId> flaechenGrenzen, List <_AcDb.ObjectId> raumBloecke, string fgLayer, string rbName)
        {
            flaechenGrenzen.Clear();
            raumBloecke.Clear();

            log.Debug("Auswahl Flächengrenzen und Raumblöcke");
            _AcEd.PromptSelectionResult res    = null;
            _AcEd.SelectionFilter       filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] {
                new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<OR"),

                new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<AND"),
                new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "*POLYLINE"),
                new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName, fgLayer),
                new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "AND>"),

                new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<AND"),
                new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"),
                //new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName ,rbName  ),
                new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "AND>"),

                new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "OR>")
            });

            _AcEd.PromptSelectionOptions SelOpts = new _AcEd.PromptSelectionOptions();
            SelOpts.MessageForAdding = "Raumblöcke und Flächengrenzen wählen: ";

            res = _Editor.GetSelection(SelOpts, filter);
            if (res.Status != _AcEd.PromptStatus.OK)
            {
                log.Debug("Auswahl wurde abgebrochen.");
                if (res.Status == _AcEd.PromptStatus.Cancel)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

#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];
                        using (_AcDb.DBObject dbobj = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false) as _AcDb.Entity)
                        {
                            _AcDb.Entity ent = dbobj as _AcDb.Entity;
                            if (ent != null)
                            {
                                if (ent is _AcDb.BlockReference)
                                {
                                    if (string.Compare(rbName, Plan2Ext.Globs.GetBlockname((_AcDb.BlockReference)ent, myT), StringComparison.OrdinalIgnoreCase) == 0)
                                    {
                                        raumBloecke.Add(oid);
                                    }
                                }
                                else
                                {
                                    flaechenGrenzen.Add(oid);
                                }
                            }
                        }
                    }
                    myT.Commit();
                }
                finally
                {
                    myT.Dispose();
                }
            }

            log.DebugFormat(CultureInfo.CurrentCulture, "Auswahl: Raumblöcke {0}, Flächengrenzen {1}", raumBloecke.Count, flaechenGrenzen.Count);

            return(true);
        }
示例#13
0
 public Engine()
 {
     _TransMan = _AcAp.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager;
 }
        internal void DoIt(_AcAp.Document doc, string rbName, string fgLayer)
        {
            log.Debug("--------------------------");

            _FlaechenGrenzen.Clear();
            _Raumbloecke.Clear();

            var _AreaEngine = new AreaEngine();

            _AcGe.Matrix3d ucs = _AcGe.Matrix3d.Identity;
            try
            {
                ucs = doc.Editor.CurrentUserCoordinateSystem;
                doc.Editor.CurrentUserCoordinateSystem = _AcGe.Matrix3d.Identity;

                if (!string.IsNullOrEmpty(rbName))
                {
                    _RaumblockName = rbName;
                }
                if (!string.IsNullOrEmpty(fgLayer))
                {
                    _FgLayer = fgLayer;
                }

                _AreaEngine.SelectFgAndRb(_FlaechenGrenzen, _Raumbloecke, _FgLayer, _RaumblockName);

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

                // todo: läuft nicht synchron - wird dzt in lisp ausgeführt
                //Globs.SetWorldUCS();

                ZoomToFlaechenGrenzen();

                // init div
                int fehlerKeinRb     = 0;
                int fehlerMehrRb     = 0;
                int fehlerWertFalsch = 0;

                _AcDb.Database           db  = doc.Database;
                _AcEd.Editor             ed  = doc.Editor;
                _AcDb.TransactionManager tm  = db.TransactionManager;
                _AcDb.Transaction        myT = tm.StartTransaction();
                try
                {
                    _AcGe.Point2d lu = new _AcGe.Point2d();
                    _AcGe.Point2d ro = new _AcGe.Point2d();

                    for (int i = 0; i < _FlaechenGrenzen.Count; i++)
                    {
                        log.Debug("--------------------------");

                        double         sumAF = 0;
                        int            rbInd = -1;
                        _AcDb.ObjectId elFG  = _FlaechenGrenzen[i];
                        log.DebugFormat("Flächengrenze {0}", elFG.Handle.ToString());

                        _AcDb.Extents3d ext    = GetExtents(tm, elFG);
                        _AcGe.Point3d   minExt = new _AcGe.Point3d(ext.MinPoint.X - ABSTANDTEXT, ext.MinPoint.Y - ABSTANDTEXT, ext.MinPoint.Z);
                        _AcGe.Point3d   maxExt = new _AcGe.Point3d(ext.MaxPoint.X + ABSTANDTEXT, ext.MaxPoint.Y + ABSTANDTEXT, ext.MaxPoint.Z);

                        List <_AcDb.ObjectId> rbsToIgnoreCol = GetFgAnz(minExt, maxExt, elFG);
                        if (rbsToIgnoreCol.Count > 0)
                        {
                            string handles = string.Join(",", rbsToIgnoreCol.Select(x => x.Handle.ToString()).ToArray());
                            log.DebugFormat("Zu ignorierende Raumblöcke: {0}", handles);
                        }

                        //    'raumbloecke holen
                        List <_AcDb.ObjectId> ssRB = selRB(minExt, maxExt);
                        if (ssRB.Count > 0)
                        {
                            string handles = string.Join(",", ssRB.Select(x => x.Handle.ToString()).ToArray());
                            log.DebugFormat("Raumblöcke: {0}", handles);
                        }


                        int rbAnz = 0;
                        //    'raumbloecke pruefen
                        for (int rbCnt = 0; rbCnt < ssRB.Count; rbCnt++)
                        {
                            _AcDb.ObjectId rbBlock2 = ssRB[rbCnt];

                            //      ' ignore rbs
                            _AcDb.ObjectId found = rbsToIgnoreCol.FirstOrDefault(x => x.Equals(rbBlock2));
                            if (found != default(_AcDb.ObjectId))
                            {
                                continue;
                            }

                            using (_AcDb.DBObject dbObj = tm.GetObject(rbBlock2, _AcDb.OpenMode.ForRead, false))
                            {
                                _AcGe.Point3d rbEp = ((_AcDb.BlockReference)dbObj).Position;

                                using (_AcDb.Entity elFGEnt = (_AcDb.Entity)tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false))
                                {
                                    if (AreaEngine.InPoly(rbEp, elFGEnt))
                                    {
                                        log.DebugFormat("Raumblock {0} ist innerhalb der Flächengrenze.", rbBlock2.Handle.ToString());

                                        if (_Raumbloecke.Contains(rbBlock2))
                                        {
                                            _Raumbloecke.Remove(rbBlock2);
                                        }
                                        rbAnz++;
                                        rbInd = rbCnt;
                                    }
                                    else
                                    {
                                        log.DebugFormat("Außen liegender Raumblock {0} wird ignoriert.", rbBlock2.Handle.ToString());
                                    }
                                }
                            }
                        }


                        if (rbAnz < 1)
                        {
                            log.WarnFormat("Kein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString());
                            //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG));
                            fehlerKeinRb++;
                        }
                        else if (rbAnz > 1)
                        {
                            log.WarnFormat("Mehr als ein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString());
                            //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG));
                            fehlerMehrRb++;
                        }
                        else
                        {
                            using (var tr = doc.TransactionManager.StartTransaction())
                            {
                                var pt = Globs.GetLabelPoint(elFG);
                                if (pt.HasValue)
                                {
                                    var rblock = tr.GetObject(ssRB[rbInd], _AcDb.OpenMode.ForWrite) as _AcDb.BlockReference;

                                    var pos = rblock.GetCenter();
                                    if (!pos.HasValue)
                                    {
                                        pos = rblock.Position;
                                    }
                                    _AcGe.Vector3d acVec3d = pos.Value.GetVectorTo(pt.Value);
                                    rblock.TransformBy(_AcGe.Matrix3d.Displacement(acVec3d));
                                    ed.WriteMessage("\nCentroid is {0}", pt);
                                }
                                else
                                {
                                    var    poly = tr.GetObject(elFG, _AcDb.OpenMode.ForRead) as _AcDb.Polyline;
                                    string msg  = string.Format(CultureInfo.CurrentCulture, "\nFläche {0}. Centroid liegt außerhalb.", poly.Handle.ToString());
                                    ed.WriteMessage(msg);
                                    log.Warn(msg);
                                }

                                tr.Commit();
                            }
                        }
                    }

                    //if (_Raumbloecke.Count > 0)
                    //{
                    //    List<object> insPoints = new List<object>();
                    //    for (int i = 0; i < _Raumbloecke.Count; i++)
                    //    {
                    //        _AcIntCom.AcadBlockReference rbBlock = (_AcIntCom.AcadBlockReference)Globs.ObjectIdToAcadEntity(_Raumbloecke[i], tm);
                    //        insPoints.Add(rbBlock.InsertionPoint);
                    //    }

                    //    _AcCm.Color col = _AcCm.Color.FromRgb((byte)0, (byte)255, (byte)0);

                    //    Plan2Ext.Globs.InsertFehlerLines(insPoints, _LooseBlockLayer, 50, Math.PI * 1.25, col);

                    //}



                    if (fehlerKeinRb > 0 || fehlerMehrRb > 0 || fehlerWertFalsch > 0 || _Raumbloecke.Count > 0)
                    {
                        string msg = string.Format(CultureInfo.CurrentCulture, "Räume ohne Raumblock: {0}\nRäume mit mehr als einem Raumblock: {1}\nRäume mit falschem Wert in Raumblock: {2}\nRaumblöcke ohne entsprechende Flächengrenzen: {3}", fehlerKeinRb, fehlerMehrRb, fehlerWertFalsch, _Raumbloecke.Count);
                        log.Debug(msg);
                        _AcAp.Application.ShowAlertDialog(msg);
                    }

                    //If wucs = 0 Then
                    //    ThisDrawing.SendCommand "(command ""_.UCS"" ""_P"") "
                    //End If

                    myT.Commit();
                }
                finally
                {
                    myT.Dispose();
                }
            }
            finally
            {
                doc.Editor.CurrentUserCoordinateSystem = ucs;
            }
        }
示例#15
0
 private static void FehlerLineOrHatchPoly(_AcDb.ObjectId oid, string layer, int red, int green, int blue, _AcDb.TransactionManager tm, _AcGe.Point3d?label)
 {
     if (label.HasValue)
     {
         _AcCm.Color col = _AcCm.Color.FromRgb((byte)red, (byte)green, (byte)blue);
         Plan2Ext.Globs.InsertFehlerLines(new List <_AcGe.Point3d> {
             label.Value
         }, layer, 50, Math.PI * 1.25, col);
     }
     else
     {
         HatchPoly(oid, layer, red, green, blue, tm);
     }
 }
        private static bool PolyInPoly(_AcDb.TransactionManager tm, _AcDb.ObjectId oid, _AcDb.ObjectId elFG)
        {
            using (_AcDb.DBObject pEntity = tm.GetObject(oid, _AcDb.OpenMode.ForRead, false))
            {
                using (_AcDb.DBObject pElFG = tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false))
                {
                    if (pEntity is _AcDb.Polyline2d)
                    {
                        _AcDb.Polyline2d oldPolyline = (_AcDb.Polyline2d)pEntity;
                        foreach (_AcDb.ObjectId Vertex2d in oldPolyline)
                        {
                            using (_AcDb.DBObject dbobj = tm.GetObject(Vertex2d, _AcDb.OpenMode.ForRead, false))
                            {
                                _AcDb.Vertex2d vertex = dbobj as _AcDb.Vertex2d;

                                if (vertex == null)
                                {
                                    string msg = string.Format(CultureInfo.CurrentCulture, "Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", oldPolyline.Handle.ToString(), dbobj.GetType().ToString());
                                    throw new InvalidOperationException(string.Format(msg));
                                }

                                _AcGe.Point3d vertexPoint = oldPolyline.VertexPosition(vertex);
                                if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG))
                                {
                                    return(false);
                                }
                            }
                        }
                        return(true);
                    }
                    else if (pEntity is _AcDb.Polyline3d)
                    {
                        _AcDb.Polyline3d poly3d = (_AcDb.Polyline3d)pEntity;
                        foreach (_AcDb.ObjectId Vertex3d in poly3d)
                        {
                            using (_AcDb.DBObject dbobj = tm.GetObject(Vertex3d, _AcDb.OpenMode.ForRead, false))
                            {
                                _AcDb.PolylineVertex3d vertex = dbobj as _AcDb.PolylineVertex3d;

                                if (vertex == null)
                                {
                                    string msg = string.Format(CultureInfo.CurrentCulture, "3D-Polylinie {0} gibt falsches Objekt {1} als Vertex zurück.", poly3d.Handle.ToString(), dbobj.GetType().ToString());
                                    throw new InvalidOperationException(string.Format(msg));
                                }

                                _AcGe.Point3d vertexPoint = vertex.Position;
                                if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG))
                                {
                                    return(false);
                                }
                            }
                        }
                        return(true);
                    }
                    else if (pEntity is _AcDb.Polyline)
                    {
                        _AcDb.Polyline poly = pEntity as _AcDb.Polyline;
                        for (int i = 0; i < poly.NumberOfVertices; i++)
                        {
                            _AcGe.Point3d vertexPoint = poly.GetPoint3dAt(i);
                            if (!AreaEngine.InPoly(vertexPoint, (_AcDb.Entity)pElFG))
                            {
                                return(false);
                            }
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#17
0
        private static void HatchPoly(_AcDb.ObjectId oid, string layer, int red, int green, int blue, _AcDb.TransactionManager tm)
        {
            string patternName    = "_SOLID";
            bool   bAssociativity = false;

            _AcIntCom.AcadEntity oPoly       = Plan2Ext.Globs.ObjectIdToAcadEntity(oid, tm);
            _AcIntCom.AcadEntity oCopiedPoly = null;
            if (oPoly is _AcIntCom.AcadPolyline)
            {
                _AcIntCom.AcadPolyline poly1 = (_AcIntCom.AcadPolyline)oPoly;
                oCopiedPoly = (_AcIntCom.AcadEntity)poly1.Copy();
                ((_AcIntCom.AcadPolyline)oCopiedPoly).Closed = true;
            }
            else if (oPoly is _AcIntCom.AcadLWPolyline)
            {
                _AcIntCom.AcadLWPolyline poly2 = (_AcIntCom.AcadLWPolyline)oPoly;
                oCopiedPoly = (_AcIntCom.AcadEntity)poly2.Copy();
                ((_AcIntCom.AcadLWPolyline)oCopiedPoly).Closed = true;
            }
            else // 3dpoly
            {
                _AcIntCom.Acad3DPolyline poly2 = (_AcIntCom.Acad3DPolyline)oPoly;
                oCopiedPoly = (_AcIntCom.AcadEntity)poly2.Copy();
                ((_AcIntCom.Acad3DPolyline)oCopiedPoly).Closed = true;
            }

            //' Create the non associative Hatch object in model space
            _AcInt.AcadApplication app = (_AcInt.AcadApplication)_AcAp.Application.AcadApplication;
            //log.Info("1..");
            //Autodesk.AutoCAD.Interop.AcadApplication abc = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
            //log.Info("2..");

            _AcIntCom.AcadHatch     hatchObj = app.ActiveDocument.ModelSpace.AddHatch(AcPatternType, patternName, bAssociativity, AcHatchObject);
            _AcIntCom.AcadAcCmColor col1     = new _AcIntCom.AcadAcCmColor(); // app.GetInterfaceObject(COLOROBJECTPROGID) as AcadAcCmColor;
            //AcadAcCmColor col2 = app.GetInterfaceObject(COLOROBJECTPROGID) as AcadAcCmColor;
            col1.SetRGB(red, green, blue);
            hatchObj.TrueColor = col1;
            _AcIntCom.AcadEntity[] outerLoop = new _AcIntCom.AcadEntity[] { oCopiedPoly };
            hatchObj.AppendOuterLoop(outerLoop);
            SetLayer((_AcIntCom.AcadEntity)hatchObj, layer);
            if (oCopiedPoly != null)
            {
                oCopiedPoly.Delete();
            }
        }
        private void ZoomToFlaechenGrenzen()
        {
            log.DebugFormat(CultureInfo.CurrentCulture, "Zoom auf Flächengrenzen");
            if (_FlaechenGrenzen.Count == 0)
            {
                return;
            }

            double MinX, MinY, MaxX, MaxY;

            _AcAp.Document           doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database           db  = doc.Database;
            _AcEd.Editor             ed  = doc.Editor;
            _AcDb.TransactionManager tm  = db.TransactionManager;
            _AcDb.Transaction        myT = tm.StartTransaction();
            try
            {
                _AcDb.Extents3d ext = GetExtents(tm, _FlaechenGrenzen[0]);
                MinX = ext.MinPoint.X;
                MinY = ext.MinPoint.Y;
                MaxX = ext.MaxPoint.X;
                MaxY = ext.MaxPoint.Y;

                for (int i = 1; i < _FlaechenGrenzen.Count; i++)
                {
                    _AcDb.ObjectId oid = _FlaechenGrenzen[i];
                    ext = GetExtents(tm, oid);
                    if (ext.MinPoint.X < MinX)
                    {
                        MinX = ext.MinPoint.X;
                    }
                    if (ext.MinPoint.Y < MinY)
                    {
                        MinY = ext.MinPoint.Y;
                    }
                    if (ext.MaxPoint.X > MaxX)
                    {
                        MaxX = ext.MaxPoint.X;
                    }
                    if (ext.MaxPoint.Y > MaxY)
                    {
                        MaxY = ext.MaxPoint.Y;
                    }
                }


                //Globs.Zoom( new Point3d(MinX, MinY, 0.0), new Point3d(MaxX, MaxY, 0.0),new Point3d(), 1.0);
                //Globs.ZoomWin3(ed, new Point3d(MinX, MinY, 0.0), new Point3d(MaxX, MaxY, 0.0));
                //Globs.ZoomWin2(ed, new Point3d(MinX, MinY, 0.0), new Point3d(MaxX, MaxY, 0.0));

                myT.Commit();
            }
            finally
            {
                myT.Dispose();
            }

            // Rauszoomen, sonst werden Blöcken nicht gefunden, die außerhalb der Flächengrenzen liegen.
            MinX -= ABSTANDTEXT;
            MinY -= ABSTANDTEXT;
            MaxX += ABSTANDTEXT;
            MaxY += ABSTANDTEXT;

            Globs.Zoom(new _AcGe.Point3d(MinX, MinY, 0.0), new _AcGe.Point3d(MaxX, MaxY, 0.0), new _AcGe.Point3d(), 1.0);
        }
示例#19
0
        public void Draw(string block, string Basislayer)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            _AcDb.TransactionManager myTm       = db.TransactionManager;
            Transaction          myT            = db.TransactionManager.StartTransaction();
            Editor               ed             = Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectContextManager conTextManager = db.ObjectContextManager;

            Dictionary <string, Point3d> _attPos = new Dictionary <string, Point3d>();
            List <AttributeDefinition>   _attDef = new List <AttributeDefinition>();

            MyLayer objLayer = MyLayer.Instance;

            //objLayer.CheckLayer(Basislayer, true);

            try
            {
                using (DocumentLock dl = Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    //Block in Zeichnung einfügen
                    BlockTable       bt     = (BlockTable)myT.GetObject(db.BlockTableId, OpenMode.ForRead);
                    BlockTableRecord btr    = (BlockTableRecord)myT.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                    BlockTableRecord btrDef = (BlockTableRecord)myT.GetObject(bt[block], OpenMode.ForRead);

                    //Attribute aus Blockdefinition übernehmen
                    if (btrDef.HasAttributeDefinitions)
                    {
                        foreach (ObjectId id in btrDef)
                        {
                            DBObject obj = myT.GetObject(id, OpenMode.ForRead);
                            try
                            {
                                AttributeDefinition ad = (AttributeDefinition)obj;

                                if (ad != null)
                                {
                                    _attPos.Add(ad.Tag, ad.Position);
                                    _attDef.Add(ad);
                                }
                            }
                            catch
                            {
                                try
                                {
                                    Entity ent = (Entity)obj;
                                    //Layer = ent.Layer;
                                }
                                catch { }
                            }
                        }
                    }

                    BlockReference blkRef = new BlockReference(_Pos3d, bt[block])
                    {
                        ScaleFactors = new Scale3d(db.Cannoscale.Scale),
                        Layer        = Basislayer
                    };
                    btr.AppendEntity(blkRef);

                    //XData schreiben
                    RegAppTable acRegAppTbl;
                    acRegAppTbl = (RegAppTable)myT.GetObject(db.RegAppTableId, OpenMode.ForRead);

                    if (!acRegAppTbl.Has(Global.Instance.AppName))
                    {
                        using (RegAppTableRecord acRegAppTblRec = new RegAppTableRecord())
                        {
                            acRegAppTblRec.Name = Global.Instance.AppName;

                            acRegAppTbl.UpgradeOpen();
                            acRegAppTbl.Add(acRegAppTblRec);
                            myT.AddNewlyCreatedDBObject(acRegAppTblRec, true);
                        }
                    }

                    using (ResultBuffer rb = new ResultBuffer())
                    {
                        rb.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, Global.Instance.AppName));
                        rb.Add(new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, _Pos3d));
                        if (_HöheOrg != null)
                        {
                            rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, _HöheOrg));
                        }
                        blkRef.XData = rb;
                        rb.Dispose();
                    }

                    myT.AddNewlyCreatedDBObject(blkRef, true);

                    //Attribute befüllen
                    if (_attPos != null)
                    {
                        string[] lsBasislayer = Basislayer.Split('-');
                        string   Stammlayer   = lsBasislayer[lsBasislayer.Length - 2];

                        for (int i = 0; i < _attPos.Count; i++)
                        {
                            AttributeReference _attRef = new AttributeReference();
                            _attRef.SetDatabaseDefaults();
                            _attRef.SetAttributeFromBlock(_attDef[i], Matrix3d.Identity);
                            _attRef.SetPropertiesFrom(_attDef[i]);

                            Point3d ptBase = new Point3d(blkRef.Position.X + _attRef.Position.X,
                                                         blkRef.Position.Y + _attRef.Position.Y,
                                                         blkRef.Position.Z + _attRef.Position.Z);


                            _attRef.Position = ptBase;

                            string attLayer = String.Empty;

                            KeyValuePair <string, Point3d> keyValuePair = _attPos.ElementAt(i);
                            switch (keyValuePair.Key)
                            {
                            case "number":
                                _attRef.TextString = _PNum;
                                _attRef.Layer      = Stammlayer + Global.Instance.LayNummer;
                                break;

                            case "height":
                                if (_HöheOrg != null)
                                {
                                    _attRef.TextString = _HöheOrg;
                                    _attRef.Layer      = Stammlayer + Global.Instance.LayHöhe;
                                }

                                break;

                            case "date":
                                _attRef.Layer = Stammlayer + "-Datum";
                                _attRef.Layer = Stammlayer + Global.Instance.LayDatum;
                                break;

                            case "code":
                                _attRef.Layer = Stammlayer + "-Code";
                                _attRef.Layer = Stammlayer + Global.Instance.LayCode;
                                break;

                            case "owner":
                                _attRef.Layer = Stammlayer + "-Hersteller";
                                break;

                            default:
                                break;
                            }

                            blkRef.AttributeCollection.AppendAttribute(_attRef);
                            myT.AddNewlyCreatedDBObject(_attRef, true);
                        }
                        blkRef.Dispose();
                    }
                }
            }
            //Block aus Prototypzeichnung holen
            catch { }

            finally
            {
                myT.Commit();
                myT.Dispose();
            }
        }
示例#20
0
 public CenterRaumBlock()
 {
     _TransMan = _AcAp.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager;
 }
示例#21
0
        public DiaSettings()
        {
            InitializeComponent();

            //Init Configuration
            //Basislayer
            value = _config.GetAppSettingString("Basislayer");
            if (value == String.Empty)
            {
                _config.SetAppSetting("Basislayer", "MP-P");
            }

            //Header
            value = _config.GetAppSettingString("useHeader");
            if (value == String.Empty)
            {
                _config.SetAppSetting("useHeader", "False");
            }
            cB_Header.Checked = Convert.ToBoolean(value);

            value = _config.GetAppSettingString("Header");
            if (value == String.Empty)
            {
                _config.SetAppSetting("Header", "PNr, X,Y,Z");
            }
            tb_Header.Text = value;

            //3dImport
            value = _config.GetAppSettingString("3dImport");
            if (value == String.Empty)
            {
                _config.SetAppSetting("3dImport", "False");
            }
            cb_3dImport.Checked = Convert.ToBoolean(value);

            //Output File
            value = _config.GetAppSettingString("OutputFile");
            if (File.Exists(value))
            {
                tb_PunktExport.Text   = value;
                cB_ExportFile.Enabled = File.Exists(value);

                value = _config.GetAppSettingString("useOutputFile");
                if (value == String.Empty)
                {
                    _config.SetAppSetting("useOutputFile", "False");
                }

                cB_OutputFile.Checked = Convert.ToBoolean(value);
            }
            else
            {
                tb_PunktExport.Text = " ";
            }

            //Separator & Decimal
            value = _config.GetAppSettingString("Separator");
            if (value == String.Empty)
            {
                _config.SetAppSetting("Separator", ";");
            }
            tB_Separator.Text = value;

            value = _config.GetAppSettingString("Decimal");
            if (value == String.Empty)
            {
                _config.SetAppSetting("Decimal", ".");
            }
            cb_Decimal.SelectedItem = value;
            cb_Decimal.Refresh();

            value = _config.GetAppSettingString("decimals");
            if (value == "")
            {
                value = "3";
                _config.SetAppSetting("decimals", value);
            }
            numUD_Kommastellen.Value = Convert.ToInt32(value);

            //import Exportfile
            value = _config.GetAppSettingString("importExportfile");
            if (value == String.Empty)
            {
                cB_ExportFile.Checked = false;
            }
            else
            {
                cB_ExportFile.Checked = Convert.ToBoolean(value);
            }

            //Treenode
            TreeNode root = treeView1.Nodes.Add("CAS 2019");

            //root.Nodes.Add("general");
            root.Nodes.Add("Import");
            root.Nodes.Add("Export");
            root.ExpandAll();
            treeView1.SelectedNode = root.FirstNode;

            //Basislayer
            myCAD.MyLayer objLayer = myCAD.MyLayer.Instance;
            objLayer.Refresh();

            try
            {
                foreach (_AcDb.LayerTableRecord ltr in objLayer.LsLayerTableRecord)
                {
                    string layName = ltr.Name;
                    if (layName.Length > 2)
                    {
                        if (layName.Substring(layName.Length - 2, 2) == "-P")
                        {
                            cbBasislayer.Items.Add(layName);
                        }
                    }
                }
            }
            catch { }

            cbBasislayer.SelectedIndex = cbBasislayer.FindStringExact(_config.GetAppSettingString("Basislayer"));

            if (cbBasislayer.SelectedIndex == -1)
            {
                if (cbBasislayer.Items.Count > 0)
                {
                    DialogResult res = MessageBox.Show(_config.GetAppSettingString("Basislayer")
                                                       + " nicht gefunden! Soll dieser Layer erstellt werden?", "",
                                                       MessageBoxButtons.YesNo);
                    if (res == DialogResult.Yes)
                    {
                        objLayer.Add(_config.GetAppSettingString("Basislayer"));
                    }
                }
                else
                {
                    string Basislayer = _config.GetAppSettingString("Basislayer");
                    CheckBasislayer();

                    cbBasislayer.Items.Add(Basislayer);
                    cbBasislayer.SelectedItem = cbBasislayer.Items[0];
                }
            }

            //Blöcke aus Protoypzeichnung lesen
            _AcAp.Document     myDWG;
            _AcAp.DocumentLock myDWGlock;
            Database           db = HostApplicationServices.WorkingDatabase;

            _AcDb.TransactionManager myTm = null;
            myTm = db.TransactionManager;
            Transaction myT = db.TransactionManager.StartTransaction();

            string ProtoDWG = CAS.myUtilities.Global.Instance.PrototypFullPath;

            lb_Prototypzeichnung.Text = ProtoDWG;

            if (File.Exists(ProtoDWG))
            {
                try
                {
                    myDWG     = _AcAp.Application.DocumentManager.MdiActiveDocument;
                    myDWGlock = myDWG.LockDocument();

                    using (Database srcDb = new Database(false, false))
                    {
                        srcDb.ReadDwgFile(ProtoDWG, FileShare.Read, true, "");
                        ObjectIdCollection blockIds = new ObjectIdCollection();

                        _AcDb.TransactionManager srcT = srcDb.TransactionManager;
                        try
                        {
                            using (Transaction protoT = srcT.StartTransaction())
                            {
                                BlockTable bt = (BlockTable)protoT.GetObject(srcDb.BlockTableId, OpenMode.ForRead, false);

                                foreach (ObjectId btrid in bt)
                                {
                                    BlockTableRecord btr = (BlockTableRecord)protoT.GetObject(btrid, OpenMode.ForRead, false);
                                    if (!btr.IsAnonymous && !btr.IsLayout)
                                    {
                                        blockIds.Add(btrid);
                                        cbBlock.Items.Add(btr.Name);
                                    }
                                    btr.Dispose();
                                }
                                protoT.Commit();
                                protoT.Dispose();
                            }
                        }
                        catch { }

                        finally
                        {
                            myT.Commit();
                            myT.Dispose();
                        }

                        //Blöcke in aktuelle Zeichnung einfügen
                        IdMapping mapping = new IdMapping();
                        srcDb.WblockCloneObjects(blockIds, db.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);

                        srcDb.Dispose();
                        myDWGlock.Dispose();
                    }
                }
                catch { }
            }
            else
            {
                MessageBox.Show("Achtung!!! Prototypzeichnung nicht gefunden!");
            }

            if (cbBlock.Items.Count > 0)
            {
                try
                {
                    cbBlock.SelectedIndex = cbBlock.FindStringExact(_config.GetAppSettingString("Block"));   //Block aus settings.xml suchen
                }
                catch
                {
                    cbBlock.SelectedItem = cbBlock.Items[0];  //sonst ersten Block wählen
                }
            }

            else
            {
                MessageBox.Show("Keine Blöcke gefunden!");
            }

            //Header
            cB_Header.Checked = _config.GetAppSettingBool("useHeader");
            tb_Header.Text    = _config.GetAppSettingString("Header");

            //Output File
            cB_OutputFile.Checked = _config.GetAppSettingBool("useOutputFile");
            tb_PunktExport.Text   = _config.GetAppSettingString("OutputFile");
        }