Ejemplo n.º 1
0
        private bool insertFormSide(_Ge.Point3d ptPos, double dir, double rotation)
        {
            _Ed.PromptStringOptions pStrOpts = new _Ed.PromptStringOptions("\nFormSide: ");
            pStrOpts.AllowSpaces = false;
            _Ed.PromptResult pStrRes = _c.ed.GetString(pStrOpts);
            string           result  = pStrRes.StringResult;

            if (pStrRes.Status == _Ed.PromptStatus.Cancel)
            {
                return(false);
            }

            _Ge.Point3d         insert = ptPos;
            _Db.AttachmentPoint a      = _Db.AttachmentPoint.BottomCenter;

            if (rotation == 0.0)
            {
                a = _Db.AttachmentPoint.BottomCenter;
                double newX = ptPos.X - (bigCircleOffset - bigCircleRadius) * dir / 2;
                double newY = ptPos.Y + textOffset;
                insert = new _Ge.Point3d(newX, newY, ptPos.Z);
            }
            else
            {
                a = _Db.AttachmentPoint.MiddleRight;
                double newX = ptPos.X - textOffset;
                double newY = ptPos.Y - (bigCircleOffset - bigCircleRadius) * dir / 2;
                insert = new _Ge.Point3d(newX, newY, ptPos.Z);
            }

            insertText(insert, a, result, 0);
            return(true);
        }
Ejemplo n.º 2
0
        public static void ManualInsertMText(AcDb.MText oMText)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);

                oMText.Normal = ed.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis;

                btr.AppendEntity(oMText);
                tr.AddNewlyCreatedDBObject(oMText, true);

                MTextPlacementJig pj = new MTextPlacementJig(oMText);

                AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword;
                while (stat == AcEd.PromptStatus.Keyword)
                {
                    AcEd.PromptResult res = ed.Drag(pj);
                    stat = res.Status;
                    if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword)
                    {
                        return;
                    }
                }
                tr.Commit();
                //return (MText)pj.Entity;
            }
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
        public void run()
        {
            _Ed.PromptStringOptions pStrOpts = new _Ed.PromptStringOptions("\nFIND: ");
            pStrOpts.AllowSpaces = true;
            _Ed.PromptResult pr = _c.ed.GetString(pStrOpts);
            if (pr.Status != _Ed.PromptStatus.OK)
            {
                return;
            }
            string find = pr.StringResult;

            pStrOpts             = new _Ed.PromptStringOptions("\nREPLACE: ");
            pStrOpts.AllowSpaces = true;
            pr = _c.ed.GetString(pStrOpts);
            if (pr.Status != _Ed.PromptStatus.OK)
            {
                return;
            }
            string replace = pr.StringResult;

            renameText(find, replace);
            renameBlockInside(find, replace);
            renameBlockFields(find, replace);
            renameLayout(find, replace);
        }
Ejemplo n.º 5
0
        public static void ManualInsertbAttribute(string nameBlock)
        {
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (!blockTable.Has(nameBlock))
                {
                    ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock);
                    return;
                }
                AcDb.BlockTableRecord curSpace       = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
                AcDb.BlockReference   blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock]);
                blockReference.TransformBy(ed.CurrentUserCoordinateSystem);
                curSpace.AppendEntity(blockReference);
                tr.AddNewlyCreatedDBObject(blockReference, true);

                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead);
                AcDb.DBText           text;
                foreach (AcDb.ObjectId id in btr)
                {
                    if (id.ObjectClass.Name == "AcDbAttributeDefinition")
                    {
                        AcDb.AttributeDefinition attDef =
                            (AcDb.AttributeDefinition)tr.GetObject(id, AcDb.OpenMode.ForRead);

                        text = new AcDb.DBText
                        {
                            TextString = "jig_test"
                        };

                        TextPlacementJig jig = new TextPlacementJig(text);

                        //PromptResult pr = ed.Drag(jig);

                        AcEd.PromptStatus stat = AcEd.PromptStatus.Keyword;
                        while (stat == AcEd.PromptStatus.Keyword)
                        {
                            AcEd.PromptResult pr = ed.Drag(jig);
                            stat = pr.Status;
                            if (stat != AcEd.PromptStatus.OK && stat != AcEd.PromptStatus.Keyword)
                            {
                                return;
                            }
                        }

                        AcDb.AttributeReference attRef = new AcDb.AttributeReference();
                        attRef.SetAttributeFromBlock(attDef, blockReference.BlockTransform);
                        AcDb.ObjectId attId = blockReference.AttributeCollection.AppendAttribute(attRef);
                        tr.AddNewlyCreatedDBObject(attRef, true);


                        tr.Commit();
                        //if (pr.Status != PromptStatus.OK) blockReference.Erase();
                    }
                }

                //tr.Commit();
            }
        }
Ejemplo n.º 6
0
        private string promptFilter()
        {
            _Ed.PromptKeywordOptions promptOptions = new _Ed.PromptKeywordOptions("");
            promptOptions.Message = "\nWhat to print: ";
            promptOptions.Keywords.Add("A");
            promptOptions.Keywords.Add("B");
            promptOptions.Keywords.Add("C");
            promptOptions.Keywords.Add("D");
            promptOptions.Keywords.Add("E");
            promptOptions.Keywords.Add("EX");

            promptOptions.Keywords.Add("F");
            promptOptions.Keywords.Add("G");
            promptOptions.Keywords.Add("H");
            promptOptions.Keywords.Add("J");
            promptOptions.Keywords.Add("K");
            promptOptions.Keywords.Add("L");

            promptOptions.Keywords.Add("LX");
            promptOptions.Keywords.Add("M");
            promptOptions.Keywords.Add("N");
            promptOptions.Keywords.Add("NX");
            promptOptions.Keywords.Add("O");
            promptOptions.Keywords.Add("Q");

            promptOptions.Keywords.Add("R");
            promptOptions.Keywords.Add("S");
            promptOptions.Keywords.Add("SH");
            promptOptions.Keywords.Add("SX");
            promptOptions.Keywords.Add("T");
            promptOptions.Keywords.Add("U");

            promptOptions.Keywords.Add("V");
            promptOptions.Keywords.Add("W");
            promptOptions.Keywords.Add("X");
            promptOptions.Keywords.Add("XX");
            promptOptions.Keywords.Add("Z");

            promptOptions.Keywords.Add("ALL");
            promptOptions.Keywords.Add("SPEC");
            promptOptions.Keywords.Add("LAST");
            promptOptions.AllowNone = true;

            _Ed.PromptResult promptResult = _c.ed.GetKeywords(promptOptions);

            if (promptResult.Status == _Ed.PromptStatus.OK)
            {
                if (promptResult.StringResult == "")
                {
                    return("LAST");
                }
                else
                {
                    return(promptResult.StringResult);
                }
            }

            return("LAST");
        }
Ejemplo n.º 7
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());
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private string promptGetMaterial()
        {
            string materjal = "K500C-T";

            _Ed.PromptStringOptions promptOptions2 = new _Ed.PromptStringOptions("");
            promptOptions2.Message      = "\nArmatuuri teras: ";
            promptOptions2.DefaultValue = "K500C-T";
            _Ed.PromptResult promptResult2 = _c.ed.GetString(promptOptions2);

            if (promptResult2.Status == _Ed.PromptStatus.OK)
            {
                materjal = promptResult2.StringResult;
            }

            return(materjal);
        }
Ejemplo n.º 9
0
 static public void test()
 {
     _AcEd.PromptResult rs =
         _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.GetString("\nEnter lisp expression: ");
     if (rs.Status == _AcEd.PromptStatus.OK && rs.StringResult != "")
     {
         _AcDb.ResultBuffer rb = AcadEvalLisp(rs.StringResult);
         if (rb != null)
         {
             PrintResbuf(rb);
         }
         else
         {
             _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nError in evaluation");
         }
     }
 }
Ejemplo n.º 10
0
        private bool promptAddRebarToXml(_Mark u)
        {
            _Ed.PromptKeywordOptions promptOptions = new _Ed.PromptKeywordOptions("");
            promptOptions.Message = "\nAdd to XML: " + u.ToString();
            promptOptions.Keywords.Add("Yes");
            promptOptions.Keywords.Add("No");
            promptOptions.AllowNone = false;
            _Ed.PromptResult promptResult = _c.ed.GetKeywords(promptOptions);

            if (promptResult.Status == _Ed.PromptStatus.OK)
            {
                if (promptResult.StringResult == "Yes")
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 11
0
        private bool insertNumber(_Ge.Point3d center, double rotation)
        {
            _Ed.PromptStringOptions pStrOpts = new _Ed.PromptStringOptions("\nNumber: ");
            pStrOpts.AllowSpaces = false;
            _Ed.PromptResult pStrRes = _c.ed.GetString(pStrOpts);
            string           result  = pStrRes.StringResult;

            if (pStrRes.Status == _Ed.PromptStatus.Cancel)
            {
                return(false);
            }

            _Db.AttachmentPoint a = _Db.AttachmentPoint.MiddleCenter;
            if (result.Length > 2)
            {
                _Ge.Point3d insert = center;

                a = _Db.AttachmentPoint.BottomRight;
                if (rotation == 0.0)
                {
                    double newX = center.X;
                    double newY = center.Y + textOffset;

                    insert = new _Ge.Point3d(newX, newY, center.Z);
                }
                else
                {
                    double newX = center.X - textOffset;
                    double newY = center.Y;

                    insert = new _Ge.Point3d(newX, newY, center.Z);
                }

                insertText(insert, a, result, rotation);
                return(false);
            }
            else
            {
                a = _Db.AttachmentPoint.MiddleCenter;
                insertText(center, a, result, 0.0);
                return(true);
            }
        }
Ejemplo n.º 12
0
        public static AcDb.ObjectId ManualInsertBlock(string nameBlock,
                                                      double scaleBlock,
                                                      Dictionary <string, string> tags)
        {
            AcDb.ObjectId idBlock = AcDb.ObjectId.Null;
            using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
            {
                AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead);
                if (!blockTable.Has(nameBlock))
                {
                    ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock);
                    return(idBlock);
                }
                AcDb.BlockTableRecord curSpace       = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);
                AcDb.BlockReference   blockReference = new AcDb.BlockReference(AcGe.Point3d.Origin, blockTable[nameBlock])
                {
                    ScaleFactors = new AcGe.Scale3d(scaleBlock, scaleBlock, scaleBlock)
                };
                blockReference.TransformBy(ed.CurrentUserCoordinateSystem);
                curSpace.AppendEntity(blockReference);

                tr.AddNewlyCreatedDBObject(blockReference, true);

                AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(blockTable[nameBlock], AcDb.OpenMode.ForRead);
                BlockPlacementJig     jig = new BlockPlacementJig(blockReference, tags);
                AcEd.PromptResult     pr  = ed.Drag(jig);

                if (pr.Status != AcEd.PromptStatus.OK)
                {
                    blockReference.Erase();
                }

                tr.Commit();
            }

            return(idBlock);
        }
Ejemplo n.º 13
0
        public static LandRasterImage SelectingRasterOnClick(string key, string searchPath)
        {
            AcEd.Editor ed = AcApp.DocumentManager.MdiActiveDocument.Editor;

            LandRasterImage landRastr = null;

            AcEd.PromptPointOptions ppo = new AcEd.PromptPointOptions("\n" + key + " > Вкажіть точку вставки растру: ");
            ppo.UseBasePoint = false;
            var ppr = ed.GetPoint(ppo);

            if (ppr.Status == AcEd.PromptStatus.OK)
            {
                landRastr = new LandRasterImage();
                AcGe.Point3d tmpPt    = ppr.Value.TransformBy(landRastr.UCS.Inverse());
                int          valueKmX = (int)(tmpPt.X / 1000);
                int          valueKmY = (int)(tmpPt.Y / 1000);
                string       imgName  = (valueKmY + 1).ToString("00") + valueKmX.ToString("00");
                landRastr.ImageName = key + "-" + imgName;
                string[] filesName = Directory.GetFiles(searchPath, imgName + ".*");

                if (filesName.Length < 1)
                {
                    ed.WriteMessage("\n" + key + "В указаной точці знайдено растр '{0}.*'.", landRastr.ImageName);
                    return(null);
                }
                else if (filesName.Length == 1)
                {
                    landRastr.FileName = filesName[0];
                }
                else if (filesName.Length > 1)
                {
                    AcEd.PromptKeywordOptions pko = new AcEd.PromptKeywordOptions("\nВиберіть растр ");

                    for (int i = 0; i < filesName.Length; i++)
                    {
                        string nameRastr = Path.GetFileName(filesName[i]);
                        if (nameRastr.IndexOf(".bmp") > -1 ||
                            nameRastr.IndexOf(".tif") > -1 ||
                            nameRastr.IndexOf(".jpg") > -1)
                        {
                            pko.Keywords.Add("<" + nameRastr
                                             .Replace(".", "> ")
                                             .Replace('b', 'B')
                                             .Replace('j', 'J')
                                             .Replace('t', 'T'));
                        }
                    }

                    pko.Keywords.Default = Path.GetFileName("<" + filesName[0])
                                           .Replace(".", "> ")
                                           .Replace('b', 'B')
                                           .Replace('j', 'J').Replace('t', 'T');
                    pko.AllowNone = false;


                    AcEd.PromptResult pr = ed.GetKeywords(pko);

                    landRastr.FileName = searchPath + pr.StringResult.Replace(' ', '.');
                }


                landRastr.InsertPoint = new AcGe.Point3d(Convert.ToDouble(valueKmX) * 1000, Convert.ToDouble(valueKmY) * 1000, 0);
            }

            return(landRastr);
        }
Ejemplo n.º 14
0
        public static void BuildingRectangle()
        {
            try
            {
                AcDb.Database db = CurrentCAD.Database;
                AcEd.Editor   ed = CurrentCAD.Editor;

                AcEd.PromptKeywordOptions pko;
                AcEd.PromptPointOptions   ppt;
                AcEd.PromptPointResult    ppr;
                AcGe.Point3d basePoint;
                AcGe.Point3d diractionPoint;

                pko = new AcEd.PromptKeywordOptions("\nПобудова прямокутника");

                pko.Keywords.Add("по Діагоналі");
                pko.Keywords.Add("по Напрямку та діагоналі");
                pko.Keywords.Add("по Ширині та висота");
                pko.Keywords.Default = "по Ширині та висота";
                pko.AllowNone        = false;

                AcEd.PromptResult pkr = ed.GetKeywords(pko);

                if (pkr.Status != AcEd.PromptStatus.OK)
                {
                    return;
                }

                MethodConstructingRectangle methodConstructing;

                if (pkr.StringResult == "Діагоналі")
                {
                    methodConstructing = MethodConstructingRectangle.Diagonal;
                }
                else if (pkr.StringResult == "Напрямку")
                {
                    methodConstructing = MethodConstructingRectangle.DirectionAndDiagonal;
                }
                else
                {
                    methodConstructing = MethodConstructingRectangle.HeightAndWidth;
                }

                ppt = new AcEd.PromptPointOptions("\nВкажіть першу точку прямокутника:");
                ppr = ed.GetPoint(ppt);
                if (ppr.Status != AcEd.PromptStatus.OK)
                {
                    return;
                }

                basePoint = ppr.Value;

                if (methodConstructing == MethodConstructingRectangle.Diagonal)
                {
                    diractionPoint = basePoint.Add(AcGe.Vector3d.XAxis);
                }
                else
                {
                    ppt = new AcEd.PromptPointOptions("\n");
                    if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal)
                    {
                        ppt.Message = "\nВкажіть точку напрямку прямокутника:";
                    }
                    else if (methodConstructing == MethodConstructingRectangle.DirectionAndDiagonal)
                    {
                        ppt.Message = "\nВкажіть ширину прямокутника:";
                    }
                    ppt.UseBasePoint = true;
                    ppt.BasePoint    = basePoint;
                    ppr = ed.GetPoint(ppt);
                    if (ppr.Status != AcEd.PromptStatus.OK)
                    {
                        return;
                    }

                    diractionPoint = ppr.Value;
                }
                jigger = new RectangleJig(methodConstructing, basePoint, diractionPoint);
                ed.Drag(jigger);

                using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
                {
                    AcDb.BlockTableRecord btr = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite);

                    Teigha.DatabaseServices.Polyline ent = new Teigha.DatabaseServices.Polyline();
                    ent.SetDatabaseDefaults();
                    for (int i = 0; i < jigger.Corners.Count; i++)
                    {
                        AcGe.Point3d pt3d = jigger.Corners[i];
                        AcGe.Point2d pt2d = new AcGe.Point2d(pt3d.X, pt3d.Y);
                        ent.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid);
                    }
                    ent.Closed = true;
                    ent.TransformBy(jigger.UCS);
                    btr.AppendEntity(ent);
                    tr.AddNewlyCreatedDBObject(ent, true);

                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                CurrentCAD.Editor.WriteMessage(ex.ToString());
            }
        }