Ejemplo n.º 1
0
        static public void Plan2CenterBlockSelBlock()
        {
            try
            {
                if (!OpenPalette())
                {
                    return;
                }

                var            opts = Globs.TheOptions;
                _AcAp.Document doc  = _AcAp.Application.DocumentManager.MdiActiveDocument;

                using (_AcAp.DocumentLock m_doclock = doc.LockDocument())
                {
                    _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager;
                    if (doc == null)
                    {
                        return;
                    }
                    _AcEd.Editor ed = doc.Editor;
#if NEWSETFOCUS
                    doc.Window.Focus();
#else
                    Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions
#endif

                    _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nBlock wählen: ");

                    if (per.Status == _AcEd.PromptStatus.OK)
                    {
                        using (var tr = doc.TransactionManager.StartTransaction())
                        {
                            _AcDb.DBObject       obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead);
                            _AcDb.BlockReference br  = obj as _AcDb.BlockReference;
                            if (br == null)
                            {
                                br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per);
                                if (br == null)
                                {
                                    return;
                                }
                            }

                            opts.SetBlockname(br.Name);

                            tr.Commit();
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2CenterBlockSelBlock aufgetreten! {0}", ex.Message));
            }
        }
Ejemplo n.º 2
0
        private static bool GetAttributeInfos(_AcEd.Editor ed, _AcAp.Document doc)
        {
            bool ok = false;

            _BlockName      = string.Empty;
            _AttributeName  = string.Empty;
            _AttributeValue = string.Empty;

            _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nZu änderndes Attribut wählen: ");

            if (per.Status == _AcEd.PromptStatus.OK)
            {
                using (var tr = doc.TransactionManager.StartTransaction())
                {
                    _AcDb.DBObject           obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead);
                    _AcDb.AttributeReference ar  = obj as _AcDb.AttributeReference;
                    if (ar != null && !ar.IsConstant)
                    {
                        _AcDb.BlockReference br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per);
                        if (br != null)
                        {
                            ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nBlockname: {0}, Attributname: {1}.", Plan2Ext.Globs.GetBlockname(br, tr), ar.Tag));
                            var prompt = new _AcEd.PromptStringOptions("\nText in Attribut: ");
                            prompt.AllowSpaces = true;
                            var prefixUserRes = ed.GetString(prompt);
                            if (prefixUserRes.Status == _AcEd.PromptStatus.OK)
                            {
                                _AttributeValue = prefixUserRes.StringResult;
                                _AttributeName  = ar.Tag;
                                _BlockName      = Plan2Ext.Globs.GetBlockname(br, tr);

                                log.InfoFormat(CultureInfo.CurrentCulture, "Block: {0}, Attribut: {1}, Wert: '{2}'", _BlockName, _AttributeName, _AttributeValue);

                                ok = true;
                            }
                        }
                    }

                    tr.Commit();
                }
            }
            return(ok);
        }
Ejemplo n.º 3
0
        static public void Plan2AutoIdSelPolygonLayer()
        {
            try
            {
                if (!OpenAutoIdPalette())
                {
                    return;
                }

                var            opts = Globs.TheAutoIdOptions;
                _AcAp.Document doc  = _AcAp.Application.DocumentManager.MdiActiveDocument;

                using (_AcAp.DocumentLock m_doclock = doc.LockDocument())
                {
                    _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager;
                    if (doc == null)
                    {
                        return;
                    }
                    _AcEd.Editor ed = doc.Editor;
#if NEWSETFOCUS
                    doc.Window.Focus();
#else
                    Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions
#endif

                    _AcEd.PromptNestedEntityOptions peo = new _AcEd.PromptNestedEntityOptions("\nPolylinie wählen: ");
                    //peo.SetRejectMessage("\nDas gewählte Element ist keine Polylinie.");
                    //peo.AddAllowedClass(typeof(Polyline), true);
                    //peo.AddAllowedClass(typeof(Polyline2d), true);
                    //peo.AddAllowedClass(typeof(Polyline3d), true);

                    _AcEd.PromptEntityResult per = ed.GetNestedEntity(peo);

                    if (per.Status == _AcEd.PromptStatus.OK)
                    {
                        using (var tr = doc.TransactionManager.StartTransaction())
                        {
                            _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead);
                            _AcDb.Entity   ent = obj as _AcDb.Entity;
                            if (ent != null)
                            {
                                if (ent is _AcDb.Polyline || ent is _AcDb.Polyline2d || ent is _AcDb.Polyline3d)
                                {
                                    opts.SetPolygonLayer(Engine.RemoveXRefPart(ent.Layer));
                                }
                                else
                                {
                                    ed.WriteMessage("\nDas gewählte Element ist keine Polylinie.");
                                }
                            }

                            tr.Commit();
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2AutoIdSelPolygonLayer aufgetreten! {0}", ex.Message));
            }
        }