Example #1
0
        private void ExplodeBlocks(_AcDb.Database db, List <_AcDb.ObjectId> allXrefsInMs, List <_AcDb.ObjectId> newlyCreatedObjects, bool deleteRef, bool deleteBtr)
        {
            log.Debug("ExplodeXRefs");
            using (_AcDb.Transaction tr = _TransMan.StartTransaction())
            {
                _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);

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


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


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

                        newlyCreatedObjects.Add(ent.ObjectId);
                    }

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

                    if (deleteBtr)
                    {
                        log.DebugFormat("DeleteBtr");
                        // funkt nicht -> xref würde gelöscht
                        var bd = (_AcDb.BlockTableRecord)tr.GetObject(blockRefTableId, _AcDb.OpenMode.ForWrite);
                        bd.Erase();
                        log.DebugFormat("Endof DeleteBtr");
                    }
                }
                tr.Commit();
            }
        }
Example #2
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);
        }
Example #3
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();
            }
        }
Example #4
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);
            }
        }
        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);
        }
Example #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);
        }
Example #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));
            }
        }
Example #8
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));
            }
        }
        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;
            }
        }
        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);
        }
Example #11
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");
        }
Example #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);
        }
Example #13
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);
        }