Esempio n. 1
0
        // Helper functions to zoom using different techniques


        // Zoom using a view object


        private static void ZoomWin(

            _AcEd.Editor ed, _AcGe.Point3d min, _AcGe.Point3d max

            )
        {
            _AcGe.Point2d min2d = new _AcGe.Point2d(min.X, min.Y);

            _AcGe.Point2d max2d = new _AcGe.Point2d(max.X, max.Y);


            _AcDb.ViewTableRecord view =

                new _AcDb.ViewTableRecord();


            view.CenterPoint =

                min2d + ((max2d - min2d) / 2.0);

            view.Height = max2d.Y - min2d.Y;

            view.Width = max2d.X - min2d.X;

            ed.SetCurrentView(view);
        }
Esempio n. 2
0
        public static void Plan2SetCtbInLayouts()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _Db = doc.Database;
            _AcEd.Editor ed = doc.Editor;
            _CtbName = string.Empty;
            _DwgsWrongCtb.Clear();
            _NrCtbs = 0;

            try
            {
                if (!GetCtbName(ed))
                {
                    return;
                }
                if (!SetCtbInLayouts())
                {
                    string msg = string.Format(CultureInfo.CurrentCulture, "Ctb '{0}' existiert nicht!", _CtbName);
                    ed.WriteMessage("\n" + msg);
                    System.Windows.Forms.MessageBox.Show(msg, "Plan2SetCtbInLayouts");
                }
                else
                {
                    string resultMsg = string.Format(CultureInfo.CurrentCulture, "Anzahl gesetzter CTBs: {0}", _NrCtbs.ToString());
                    log.Info(resultMsg);
                    System.Windows.Forms.MessageBox.Show(resultMsg, "Plan2SetCtb");
                }
            }
            catch (System.Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2SetCtbInLayouts): {0}", ex.Message);
                ed.WriteMessage("\n" + msg);
                System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2SetCtbInLayouts");
            }
        }
Esempio n. 3
0
        // Zoom via COM


        private static void ZoomWin2(

            _AcEd.Editor ed, _AcGe.Point3d min, _AcGe.Point3d max

            )
        {
            _AcInt.AcadApplication app =

                (_AcInt.AcadApplication)_AcAp.Application.AcadApplication;


            double[] lower =

                new double[3] {
                min.X, min.Y, min.Z
            };

            double[] upper

                = new double[3] {
                max.X, max.Y, max.Z
                };


            app.ZoomWindow(lower, upper);
        }
Esempio n. 4
0
        public static void ChangeEntColour()
        {
            //
            // Get some user input:
            //
            _AcEd.Editor             ed  = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            _AcEd.PromptEntityResult res = ed.GetEntity("Select an entity to change its colour:");

            if (res.Status == _AcEd.PromptStatus.OK)
            {
                var entId = res.ObjectId;

                var db = _AcDb.HostApplicationServices.WorkingDatabase;
                using (var tr = db.TransactionManager.StartTransaction()) {
                    var ent = tr.GetObject(entId, Teigha.DatabaseServices.OpenMode.ForWrite) as _AcDb.Entity;

                    //
                    // Ask the user for the new colour number
                    //
                    _AcEd.PromptIntegerResult intres = ed.GetInteger("\nEnter new colorindex integer (0 -> 255): ");

                    if (intres.Status == _AcEd.PromptStatus.OK)
                    {
                        ent.ColorIndex = intres.Value;
                    }
                    tr.Commit();
                }
            }
        }
Esempio n. 5
0
        static public void GetXData()
        {
            AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument;
            AcEd.Editor   ed  = doc.Editor;

            AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: ");
            AcEd.PromptEntityResult  res = ed.GetEntity(opt);

            if (res.Status == AcEd.PromptStatus.OK)
            {
                using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction())
                {
                    AcDb.DBObject     obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForRead);
                    AcDb.ResultBuffer rb  = obj.XData;
                    if (rb == null)
                    {
                        ed.WriteMessage("\nEntity does not have XData attached.");
                    }
                    else
                    {
                        int n = 0;
                        foreach (AcDb.TypedValue tv in rb)
                        {
                            ed.WriteMessage("\nTypedValue {0} - type: {1}, value: {2}", n++, tv.TypeCode, tv.Value);
                        }
                        rb.Dispose();
                    }
                }
            }
        }
Esempio n. 6
0
        public void Initialize()
        {
            _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            CAS.myFunctions.DiaSettings objSettings = new myFunctions.DiaSettings();

            ed.WriteMessage("CAS installed");
        }
        private static bool SetPlotSettings(string loName, string device, string pageSize, string styleSheet, double?scaleNumerator, double?scaleDenominator, short?plotRotation)
        {
            _AcAp.Document      doc       = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database      db        = doc.Database;
            _AcEd.Editor        ed        = doc.Editor;
            _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current;

            var layoutId = layoutMgr.GetLayoutId(loName);

            if (!layoutId.IsValid)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Layout '{0}' existiert nicht!", loName));
            }

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var layout = (_AcDb.Layout)tr.GetObject(layoutId, _AcDb.OpenMode.ForWrite);

                layout.SetPlotSettings(device, pageSize, styleSheet, scaleNumerator, scaleDenominator, plotRotation);

                tr.Commit();
            }

            return(true);
        }
Esempio n. 8
0
        public static bool CallCropBat(_AcDb.ResultBuffer rb)
        {
            _AcEd.Editor ed       = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            string       taskName = "CallCropBat";

            try
            {
                using (TaskService tasksrvc = new TaskService("server", "pdfcrop", "workgroup", "pdf"))
                {
                    Task task = tasksrvc.FindTask(taskName);
                    if (task != null)
                    {
                        var t1 = task.Run();
                        ed.WriteMessage(string.Format("\nTask '{0}' ausgeführt.", taskName));
                        return(true);
                    }
                    else
                    {
                        ed.WriteMessage(string.Format("\nTask '{0}' nicht gefunden!", taskName));
                    }
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nFehler in CallCropBat! {0}'", ex.Message));
            }
            return(false);
        }
Esempio n. 9
0
        static public void DynamicBlockProps()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcDb.Database db  = doc.Database;
            _AcEd.Editor   ed  = doc.Editor;

            _AcEd.PromptStringOptions pso = new _AcEd.PromptStringOptions("\nEnter dynamic block name or enter to select: ");
            pso.AllowSpaces = true;
            _AcEd.PromptResult pr = ed.GetString(pso);

            if (pr.Status != _AcEd.PromptStatus.OK)
            {
                return;
            }

            _AcDb.Transaction tr = db.TransactionManager.StartTransaction();
            using (tr)
            {
                _AcDb.BlockReference br = null;
                // If a null string was entered allow entity selection
                if (pr.StringResult == "")
                {
                    // Select a block reference
                    _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions("\nSelect dynamic block reference: ");
                    peo.SetRejectMessage("\nEntity is not a block.");
                    peo.AddAllowedClass(typeof(_AcDb.BlockReference), false);

                    _AcEd.PromptEntityResult per = ed.GetEntity(peo);
                    if (per.Status != _AcEd.PromptStatus.OK)
                    {
                        return;
                    }

                    // Access the selected block reference
                    br = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference;
                }

                else
                {
                    // Otherwise we look up the block by name
                    _AcDb.BlockTable bt = tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable;
                    if (!bt.Has(pr.StringResult))
                    {
                        ed.WriteMessage("\nBlock \"" + pr.StringResult + "\" does not exist.");
                        return;
                    }

                    // Create a new block reference referring to the block
                    br = new _AcDb.BlockReference(new _AcGe.Point3d(), bt[pr.StringResult]);
                }

                _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, _AcDb.OpenMode.ForRead);

                // Call our function to display the block properties
                DisplayDynBlockProperties(ed, br, btr.Name);

                // Committing is cheaper than aborting
                tr.Commit();
            }
        }
Esempio n. 10
0
        public static void Plan2ImportLayerFilters()
        {
            var filePath = GetDwgName();

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            if (!System.IO.File.Exists(filePath))
            {
                return;
            }

            _AcAp.Document        doc    = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcEd.Editor          ed     = doc.Editor;
            _AcDb.Database        destDb = doc.Database;
            _AcLm.LayerFilterTree lft    = destDb.LayerFilters;
            using (_AcDb.Database srcDb = new _AcDb.Database(false, false))
            {
                srcDb.ReadDwgFile(filePath, _AcDb.FileOpenMode.OpenForReadAndAllShare, false, String.Empty);
                ImportNestedFilters(srcDb.LayerFilters.Root, lft.Root, srcDb, destDb, false, ed);
            }
            destDb.LayerFilters = lft;
        }
Esempio n. 11
0
        public bool Plan2ExcelToBlock(_AcDb.ResultBuffer rb)
        {
            _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            try
            {
                if (rb == null)
                {
                    ShowCallInfoImport(ed);
                    return(false);
                }
                _AcDb.TypedValue[] values = rb.AsArray();
                if (values == null || values.Length < 2)
                {
                    ShowCallInfoImport(ed);
                    return(false);
                }
                // Get ExcelFileName from Args
                if (values[0].Value == null)
                {
                    ShowCallInfoImport(ed);
                    return(false);
                }
                string excelFileName = values[0].Value.ToString();
                if (string.IsNullOrEmpty(excelFileName))
                {
                    ShowCallInfoImport(ed);
                    return(false);
                }

                bool createChangeLines = true;
                switch (values[1].TypeCode)
                {
                case 5019:
                    createChangeLines = false;
                    break;

                case 5021:
                    createChangeLines = true;
                    break;

                default:
                    ShowCallInfoImport(ed);
                    return(false);
                }

                // Start Import
                StartImport(excelFileName, createChangeLines);

                return(true);
            }
            catch (System.Exception ex)
            {
                log.Error(ex.Message);
                string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2ExcelToBlock): {0}", ex.Message);
                ed.WriteMessage("\n" + msg);
                System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2ExcelToBlock");
                return(false);
            }
        }
Esempio n. 12
0
        public bool Plan2BlockToExcel(_AcDb.ResultBuffer rb)
        {
            _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
            try
            {
                if (rb == null)
                {
                    ShowCallInfo(ed);
                    return(false);
                }
                _AcDb.TypedValue[] values = rb.AsArray();
                if (values == null || values.Length < 2)
                {
                    ShowCallInfo(ed);
                    return(false);
                }
                // Get Blockname from Args
                if (values[0].Value == null)
                {
                    ShowCallInfo(ed);
                    return(false);
                }
                string blockName = values[0].Value.ToString();
                if (string.IsNullOrEmpty(blockName))
                {
                    ShowCallInfo(ed);
                    return(false);
                }

                // Get ExcelFileName from Args
                if (values[1].Value == null)
                {
                    ShowCallInfo(ed);
                    return(false);
                }
                string excelFileName = values[1].Value.ToString();
                if (string.IsNullOrEmpty(excelFileName))
                {
                    ShowCallInfo(ed);
                    return(false);
                }

                // Start Export
                StartExport(blockName, excelFileName);

                return(true);
            }
            catch (System.Exception ex)
            {
                log.Error(ex.Message);
                string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2BlockToExcel): {0}", ex.Message);
                ed.WriteMessage("\n" + msg);
                System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2BlockToExcel");
                return(false);
            }
        }
Esempio n. 13
0
        public _CONNECTION()
        {
            _doc   = _Ap.Application.DocumentManager.MdiActiveDocument;
            _db    = _doc.Database;
            _ed    = _doc.Editor;
            _trans = _db.TransactionManager.StartTransaction();

            _blockTable = _trans.GetObject(_db.BlockTableId, _Db.OpenMode.ForWrite) as _Db.BlockTable;
            _modelSpace = _trans.GetObject(_Db.SymbolUtilityServices.GetBlockModelSpaceId(_db), _Db.OpenMode.ForWrite) as _Db.BlockTableRecord;
        }
Esempio n. 14
0
        public void Initialize()
        {
            _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;

            string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            ed.WriteMessage("\nBeams application version:{0} loaded successfully!", assemblyVersion);
            ed.WriteMessage("\nEnter \"BEAM1\" to draw a beam.");
            ed.WriteMessage("\nEnter \"ENT-COLOUR\" to change and entity's colour.");
        }
Esempio n. 15
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));
            }
        }
Esempio n. 16
0
 public LandBlockJig(AcDb.BlockReference br)
     : base(br)
 {
     _br  = br;
     _pos = _br.Position;
     AcEd.Editor             ed     = CurrentCAD.Editor;
     AcGe.CoordinateSystem3d ucs    = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
     AcGe.Matrix3d           ocsMat = AcGe.Matrix3d.WorldToPlane(new AcGe.Plane(AcGe.Point3d.Origin, ucs.Zaxis));
     _ucsRot = AcGe.Vector3d.XAxis.GetAngleTo(ucs.Xaxis.TransformBy(ocsMat), ucs.Zaxis);
     _rot    = _br.Rotation - _ucsRot;
 }
Esempio n. 17
0
 public BlockPlacementJig(AcDb.BlockReference br, Dictionary <string, string> tags)
     : base(br)
 {
     blockReference = br;
     position       = blockReference.Position;
     AcEd.Editor             ed     = CurrentCAD.Editor;
     AcGe.CoordinateSystem3d ucs    = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
     AcGe.Matrix3d           ocsMat = AcGe.Matrix3d.WorldToPlane(new AcGe.Plane(AcGe.Point3d.Origin, ucs.Zaxis));
     ucsRotation = AcGe.Vector3d.XAxis.GetAngleTo(ucs.Xaxis.TransformBy(ocsMat), ucs.Zaxis);
     rotation    = blockReference.Rotation - ucsRotation;
     this.tags   = tags;
     layerId     = blockReference.LayerId;
 }
Esempio n. 18
0
        private List <_AcDb.ObjectId> GetFgAnz(_AcGe.Point3d minExt, _AcGe.Point3d maxExt, _AcDb.ObjectId elFG)
        {
            List <_AcDb.ObjectId> Ret = new List <_AcDb.ObjectId>();

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

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

            return(Ret);
        }
Esempio n. 19
0
        // Zoom by sending a command


        private static void ZoomWin3(

            _AcEd.Editor ed, _AcGe.Point3d min, _AcGe.Point3d max

            )
        {
            string lower =

                min.ToString().Substring(

                    1,

                    min.ToString().Length - 2

                    );

            string upper =

                max.ToString().Substring(

                    1,

                    max.ToString().Length - 2

                    );


            string cmd =

                "_.ZOOM _W " + lower + " " + upper + " ";


            // Call the command synchronously using COM


            _AcInt.AcadApplication app =

                (_AcInt.AcadApplication)_AcAp.Application.AcadApplication;


            app.ActiveDocument.SendCommand(cmd);


            // Could also use async command calling:

            //ed.Document.SendStringToExecute(

            //  cmd, true, false, true

            //);
        }
Esempio n. 20
0
        //Methoden
        public void Start()
        {
            _block      = _config.GetAppSettingString("Block");
            _basislayer = _config.GetAppSettingString("Basislayer");

            OpenFileDialog ddOpenFile = new OpenFileDialog()
            {
                Title  = "Vermessungspunkte importieren",
                Filter = "Punktdatei|*.csv"
            };

            _AcEd.Editor m_ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;

            DialogResult diagRes          = DialogResult.None;
            bool         importExportfile = Convert.ToBoolean(_config.GetAppSettingBool("importExportfile"));

            if (!importExportfile)
            {
                diagRes = ddOpenFile.ShowDialog();
            }
            else
            {
                ddOpenFile.FileName = _config.GetAppSettingString("Outputfile");
                diagRes             = DialogResult.OK;
            }

            if (diagRes == DialogResult.OK)
            {
                _Filename = ddOpenFile.FileName;
                bool fileOK = true;

                //Punktdatei einlesen
                try
                {
                    StreamReader sr = new StreamReader(_Filename, Encoding.Default);
                    _Text = sr.ReadToEnd();
                    sr.Close();
                }
                catch { fileOK = false; }

                if (fileOK)
                {
                    //Punkte in Autocad einfügen
                    using (var progress = new ProcessingProgressBar(this))
                    {
                        progress.Start();
                    }
                }
            }
        }
Esempio n. 21
0
        private static bool GetNewText(_AcEd.Editor ed)
        {
            var prompt = new _AcEd.PromptStringOptions("\nNeuer Text: ");

            prompt.AllowSpaces = true;
            var prefixUserRes = ed.GetString(prompt);

            if (prefixUserRes.Status != _AcEd.PromptStatus.OK)
            {
                return(false);
            }
            _NewText = prefixUserRes.StringResult;
            return(true);
        }
Esempio n. 22
0
        public static bool Plan2RemoveHyperLinks(_AcDb.ResultBuffer rb)
        {
            var doc = _AcAp.Application.DocumentManager.MdiActiveDocument;

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

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

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

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

                using (_AcDb.Transaction trans = dbTrans.StartTransaction())
                {
                    _AcDb.Entity ent = trans.GetObject((_AcDb.ObjectId)typedValues[0].Value, _AcDb.OpenMode.ForWrite) as _AcDb.Entity;
                    if (ent != null)
                    {
                        //ent.Hyperlinks.Clear(); // -> crashes
                        while (ent.Hyperlinks.Count > 0)
                        {
                            ent.Hyperlinks.RemoveAt(0);
                        }
                    }
                    trans.Commit();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)");
            }
            return(false);
        }
Esempio n. 23
0
        public static void CreateBeam()
        {
            _AcGe.Point3d p0, p1, pside;

            //
            // Get some user input:
            //
            _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;

            _AcEd.PromptPointOptions ppo = new _AcEd.PromptPointOptions("\nSelect start point of beam: ");
            ppo.UseBasePoint = false;

            _AcEd.PromptPointResult ppres = ed.GetPoint(ppo);
            if (ppres.Status != _AcEd.PromptStatus.OK)
            {
                return;
            }
            p0 = ppres.Value;

            ppo.UseBasePoint = true;
            ppo.BasePoint    = p0;
            ppo.Message      = "\nSelect end point of beam: ";
            ppres            = ed.GetPoint(ppo);
            if (ppres.Status != _AcEd.PromptStatus.OK)
            {
                return;
            }
            p1 = ppres.Value;

            ppo.BasePoint = p1;
            ppo.Message   = "\nSelect side of beam drawing direction (Press ESC for on centre line): ";
            ppres         = ed.GetPoint(ppo);
            if (ppres.Status == _AcEd.PromptStatus.Cancel)
            {
                pside = new Teigha.Geometry.Point3d(); // send empty point, could do better here with keywords for the propmt.
            }
            else
            {
                pside = ppres.Value;
            }

            //
            // Create the beam:
            //
            BeamData   beamData   = new BeamData(200, 120, 6000, p0, p1, pside);
            BeamDrawer beamDrawer = new BeamDrawer(beamData);

            beamDrawer.DrawBeam();
        }
Esempio n. 24
0
        public static void Plan2ReplaceInLayoutNames()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _Db = doc.Database;
            _AcEd.Editor ed = doc.Editor;

            _OldText = string.Empty;
            _NewText = string.Empty;

            try
            {
                var layoutNames = Plan2Ext.Layouts.GetLayoutNames();
                layoutNames = layoutNames.Where(x => string.Compare(x, "Model", StringComparison.OrdinalIgnoreCase) != 0).ToList();

                if (!GetOldText(ed))
                {
                    return;
                }
                if (!GetNewText(ed))
                {
                    return;
                }

                _Tr = _Db.TransactionManager.StartTransaction();
                using (_Tr)
                {
                    _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current;

                    foreach (var name in layoutNames)
                    {
                        bool changed;
                        var  newT = ReplaceTexts(name, out changed);
                        if (changed)
                        {
                            layoutMgr.RenameLayout(name, newT);
                        }
                    }

                    _Tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2ReplaceInLayoutNames): {0}", ex.Message);
                ed.WriteMessage("\n" + msg);
                System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2ReplaceInLayoutNames");
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Öffnen einer Dwg ohne Editor
        /// </summary>
        //[_AcTrx.CommandMethod("Plan2TestSideDb")]
        static public void Plan2TestSideDb()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcEd.Editor   ed  = doc.Editor;
            // Ask the user to select a file
            _AcEd.PromptResult res = ed.GetString("\nEnter the path of a DWG or DXF file: ");
            if (res.Status == _AcEd.PromptStatus.OK)
            {
                // Create a database and try to load the file
                _AcDb.Database db = new _AcDb.Database(false, true);
                using (db)
                {
                    try
                    {
                        db.ReadDwgFile(res.StringResult, System.IO.FileShare.Read, false, "");
                    }
                    catch (System.Exception)
                    {
                        ed.WriteMessage("\nUnable to read drawing file.");
                        return;
                    }

                    _AcDb.Transaction tr = db.TransactionManager.StartTransaction();
                    using (tr)
                    {
                        // Open the blocktable, get the modelspace
                        _AcDb.BlockTable       bt  = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead);
                        _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead);

                        // Iterate through it, dumping objects
                        foreach (_AcDb.ObjectId objId in btr)
                        {
                            _AcDb.Entity ent = (_AcDb.Entity)tr.GetObject(objId, _AcDb.OpenMode.ForRead);

                            // Let's get rid of the standard namespace
                            const string prefix     = "Autodesk.AutoCAD.DatabaseServices.";
                            string       typeString = ent.GetType().ToString();
                            if (typeString.Contains(prefix))
                            {
                                typeString = typeString.Substring(prefix.Length);
                            }
                            ed.WriteMessage("\nEntity " + ent.ObjectId.ToString() + " of type " + typeString + " found on layer " +
                                            ent.Layer + " with colour " + ent.Color.ToString());
                        }
                    }
                }
            }
        }
Esempio n. 26
0
        private static string GetDwgName()
        {
            _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
            _AcEd.Editor   ed  = doc.Editor;

            _AcWnd.OpenFileDialog ofd = new _AcWnd.OpenFileDialog(
                "AutoCAD-Datei mit den zu importierenden Layerfilter wählen", "", "dwg", "AutoCAD-Datei mit den zu importierenden Layerfilter wählen", _AcWnd.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension
                );
            System.Windows.Forms.DialogResult dr = ofd.ShowDialog();
            if (dr != System.Windows.Forms.DialogResult.OK)
            {
                return(null);
            }

            return(ofd.Filename);
        }
Esempio n. 27
0
        private static bool GetOldText(_AcEd.Editor ed)
        {
            var prompt = new _AcEd.PromptStringOptions("\nZu ersetzender Text: ");

            prompt.AllowSpaces = true;
            while (string.IsNullOrEmpty(_OldText))
            {
                var prefixUserRes = ed.GetString(prompt);
                if (prefixUserRes.Status != _AcEd.PromptStatus.OK)
                {
                    return(false);
                }
                _OldText = prefixUserRes.StringResult;
            }
            return(true);
        }
Esempio n. 28
0
        static public void Plan2LayTrans()
        {
            try
            {
#if BRX_APP
                return;
#else
                _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument;
                using (_AcAp.DocumentLock m_doclock = doc.LockDocument())
                {
                    _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
                    // First let's use the editor method, GetFileNameForOpen()
                    _AcEd.PromptOpenFileOptions opts = new _AcEd.PromptOpenFileOptions("Excel-Datei für Layer-Infos");
                    opts.Filter = "Excel (*.xlsx)|*.xlsx|Excel alt (*.xls)|*.xls";
                    _AcEd.PromptFileNameResult pr = ed.GetFileNameForOpen(opts);
                    if (pr.Status != _AcEd.PromptStatus.OK)
                    {
                        return;
                    }

                    //_AcWnd.OpenFileDialog ofd = new _AcWnd.OpenFileDialog("Excel-Datei", "", "xlsx", "LayTrans", _AcWnd.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension);
                    //System.Windows.Forms.DialogResult dr = ofd.ShowDialog();
                    //if (dr != System.Windows.Forms.DialogResult.OK)  return;

                    string fileName = pr.StringResult;

                    Engine engine = new Engine();
                    var    ok     = engine.LayTrans(fileName);
                    if (!ok)
                    {
                        _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in LayTrans!"));
                    }
                    else
                    {
                        string msg = string.Format(CultureInfo.CurrentCulture, "LayTrans wurde erfolgreich beendet.");
                        _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(msg);
                        log.Info(msg);
                    }
                }
#endif
            }
            catch (System.Exception ex)
            {
                log.Error(ex.Message, ex);
                _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2LayTrans aufgetreten! {0}", ex.Message));
            }
        }
Esempio n. 29
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 30
0
        private static void DisplayDynBlockProperties(_AcEd.Editor ed, _AcDb.BlockReference br, string name)
        {
            // Only continue is we have a valid dynamic block
            if (br != null && br.IsDynamicBlock)
            {
                ed.WriteMessage("\nDynamic properties for \"{0}\"\n", name);

                // Get the dynamic block's property collection
                _AcDb.DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection;

                // Loop through, getting the info for each property
                foreach (_AcDb.DynamicBlockReferenceProperty prop in pc)
                {
                    // Start with the property name, type and description
                    ed.WriteMessage("\nProperty: \"{0}\" : {1}", prop.PropertyName, prop.UnitsType);
                    if (prop.Description != "")
                    {
                        ed.WriteMessage("\n  Description: {0}", prop.Description);
                    }

                    // Is it read-only?
                    if (prop.ReadOnly)
                    {
                        ed.WriteMessage(" (Read Only)");
                    }

                    // Get the allowed values, if it's constrained
                    bool first = true;
                    foreach (object value in prop.GetAllowedValues())
                    {
                        ed.WriteMessage((first ? "\n  Allowed values: [" : ", "));
                        ed.WriteMessage("\"{0}\"", value);
                        first = false;
                    }

                    if (!first)
                    {
                        ed.WriteMessage("]");
                    }

                    // And finally the current value
                    ed.WriteMessage("\n  Current value: \"{0}\"\n", prop.Value);
                }
            }
        }