Beispiel #1
0
        private _Db.DBObjectCollection getGeometry()
        {
            _Db.DBObjectCollection geometry = new _Db.DBObjectCollection();

            _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions();
            opts.MessageForAdding = "\nSelect Geometry: ";
            _Ed.PromptSelectionResult userSelection = _c.doc.Editor.GetSelection(opts);
            if (userSelection.Status != _Ed.PromptStatus.OK)
            {
                throw new DMTException("[ERROR] Geometry - cancelled");
            }

            _Ed.SelectionSet selectionSet = userSelection.Value;

            foreach (_Ed.SelectedObject currentObject in selectionSet)
            {
                if (currentObject == null)
                {
                    continue;
                }

                _Db.Entity currentEntity = _c.trans.GetObject(currentObject.ObjectId, _Db.OpenMode.ForRead) as _Db.Entity;
                if (currentEntity == null)
                {
                    continue;
                }

                if (currentEntity is _Db.Curve)
                {
                    geometry.Add(currentEntity);
                }
            }

            return(geometry);
        }
Beispiel #2
0
        private void getSelectedObjects(ref List <_Db.Dimension> dims, ref List <_Db.BlockReference> blocks, ref List <_Db.MText> txts)
        {
            _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions();
            opts.MessageForAdding = "\nSelect area [empty select == ALL]";

            _Ed.PromptSelectionResult selection = _c.ed.GetSelection(opts);

            if (selection.Status == _Ed.PromptStatus.OK)
            {
                _Db.ObjectId[] selectionIds = selection.Value.GetObjectIds();
                foreach (_Db.ObjectId id in selectionIds)
                {
                    alfa(id, ref dims, ref blocks, ref txts);
                }
            }
            else if (selection.Status == _Ed.PromptStatus.Error)
            {
                _Db.BlockTableRecord btr = _c.trans.GetObject(_c.modelSpace.Id, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;

                foreach (_Db.ObjectId id in btr)
                {
                    alfa(id, ref dims, ref blocks, ref txts);
                }
            }
        }
Beispiel #3
0
        private List <_Db.BlockReference> getSelectedBlockReference(string[] blockNames)
        {
            List <_Db.BlockReference> refs = new List <_Db.BlockReference>();

            _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions();
            opts.MessageForAdding = "\nSelect BLOCK " + blockNames[0] + " / " + blockNames[1];

            _Ed.PromptSelectionResult selection = _c.ed.GetSelection(opts);

            if (selection.Status == _Ed.PromptStatus.OK)
            {
                _Db.ObjectId[] selectionIds = selection.Value.GetObjectIds();

                foreach (_Db.ObjectId id in selectionIds)
                {
                    _Db.DBObject currentEntity = _c.trans.GetObject(id, _Db.OpenMode.ForWrite, false) as _Db.DBObject;

                    if (currentEntity == null)
                    {
                        continue;
                    }

                    else if (currentEntity is _Db.BlockReference)
                    {
                        _Db.BlockReference blockRef = currentEntity as _Db.BlockReference;

                        _Db.BlockTableRecord block = null;
                        if (blockRef.IsDynamicBlock)
                        {
                            block = _c.trans.GetObject(blockRef.DynamicBlockTableRecord, _Db.OpenMode.ForRead) as _Db.BlockTableRecord;
                        }
                        else
                        {
                            block = _c.trans.GetObject(blockRef.BlockTableRecord, _Db.OpenMode.ForRead) as _Db.BlockTableRecord;
                        }

                        if (block != null)
                        {
                            if (blockNames.Contains(block.Name))
                            {
                                refs.Add(blockRef);
                            }
                        }
                    }
                }
            }

            return(refs);
        }
Beispiel #4
0
        private void getSettings()
        {
            _Db.TypedValue[] filterlist = new _Db.TypedValue[2];
            filterlist[0] = new _Db.TypedValue(0, "INSERT");
            filterlist[1] = new _Db.TypedValue(2, "Reinf_program_settings");
            _Ed.SelectionFilter filter = new _Ed.SelectionFilter(filterlist);

            _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions();
            opts.MessageForAdding = "\nSelect Reinf_program_settings block: ";

            _Ed.PromptSelectionResult selection = _c.ed.GetSelection(opts, filter);
            if (selection.Status != _Ed.PromptStatus.OK)
            {
                throw new DMTException("[ERROR] Reinf_program_settings - cancelled");
            }
            if (selection.Value.Count != 1)
            {
                throw new DMTException("[ERROR] Reinf_program_settings - too many in selection");
            }


            _Db.ObjectId       selectionId = selection.Value.GetObjectIds()[0];
            _Db.BlockReference selectionBR = _c.trans.GetObject(selectionId, _Db.OpenMode.ForWrite) as _Db.BlockReference;

            L._V_.Z_DRAWING_SCALE = selectionBR.ScaleFactors.X;

            foreach (_Db.ObjectId arId in selectionBR.AttributeCollection)
            {
                _Db.DBObject           obj = _c.trans.GetObject(arId, _Db.OpenMode.ForWrite);
                _Db.AttributeReference ar  = obj as _Db.AttributeReference;

                if (ar != null)
                {
                    setProgramVariables(ar);
                }
            }
        }
        public static void Plan2AufteilungNet()
        {
            var acadApp = (Autodesk.AutoCAD.Interop.AcadApplication)_AcAp.Application.AcadApplication;

            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            _AcEd.Editor   ed  = doc.Editor;
            try
            {
                ed.Command("_.LAYER", "_TH", "*", "_ON", "*", "_UN", "*", "");
                var selOp = new _AcEd.PromptSelectionOptions();
                selOp.MessageForAdding = "Zu verschiebende Elemente wählen: ";
                _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] {
                    new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<NOT"),
                    new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<AND"),
                    new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "*POLYLINE"),
                    new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName, "A_AL_MANSFEN"),
                    new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "AND>"),
                    new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "NOT>")
                });
                while (true)
                {
                    var res = ed.GetSelection(selOp, filter);
                    if (res.Status != _AcEd.PromptStatus.OK)
                    {
                        break;
                    }
                    else
                    {
                        var            ss     = res.Value;
                        var            selOpE = new _AcEd.PromptSelectionOptions();
                        _AcDb.ObjectId mf1    = default(_AcDb.ObjectId);
                        if (!GetMansfen("Quell-Mansfen wählen: ", ref mf1))
                        {
                            break;
                        }
                        _AcDb.ObjectId mf2 = default(_AcDb.ObjectId);
                        if (!GetMansfen("Ziel-Mansfen wählen: ", ref mf2))
                        {
                            break;
                        }

                        if (!SameMansfens(mf1, mf2))
                        {
                            ed.WriteMessage("\nDie gewählten Mansfens sind nicht identisch!");
                            System.Windows.Forms.MessageBox.Show("\nDie gewählten Mansfens sind nicht identisch!", "Plan2AufteilungNet");
                        }
                        else
                        {
                            _AcGe.Point3d fromPoint = GetLuPoint(mf1);
                            _AcGe.Point3d toPoint   = GetLuPoint(mf2);

                            string dwgName     = doc.Name;
                            var    dwgProposal = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(dwgName), System.IO.Path.GetFileNameWithoutExtension(dwgName) + "_X.dwg");
                            _AcWnd.SaveFileDialog             sfd = new _AcWnd.SaveFileDialog("Ziel-Zeichnung", dwgProposal, "dwg", "TargetDrawing", _AcWnd.SaveFileDialog.SaveFileDialogFlags.NoFtpSites);
                            System.Windows.Forms.DialogResult dr  = sfd.ShowDialog();
                            if (dr == System.Windows.Forms.DialogResult.OK)
                            {
                                var ucs        = ed.CurrentUserCoordinateSystem;
                                var fromPointU = Globs.TransWcsUcs(fromPoint); // fromPoint.TransformBy(ucs);
                                var toPointU   = Globs.TransWcsUcs(toPoint);   // toPoint.TransformBy(ucs);


                                // only acad2015 -
                                ed.Command("_.UNDO", "_M");

                                ed.Command("_.DIMDISASSOCIATE", ss, "");

                                ed.Command("_.MOVE", ss, "", fromPointU, toPointU);
                                //ed.Command("_.MOVE", ss, "", "0,0", "100,100");
                                ed.Command("_.ERASE", "_ALL", "_R", ss, mf2, "");

                                doc.Database.SaveAs(sfd.Filename, false, _AcDb.DwgVersion.Current, doc.Database.SecurityParameters);

                                ed.Command("_.UNDO", "_B");
                                //doc.SendStringToExecute("._UNDO B", true, false, true);
                                // also supports acad2013
                                doc.SendStringToExecute(".'_UNDO M ", true, false, true);
                                //acadApp.ActiveDocument.SendCommand("_.UNDO _M\n");
                                //acadApp.ActiveDocument.SendCommand("_.DIMDISASSOCIATE _P \n");
                            }
                        }

                        Globs.HightLight(mf1, onOff: false);
                        Globs.HightLight(mf2, onOff: false);
                    }
                }
            }
            catch (System.Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2AufteilungNet): {0}", ex.Message);
                ed.WriteMessage("\n" + msg);
                System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2AufteilungNet");
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        private List <G.Line> getGeometry()
        {
            List <G.Line> polys = new List <G.Line>();

            _Ed.PromptSelectionOptions opts = new _Ed.PromptSelectionOptions();
            opts.MessageForAdding = "\nSelect Geometry: ";

            _Ed.PromptSelectionResult userSelection = _c.doc.Editor.GetSelection(opts);

            if (userSelection.Status != _Ed.PromptStatus.OK)
            {
                throw new DMTException("[ERROR] Geometry - cancelled");
            }

            _Ed.SelectionSet selectionSet = userSelection.Value;

            foreach (_Ed.SelectedObject currentObject in selectionSet)
            {
                if (currentObject == null)
                {
                    continue;
                }
                _Db.Entity currentEntity = _c.trans.GetObject(currentObject.ObjectId, _Db.OpenMode.ForRead) as _Db.Entity;
                if (currentEntity == null)
                {
                    continue;
                }

                if (currentEntity is _Db.Polyline)
                {
                    _Db.Polyline poly   = _c.trans.GetObject(currentEntity.ObjectId, _Db.OpenMode.ForRead) as _Db.Polyline;
                    int          points = poly.NumberOfVertices;

                    for (int i = 1; i < points; i++)
                    {
                        _Ge.Point2d p1 = poly.GetPoint2dAt(i - 1);
                        _Ge.Point2d p2 = poly.GetPoint2dAt(i);

                        G.Point new_p1 = new G.Point(p1.X, p1.Y);
                        G.Point new_p2 = new G.Point(p2.X, p2.Y);

                        if (new_p1 == new_p2)
                        {
                            continue;
                        }

                        G.Line line = new G.Line(new_p1, new_p2);
                        if (!polys.Contains(line))
                        {
                            polys.Add(line);
                        }
                    }

                    if (poly.Closed)
                    {
                        _Ge.Point2d p1     = poly.GetPoint2dAt(points - 1);
                        _Ge.Point2d p2     = poly.GetPoint2dAt(0);
                        G.Point     new_p1 = new G.Point(p1.X, p1.Y);
                        G.Point     new_p2 = new G.Point(p2.X, p2.Y);

                        if (new_p1 == new_p2)
                        {
                            continue;
                        }

                        G.Line line = new G.Line(new_p1, new_p2);
                        if (!polys.Contains(line))
                        {
                            polys.Add(line);
                        }
                    }
                }
            }

            if (polys.Count < 3)
            {
                throw new DMTException("[ERROR] Geometry - less then 3");
            }

            return(polys);
        }