コード例 #1
0
ファイル: TextTools.cs プロジェクト: coordinate/MyLearnning
        /// <summary>
        /// 设置单行文本的属性为当前文字样式的属性
        /// </summary>
        /// <param name="txt">单行文本对象</param>
        public static void SetFromTextStyle(this DBText txt)
        {
            //打开文字样式表记录
            TextStyleTableRecord str = (TextStyleTableRecord)txt.TextStyleId.GetObject(OpenMode.ForRead);

            //必须保证文字为写的状态
            if (!txt.IsWriteEnabled)
            {
                txt.UpgradeOpen();
            }
            txt.Oblique    = str.ObliquingAngle; //设置倾斜角(弧度)
            txt.Annotative = str.Annotative;     //设置文字的注释性
            //文字方向与布局是否匹配
            txt.SetPaperOrientation(Convert.ToBoolean(str.PaperOrientation));
            txt.WidthFactor = str.XScale;   //设置宽度比例
            txt.Height      = str.TextSize; //设置高度
            if (str.FlagBits == 2)
            {
                txt.IsMirroredInX = true;//颠倒
            }
            else if (str.FlagBits == 4)
            {
                txt.IsMirroredInY = true; //反向
            }
            else if (str.FlagBits == 6)   //颠倒并反向
            {
                txt.IsMirroredInX = txt.IsMirroredInY = true;
            }
            txt.DowngradeOpen();//为了安全切换为读的状态
        }
コード例 #2
0
ファイル: ProtectionPlacer.cs プロジェクト: ming91915/CADDev
 private void ChangeText(DBText txt, string newText)
 {
     if (!string.IsNullOrEmpty(newText))
     {
         txt.UpgradeOpen();
         txt.TextString = newText;
         txt.Draw();
         txt.DowngradeOpen();
     }
 }
コード例 #3
0
        /// <summary> 删除子边坡所绑定的防护文字 </summary>
        /// <param name="seg"></param>
        /// <param name="db"></param>
        public static void EraseText(ISlopeSeg seg, Database db)
        {
            DBText originalText = null;

            try
            {
                originalText = seg.ProtectionMethodText.GetDBObject <DBText>(db);
            }
            catch (Exception)
            {
            }
            if (originalText != null)
            {
                originalText.UpgradeOpen();
                originalText.Erase(true);
                originalText.DowngradeOpen();
                seg.ProtectionMethodText = default(Handle);
            }
        }
コード例 #4
0
        public void SelectTextAtBounds()
        {
            DBText sourceObj;

            if (!ObjectCollector.TrySelectAllowedClassObject <DBText>(out sourceObj))
            {
                return;
            }
            TypedValue[] tvs = new[] {
                new TypedValue((int)DxfCode.Start, "TEXT")
            };
            Tools.StartTransaction(() =>
            {
                Rectangle3d?bounds = sourceObj.GetTextBoxCorners();
                if (!bounds.HasValue)
                {
                    return;
                }

                Polyline pline = new Polyline(5);
                pline.AddVertexAt(0, bounds.Value.LowerLeft.Add((bounds.Value.LowerLeft - bounds.Value.UpperRight).MultiplyBy(0.1)));
                pline.AddVertexAt(1, bounds.Value.UpperLeft.Add((bounds.Value.UpperLeft - bounds.Value.LowerRight).MultiplyBy(0.1)));
                pline.AddVertexAt(2, bounds.Value.UpperRight.Add((bounds.Value.UpperRight - bounds.Value.LowerLeft).MultiplyBy(0.1)));
                pline.AddVertexAt(3, bounds.Value.LowerRight.Add((bounds.Value.LowerRight - bounds.Value.UpperLeft).MultiplyBy(0.1)));
                pline.AddVertexAt(4, bounds.Value.LowerLeft.Add((bounds.Value.LowerLeft - bounds.Value.UpperRight).MultiplyBy(0.1)));

                var spres = Tools.GetAcadEditor().SelectWindowPolygon(pline.GetPoints(), new SelectionFilter(tvs));

                pline.SaveToDatebase();

                if (spres.Status == PromptStatus.OK)
                {
                    DBText text = spres.Value.GetSelectedItems <DBText>().FirstOrDefault();
                    if (text != null)
                    {
                        text.UpgradeOpen();
                        text.ColorIndex = 181;
                        text.DowngradeOpen();
                    }
                }
            });
        }
コード例 #5
0
        } // END ObjectIdCollection()

        // Cycle though filtered DWG Objects [util_Entity.GetDXFEntities()] and
        // assign correct Block [util_ExcelReader.ReadInDXFDataTable] to
        // the position of DBTEXT object
        public static void ProcessDXFEntities()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                // Create a filtered Collection with ObjectId's
                ObjectIdCollection ents = GetDXFEntities();

                // Cycle through our collection (even if there are no Entities (AutoCAD Objects)) to...
                foreach (ObjectId objID in ents)
                {
                    // Use DTEXT objectId's to assign the appropriate Block with data
                    if (objID.ObjectClass.DxfName == "TEXT")
                    {
                        DBText dbTxt = tr.GetObject(objID, OpenMode.ForRead) as DBText;

                        if (dbTxt.TextString == "DW")
                        {
                            dbTxt.UpgradeOpen();
                            dbTxt.TextString = "(MATERIAL) DRIVWAY";
                            dbTxt.Height     = 1.5;
                            dbTxt.Layer      = "SHOTPOINTS-CHECK";
                            dbTxt.DowngradeOpen();
                        }

                        // Cycle over the Edge of Pavement/Road/Sidewalks annotations...
                        if (dbTxt.TextString.StartsWith("SW") ||
                            dbTxt.TextString.StartsWith("EO") ||
                            dbTxt.TextString.StartsWith("FO") ||
                            dbTxt.TextString.StartsWith("PK"))
                        {
                            // ... and move them to the SHOTPOINTS Layer
                            dbTxt.UpgradeOpen();

                            // If MyCommands.moveToUsedShotpointsLayer == false, don't move to
                            if (MyCommands.moveToShotpointsLayer)
                            {
                                dbTxt.Layer = "SHOTPOINTS";
                                dbTxt.DowngradeOpen();
                            }
                            else
                            {
                                dbTxt.Layer = "SHOTPOINTS-USED";
                                dbTxt.DowngradeOpen();
                            }
                        }
                        else
                        {
                            // We need to check the Field Crew Annotations before running it
                            // against the nTRIX.xlsx list of annotations
                            string crewAnno = dbTxt.TextString;

                            // To deal with Crew Annotations that inculde "_"
                            if (dbTxt.TextString.Contains("_"))
                            {
                                // Split DBTEXT.TextString into 1 to 3 pieces
                                string[] attribVals = dbTxt.TextString.Split('_');

                                // If DBTEXT.TextString has an "_"...
                                if (!string.IsNullOrEmpty(attribVals[1]))
                                {
                                    switch (attribVals[0])
                                    {
                                    case "PARKING":
                                    case "PARKINGMETER":
                                    case "P-E":
                                    case "P-JO":
                                    case "PM":
                                    case "PM1":
                                    case "PM2":
                                    case "POLE-ELEC.":
                                    case "POLE-JO":
                                    case "POLE-SE":
                                    case "POLE-ST":
                                    case "P-T":
                                    case "TREE":
                                        // ...only use the first part that 'should' match the
                                        // Excel DXF value "Annotation to use" column
                                        crewAnno = attribVals[0];
                                        break;
                                    }
                                }
                            }

                            // Look-up the DBTEXT annotation using our parsed crewAnno value
                            var results = (from rw in MyCommands.lkAbbrevTbl.AsEnumerable()
                                           where rw.Field <string>("ANNO") == crewAnno
                                           select rw).FirstOrDefault();

                            // If we found a matching Annotation...
                            if (results != null)
                            {
                                // Get the location of the DTEXT Annotation (Point3D)
                                // to use as the insertion point of the new Block
                                Point3d loc = dbTxt.Position;

                                Double rotation;
                                if (MyCommands.useCurrentUCS_Rotation == false)
                                {
                                    // Use the DBText's Rotation to set the rotation of the new BlockRef
                                    rotation = dbTxt.Rotation;
                                }
                                else
                                {
                                    CoordinateSystem3d UCS = ed.CurrentUserCoordinateSystem.CoordinateSystem3d;
                                    Plane OcsPlane         = new Plane(Point3d.Origin, UCS.Zaxis);
                                    CoordinateSystem3d OCS = Matrix3d.PlaneToWorld(OcsPlane).CoordinateSystem3d;
                                    rotation = OCS.Xaxis.GetAngleTo(UCS.Xaxis, UCS.Zaxis);
                                }

                                // ...we insert the appropriate Block ONLY
                                // if we already ran util_ExcelReader.ValidateLayers &
                                // util_ExcelReader.ValidateBlocks
                                InsertBlock(loc, dbTxt.TextString,
                                            results.Field <string>("BLOCK"),
                                            results.Field <string>("DYN_VAL"),
                                            results.Field <string>("LAYER"),
                                            results.Field <string>("PROP_NAME"),
                                            rotation);

                                // ... and move them to the SHOTPOINTS Layer
                                dbTxt.UpgradeOpen();

                                // If MyCommands.moveToUsedShotpointsLayer == false, don't move to
                                if (MyCommands.moveToShotpointsLayer)
                                {
                                    dbTxt.Layer = "SHOTPOINTS";
                                    dbTxt.DowngradeOpen();
                                }
                                else
                                {
                                    dbTxt.Layer = "SHOTPOINTS-USED";
                                    dbTxt.DowngradeOpen();
                                }
                            }
                            else //...we could not find a match and...
                            {
                                // ...move the DBTEXT to the SHOTPOINTS-CHECK Layer
                                // for the Drafter to decide what to do
                                dbTxt.UpgradeOpen();
                                dbTxt.Layer = "SHOTPOINTS-CHECK";
                                dbTxt.DowngradeOpen();
                            }
                        }
                    }

                    // We leave the LINES in the DXF alone and move all the LAYER 0 POINTS
                    // onto the SHOTPOINTS Layer for the Drafter to use as they see fit
                    if (objID.ObjectClass.DxfName == "POINT")
                    {
                        DBPoint pnt = tr.GetObject(objID, OpenMode.ForWrite) as DBPoint;

                        // If MyCommands.moveToUsedShotpointsLayer == false, don't move to
                        if (MyCommands.moveToShotpointsLayer)
                        {
                            pnt.Layer = "SHOTPOINTS";
                        }
                        else
                        {
                            pnt.Layer = "SHOTPOINTS-USED";
                        }
                    }
                }
                tr.Commit();
            }
        } // END ProcessDXFEntities
コード例 #6
0
        public void SelectAtDistanseAtVis()
        {
            List <DBText> res = new List <DBText>();

            DBText sourceObj;

            if (!ObjectCollector.TrySelectAllowedClassObject <DBText>(out sourceObj))
            {
                return;
            }
            DBText destObj;

            if (!ObjectCollector.TrySelectAllowedClassObject <DBText>(out destObj))
            {
                return;
            }

            Rectangle3d?bounds = sourceObj.GetTextBoxCorners();

            if (!bounds.HasValue)
            {
                return;
            }
            Rectangle3d?destBounds = destObj.GetTextBoxCorners();

            if (!destBounds.HasValue)
            {
                return;
            }

            Vector3d vector = destBounds.Value.LowerLeft - bounds.Value.LowerLeft;

            Drawing.SimpleGride gride1 = new Drawing.SimpleGride(bounds.Value.LowerLeft, vector.GetPerpendicularVector().Negate(), vector, vector.Length, vector.Length);

            TypedValue[] tvs = new[] {
                new TypedValue((int)DxfCode.Start, "TEXT")
            };

            //Tools.GetActiveAcadDocument().SendStringToExecute("._zoom _e ", true, false, false);


            Polyline rectg = new Polyline(5);

            rectg.AddVertexAt(0, bounds.Value.LowerLeft.Add((bounds.Value.LowerLeft - bounds.Value.UpperRight).MultiplyBy(0.2)));
            rectg.AddVertexAt(1, bounds.Value.UpperLeft.Add((bounds.Value.UpperLeft - bounds.Value.LowerRight).MultiplyBy(0.2)));
            rectg.AddVertexAt(2, bounds.Value.UpperRight.Add((bounds.Value.UpperRight - bounds.Value.LowerLeft).MultiplyBy(0.2)));
            rectg.AddVertexAt(3, bounds.Value.LowerRight.Add((bounds.Value.LowerRight - bounds.Value.UpperLeft).MultiplyBy(0.2)));
            rectg.AddVertexAt(4, bounds.Value.LowerLeft.Add((bounds.Value.LowerLeft - bounds.Value.UpperRight).MultiplyBy(0.2)));

            int     count          = 200;
            Point3d maxPointScreen = sourceObj.Position.Add(vector.MultiplyBy(count) +
                                                            vector.GetPerpendicularVector().Negate().MultiplyBy(count * vector.Length));
            Point3d minPointScreen = sourceObj.Position.Add(vector.Negate().MultiplyBy(count) +
                                                            vector.GetPerpendicularVector().MultiplyBy(count * vector.Length));

            Drawing.Helpers.Zoomer.Zoom(minPointScreen, maxPointScreen, new Point3d(), 1);

            Tools.StartTransaction(() =>
            {
                for (int r = -count; r < count; r++)
                {
                    for (int c = -count; c < count; c++)
                    {
                        var point1   = gride1.CalculateGridPoint(r, c);
                        Matrix3d mat = Matrix3d.Displacement(point1 - bounds.Value.LowerLeft);

                        var spres = Tools.GetAcadEditor().SelectWindowPolygon(((Polyline)rectg.GetTransformedCopy(mat)).GetPoints(),
                                                                              new SelectionFilter(tvs));

                        //((Polyline)rectg.GetTransformedCopy(mat)).SaveToDatebase();

                        if (spres.Status == PromptStatus.OK)
                        {
                            DBText text = spres.Value.GetSelectedItems <DBText>().FirstOrDefault();
                            if (text != null)
                            {
                                text.UpgradeOpen();
                                text.ColorIndex = 181;
                                text.DowngradeOpen();
                            }
                        }


                        /*Entity[] marker = new[] { (Entity)new DBPoint(point1), (Entity)new Line(point1, point1.Add(bounds.Value.UpperRight - bounds.Value.LowerLeft)) };
                         * marker.SaveToDatebase<Entity>();*/
                    }
                }
            });
        }
コード例 #7
0
ファイル: DbTextsFormator.cs プロジェクト: sunjini/CADDev
        private void SeperateOneDbText(DocumentModifier docMdf, DBText txt, BlockTableRecord btr)
        {
            var txtStr = txt.TextString;

            if (txtStr.Length == 0)
            {
                return;
            }
            // if (txtStr.Length == 1) return;
            // 单行文字中至少有一个字符

            bool         lasteIsEng      = (int)txtStr[0] < 127;
            TextLanguage curTextLanguage = new TextLanguage(isEng: lasteIsEng);
            var          sepTexts        = new List <TextLanguage> {
                curTextLanguage
            };                                                         // 分割好的文字

            for (int i = 0; i < txtStr.Length; i++)
            {
                char c = txtStr[i];
                // 如果是空格,则保持其前面的中英文类型
                if (char.IsWhiteSpace(c))
                {
                    curTextLanguage.Append(c);
                }
                // 1、用ASCII码判断:在 ASCII码表中,英文的范围是0 - 127,而汉字则是大于127。
                else if ((int)c > 127) // 说明是中文
                {
                    if (lasteIsEng)
                    {
                        curTextLanguage = new TextLanguage(false);
                        sepTexts.Add(curTextLanguage);
                        //
                    }
                    curTextLanguage.Append(c);
                    lasteIsEng = false;
                }
                else // 说明是英文
                {
                    if (!lasteIsEng)
                    {
                        curTextLanguage = new TextLanguage(true);
                        sepTexts.Add(curTextLanguage);
                        //
                    }
                    curTextLanguage.Append(c);
                    lasteIsEng = true;
                }
            }
            // ------------- 对分割好的文字进行处理
            double selfMoveY;
            double nextMoveX;
            var    firstT = sepTexts[0];

            if (sepTexts.Count == 1)
            {
                // 只修改字高,不修改定位
                txt.UpgradeOpen();
                txt.Height = GetStringHeight(firstT._isEng, out nextMoveX, out selfMoveY);
                txt.DowngradeOpen();
            }
            else if (sepTexts.Count > 1)
            {
                DBText  leftTxt = txt;
                DBText  rightTxt;
                Point3d oriLeftBottom = leftTxt.Position; // 全部文本的最左下角点

                // 先处理第一批字符
                leftTxt.UpgradeOpen();
                leftTxt.TextString = firstT.Text;

                // 将对齐方式转换为默认的左对齐
                leftTxt.SetAlignment();
                //
                leftTxt.Height   = GetStringHeight(firstT._isEng, out nextMoveX, out selfMoveY);
                leftTxt.Position = new Point3d(oriLeftBottom.X, oriLeftBottom.Y + selfMoveY, oriLeftBottom.Z);

                // GetStringWidth(firstT._isEng, firstT.Text.Length, originalHeight, widthFactor);
                leftTxt.DowngradeOpen();
                //
                var     leftWidth = 0.0; // GetTextWidth(leftTxt); // 左侧文本的左下角点到全部文本最左下角点的距离
                var     rota      = leftTxt.Rotation;
                var     thisMoveX = nextMoveX;
                Point3d startPosition;;  // 字符末端的坐标
                // 处理后面的字符串
                for (int i = 1; i < sepTexts.Count; i++)
                {
                    var tl = sepTexts[i];
                    rightTxt            = leftTxt.GetTransformedCopy(Matrix3d.Identity) as DBText;
                    rightTxt.TextString = tl.Text;
                    rightTxt.Height     = GetStringHeight(tl._isEng, out nextMoveX, out selfMoveY);
                    startPosition       = GetStartPosition(oriLeftBottom, ref leftWidth, leftTxt, rota, thisMoveX, selfMoveY);
                    rightTxt.Position   = startPosition;
                    //
                    thisMoveX = nextMoveX;
                    leftTxt   = rightTxt;
                    // GetStringWidth(tl._isEng, tl.Text.Length, originalHeight, widthFactor);
                    // 添加到数据库中
                    btr.AppendEntity(rightTxt);
                    docMdf.acTransaction.AddNewlyCreatedDBObject(rightTxt, true);
                }
            }
        }