コード例 #1
0
            public ObjectId AppendBlock(Point3d position, Point3d valuePoint)
            {
                Matrix3d rot = Matrix3d.Rotation(this.SpecifyAngle, this.Matrix.CoordinateSystem3d.Zaxis, position);

                if (this.SpecifyAngle != 0d)
                {
                    position   = position.TransformBy(rot);
                    valuePoint = valuePoint.TransformBy(rot);
                }

                double value = Mode == DirectionMode.Horizontal ?
                               _calcValue(position, valuePoint).X :
                               _calcValue(position, valuePoint).Y;

                ObjectId brId = BlockTools.AddBlockRefToModelSpace(this.BlockTableRecordId,
                                                                   new List <string>(new[] { Math.Abs(Math.Round(value * 1000d, 0)).ToString() }), position, Matrix);

                using (Transaction trans = Tools.StartTransaction())
                {
                    BlockReference br = (BlockReference)trans.GetObject(brId, OpenMode.ForRead);
                    br.UpgradeOpen();
                    if (value < 0)
                    {
                        Mirror(br);
                    }
                    if (this.SpecifyAngle != 0d)
                    {
                        br.TransformBy(rot);
                    }
                    trans.Commit();
                }
                return(brId);
            }
コード例 #2
0
            public ObjectId DisplayArrow(Point3d position, Point3d valuePoint, string tag, Autodesk.AutoCAD.GraphicsInterface.TransientDrawingMode viewMod = Autodesk.AutoCAD.GraphicsInterface.TransientDrawingMode.DirectShortTerm)
            {
                ObjectId       brId = AppendBlock(position, valuePoint);
                BlockReference br;

                using (Transaction trans = Tools.StartTransaction())
                {
                    br = (BlockReference)brId.GetObject(OpenMode.ForWrite, false, true);
                    br.Erase(true);
                    trans.Commit();
                }
                using (Transaction trans = Tools.StartTransaction())
                {
                    ObjectId btrId = BlockTools.GetAnonymCopy(brId, trans, false);
                    brId = BlockTools.AddBlockRefToModelSpace(btrId, new[] { "N" }.ToList(), br.Position, this.Matrix);
                    trans.Commit();
                }

                using (Transaction trans = Tools.StartTransaction())
                {
                    br = (BlockReference)brId.GetObject(OpenMode.ForWrite, false, true);
                    br.Erase(true);
                    trans.Commit();
                }

                using (Transaction trans = Tools.StartTransaction())
                {
                    br = (BlockReference)brId.GetObject(OpenMode.ForWrite, true, true);
                    this.DynTransient.ClearTransientGraphics();
                    this.DynTransient.AddMarker((DBObject)br, tag, viewMod);
                    this.DynTransient.Display();
                }

                return(brId);
            }
コード例 #3
0
ファイル: BlockCmd.cs プロジェクト: VB6Hobbyst7/AutoCad-1
            public ArrowDirectional2 PastNewArrowItem(Point3d position, Point3d valuePoint)
            {
                _createBlockRecord();

                double value = Mode == DirectionMode.Horizontal ?
                               _calcValue(position, valuePoint).X :
                               _calcValue(position, valuePoint).Y;

                if (value < 0)
                {
                    _mirror();
                }

                ObjectId brId = BlockTools.AddBlockRefToModelSpace(this.BlockTableRecordId,
                                                                   new List <string>(new[] { Math.Abs(Math.Round(value * 1000d, 0)).ToString() }), position, UcsMatrix);

                /*using (Transaction trans = Tools.StartTransaction())
                 * {
                 *  if (value < 0)
                 *  {
                 *      BlockTableRecord btr = this.BlockTableRecordId.GetObjectForRead<BlockTableRecord>();
                 *      btr.UpgradeOpen();
                 *      //btr.UpdateAnonymousBlocks();
                 *
                 *      _arrowBlockRef = (BlockReference)trans.GetObject(brId, OpenMode.ForRead);
                 *      _arrowBlockRef.UpgradeOpen();
                 *      _mirror();
                 *      _arrowBlockRef.RecordGraphicsModified(true);
                 *
                 *
                 *      if (_arrowBlockRef.AttributeCollection != null)
                 *      {
                 *          foreach (ObjectId arId in _arrowBlockRef.AttributeCollection)
                 *          {
                 *              AttributeReference ar = (AttributeReference)arId.GetObject(OpenMode.ForRead, false, true);
                 *              ar.UpgradeOpen();
                 *              ar.RecordGraphicsModified(true);
                 *          }
                 *      }
                 *  }
                 * }*/


                Tools.GetActiveAcadDocument().TransactionManager.FlushGraphics();
                this.ArrowId = brId;

                return(this);
            }
コード例 #4
0
            public ObjectId AppendBlockEx(Point3d position, Point3d valuePoint)
            {
                Matrix3d rot = Matrix3d.Rotation(this.SpecifyAngle, this.Matrix.CoordinateSystem3d.Zaxis, position);

                if (this.SpecifyAngle != 0d)
                {
                    position   = position.TransformBy(rot);
                    valuePoint = valuePoint.TransformBy(rot);
                }

                double value = Mode == DirectionMode.Horizontal ?
                               _calcValue(position, valuePoint).X :
                               _calcValue(position, valuePoint).Y;

                ObjectId brId = BlockTools.AddBlockRefToModelSpace(this.BlockTableRecordId,
                                                                   new List <string>(new[] { Math.Abs(Math.Round(value * 1000d, 0)).ToString() }), position, Matrix);

                BlockReference br;

                using (Transaction trans = Tools.StartTransaction())
                {
                    br = (BlockReference)trans.GetObject(brId, OpenMode.ForRead);
                    br.UpgradeOpen();
                    if (value < 0)
                    {
                        Mirror(br);
                    }
                    if (this.SpecifyAngle != 0d)
                    {
                        br.TransformBy(rot);
                    }
                    trans.Commit();
                }

                /*using (Transaction trans = Tools.StartTransaction())
                 * {
                 *  ObjectId anyBtrId = BlockTools.GetAnonymCopy(br.Id, trans, false);
                 *  AttributeReference ar = br.GetAttributeByTag(this.anchorTag, trans);
                 *  br = (BlockReference)trans.GetObject(brId, OpenMode.ForWrite);
                 *  br.Erase(true);
                 *  brId = BlockTools.AddBlockRefToModelSpace(anyBtrId, new[] { ar.TextString }.ToList(), br.Position, Matrix, trans, false);
                 *  trans.Commit();
                 * }*/

                return(brId);
            }
コード例 #5
0
ファイル: BlockCmd.cs プロジェクト: VB6Hobbyst7/AutoCad-1
        public void TestAnonyBlock()
        {
            Polyline pline = new Polyline(3);

            pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
            pline.AddVertexAt(1, new Point2d(pline.GetPoint2dAt(0).X + 3, pline.GetPoint2dAt(0).Y), 0, 0.4, 0);
            pline.AddVertexAt(2, new Point2d(pline.GetPoint2dAt(1).X + 1.5, pline.GetPoint2dAt(1).Y), 0, 0, 0);
            pline.LineWeight = LineWeight.LineWeight020;

            AttributeDefinition ad = _createAttribute(pline.StartPoint, pline);

            Matrix3d ucs = CoordinateSystem.CoordinateTools.GetCurrentUcs();

            var btrId = BlockTools.CreateBlockTableRecordEx(Point3d.Origin, "test11111", new[] { (Entity)pline, (Entity)ad }.ToList(), AnnotativeStates.True);
            var brId  = BlockTools.AddBlockRefToModelSpace(btrId, new[] { "3" }.ToList(), new Point3d(10, 10, 10), ucs);

            using (Transaction trans = Tools.StartTransaction())
            {
                BlockReference br = (BlockReference)brId.GetObject(OpenMode.ForRead, false, true);
                br.UpgradeOpen();
                br.TransformBy(Matrix3d.Rotation(Math.PI / 2d, ucs.CoordinateSystem3d.Zaxis, br.Position));
                //br.Erase(true);
                trans.Commit();
            }

            AttributeReference ar;

            using (Transaction trans = Tools.StartTransaction())
            {
                BlockReference br = (BlockReference)brId.GetObject(OpenMode.ForRead, true, true);
                ar = br.GetAttributeByTag(ad.Tag, trans);
                ar = (AttributeReference)ar.Id.GetObject(OpenMode.ForRead, true, true);
                var anBtrId = BlockTools.GetAnonymCopy(brId, trans, false);
                var anBrId  = BlockTools.AddBlockRefToModelSpace(anBtrId, new[] { ar.TextString }.ToList(), new Point3d(0, 0, 0), ucs);

                trans.Commit();
            }
        }
コード例 #6
0
        public bool DrawAnchorDeviations()
        {
            Polyline pline = new Polyline(4);
            pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
            pline.AddVertexAt(1, new Point2d(3, 0), 0, 0, 0);
            pline.AddVertexAt(2, new Point2d(4, 0), 0, 0.4, 0);
            pline.AddVertexAt(3, new Point2d(5.5, 0), 0, 0.4, 0);
            pline.LineWeight = LineWeight.LineWeight015;

            AttributeDefinition acAttDef = new AttributeDefinition();

            acAttDef.Verifiable = true;
            acAttDef.Height = 1.8;
            //acAttDef.Justify = AttachmentPoint.BaseMid;
            acAttDef.Prompt = "Deviation #: ";
            acAttDef.Tag = "Deviation#";
            acAttDef.TextString = "0";
            acAttDef.Position = new Point3d((pline.Length) / 2d - acAttDef.Height / 2d, acAttDef.Height * 0.1, 0);

            PromptPointOptions ppo = new PromptPointOptions("\nУкажите проектное положение");
            PromptPointResult ppr = Tools.GetAcadEditor().GetPoint(ppo);

            if (ppr.Status != PromptStatus.OK)
                return false;
            Point3d pPoint = ppr.Value;

            ppo = new PromptPointOptions("\nУкажите фактическое положение");
            ppo.BasePoint = pPoint;
            ppo.UseBasePoint = true;
            ppo.UseDashedLine = true;

            ppr = Tools.GetAcadEditor().GetPoint(ppo);

            if (ppr.Status != PromptStatus.OK)
                return false;
            Point3d fPoint = new Point3d(ppr.Value.X, ppr.Value.Y, pPoint.Z);

            List<Entity> ents = new List<Entity>(new[] { pline, (Entity)acAttDef });

            var btrId = BlockTools.CreateBlockTableRecordEx(Point3d.Origin, "_DrawAnchorDeviations", ents, AnnotativeStates.True);

            if (btrId != ObjectId.Null)
            {
                fPoint = fPoint.RotateBy(-_angle, _ucs.CoordinateSystem3d.Zaxis, pPoint);

                var brHorizontalId = BlockTools.AddBlockRefToModelSpace(btrId, new[] { Math.Abs(Math.Round((fPoint.X - pPoint.X) * 1000d, 0)).ToString() }.ToList(), pPoint, _ucs);
                var brVerticalId = BlockTools.AddBlockRefToModelSpace(btrId, new[] { Math.Abs(Math.Round((fPoint.Y - pPoint.Y) * 1000d, 0)).ToString() }.ToList(), pPoint, _ucs);
                using (Transaction trans = Tools.StartTransaction())
                {
                    BlockReference br1 = (BlockReference)trans.GetObject(brHorizontalId, OpenMode.ForWrite);
                    BlockReference br2 = (BlockReference)trans.GetObject(brVerticalId, OpenMode.ForWrite);

                    const string MIRRTEXT = "MIRRTEXT";
                    object defVal = acadApp.Application.GetSystemVariable(MIRRTEXT);
                    acadApp.Application.SetSystemVariable(MIRRTEXT, 0);

                    try
                    {
                        if (fPoint.X - pPoint.X < 0d)
                        {
                            BlockTools.MirroringBlockByYAxis(br1);
                        }

                        br2.TransformBy(Matrix3d.Rotation(Math.PI / 2, _ucs.CoordinateSystem3d.Zaxis, br2.Position));
                        if (fPoint.X - pPoint.X < 0d)
                            BlockTools.MirroringBlockByYAxis(br2);
                        if (fPoint.Y - pPoint.Y < 0)
                        {
                            BlockTools.MirroringBlockByXAxis(br2);
                            BlockTools.MirroringBlockByYAxis(br2);
                        }

                        br1.TransformBy(Matrix3d.Rotation(_angle, _ucs.CoordinateSystem3d.Zaxis, br1.Position));
                        br2.TransformBy(Matrix3d.Rotation(_angle, _ucs.CoordinateSystem3d.Zaxis, br2.Position));

                        using (TransientGraphicsTools.SelectableTransient _transient =
                            new TransientGraphicsTools.SelectableTransient(new List<Entity>(new[] { br1, br2 })))
                        {
                            _transient.Display();

                            ppo = new PromptPointOptions("\nУкажите точку определяющую сторону отобажения");
                            ppo.UseBasePoint = true;
                            ppo.BasePoint = pPoint;
                            ppo.UseDashedLine = true;

                            ppr = Tools.GetAcadEditor().GetPoint(ppo);

                            if (ppr.Status == PromptStatus.OK)
                            {
                                Point3d point = ppr.Value;

                                Polyline transPline = null;

                                if (pline.Id != ObjectId.Null)
                                    pline = (Polyline)trans.GetObject(pline.Id, OpenMode.ForRead);
                                transPline = (Polyline)pline.Clone();

                                transPline.TransformBy(br1.BlockTransform);
                                double ang = CoordinateGeometry.Helper.GetAngle(transPline.StartPoint, transPline.EndPoint, point);
                                if (Math.Abs(ang) > Math.PI/2d)
                                {
                                    Matrix3d mat = Matrix3d.Displacement(transPline.StartPoint - transPline.EndPoint);
                                    br1.TransformBy(mat);
                                }

                                transPline = (Polyline)pline.Clone();

                                transPline.TransformBy(br2.BlockTransform);
                                ang = CoordinateGeometry.Helper.GetAngle(transPline.StartPoint, transPline.EndPoint, point);
                                if (Math.Abs(ang) > Math.PI / 2d)
                                {
                                    Matrix3d mat = Matrix3d.Displacement(transPline.StartPoint - transPline.EndPoint);
                                    br2.TransformBy(mat);
                                }
                            }

                            _transient.StopDisplaying();
                        }

                        trans.Commit();
                        return true;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        acadApp.Application.SetSystemVariable(MIRRTEXT, defVal);
                    }
                }
            }
            return false;
        }