Ejemplo n.º 1
0
        public virtual void TrasientDisplayAtBlock(Point3d insertPoint, IEnumerable <Entity> entities)
        {
            if (_transient == null)
            {
                _transient = new IgorKL.ACAD3.Model.Helpers.Display.DynamicTransient();
            }

            Calculate();
            ObjectId btrId   = AcadBlocks.BlockTools.CreateBlockTableRecord("*U", insertPoint, entities.Select(ent => (Entity)ent.Clone()), _annotative);
            ObjectId blockId = AcadBlocks.BlockTools.AppendBlockItem(insertPoint, btrId, null, _ucs);

            BlockReference block = null;

            Tools.StartTransaction(() =>
            {
                block      = blockId.GetObjectForWrite <BlockReference>();
                var buffer = (BlockReference)block.Clone();
                block.Erase(true);
                block = buffer;
            });

            _transient.AddMarker((DBObject)block);

            _transient.Display();
        }
Ejemplo n.º 2
0
        protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
        {
            lock (Entities)
            {
                Entities.Clear();
                Entities.AddRange(_arrow.Explode().Select(x =>
                {
                    if (x is DBText)
                    {
                        return(_convertToAttribute((DBText)x));
                    }
                    return(x);
                }));

                ObjectId btrId = AcadBlocks.BlockTools.CreateBlockTableRecordEx(_insertPoint, "*U", Entities.Select(x => (Entity)x.Clone()).ToList(), AnnotativeStates.True);
                ObjectId brId  = AcadBlocks.BlockTools.AddBlockRefToModelSpace(btrId, null, _insertPoint, _ucs);

                Tools.StartTransaction(() =>
                {
                    BlockReference br = brId.GetObjectForWrite <BlockReference>();
                    br.SetDatabaseDefaults(HostApplicationServices.WorkingDatabase);
                    br.RecordGraphicsModified(true);

                    Entity inMemoryEntity = (Entity)br.Clone();
                    draw.Geometry.Draw(inMemoryEntity);

                    var btr = br.BlockTableRecord.GetObjectForWrite <BlockTableRecord>();
                    br.Erase();
                    btr.EraseBolckTableRecord();
                    inMemoryEntity.Dispose();
                });
            }

            return(true);
        }
Ejemplo n.º 3
0
        public virtual void TrasientDisplayAtBlock()
        {
            if (_transient == null)
            {
                _transient = new IgorKL.ACAD3.Model.Helpers.Display.DynamicTransient();
            }

            Calculate();
            ObjectId btrId   = _createTableRecord(_entities.Select(ent => (Entity)ent.Clone()));
            ObjectId blockId = _createBlockItem(btrId, _insertPointUcs);

            BlockReference block = null;

            Tools.StartTransaction(() =>
            {
                block      = blockId.GetObjectForWrite <BlockReference>();
                var buffer = (BlockReference)block.Clone();
                block.Erase(true);
                block = buffer;
            });

            _transient.AddMarker((DBObject)block);

            _transient.Display();
        }
Ejemplo n.º 4
0
        private void _setEntitiesFromInnerGrid()
        {
            int rowCount    = SimpleGride.CalculateCeilingCount(_boundRectg.GetLeftVerticalVector(), _step) + 1;
            int columnCount = SimpleGride.CalculateCeilingCount(_boundRectg.GetLowertHorizontalVector(), _step) + 1;

            if (rowCount * columnCount > Math.Pow(50, 2))
            {
                return;
            }
            if (rowCount * columnCount == 0d)
            {
                return;
            }

            Entities.ForEach(ent => ent.Dispose());
            Entities.Clear();
            CoordinateLable lableFactory = new CoordinateLable();

            Tools.StartTransaction(() =>
            {
                for (int row = 0; row < rowCount; row++)
                {
                    for (int col = 0; col < columnCount; col++)
                    {
                        //Entities.Add(new DBPoint(_innerGridUcs.CalculateGridPoint(row, col)));
                        Point3d point     = _innerGridUcs.CalculateGridPoint(row, col);
                        BlockReference br = lableFactory.CreateItem(point, Matrix3d.Identity).GetObjectForRead <BlockReference>();
                        Entities.Add((Entity)br.Clone());
                        br.Erase(true);
                    }
                }
                Tools.GetAcadDatabase().TransactionManager.QueueForGraphicsFlush();
            });
        }
Ejemplo n.º 5
0
        public static ObjectId GetAnonymClone(this BlockReference br, Point3d position)
        {
            ObjectId res = ObjectId.Null;

            Tools.StartTransaction(() =>
            {
                br = br.Id.GetObjectForRead <BlockReference>(true);
                DBObjectCollection entIds = new DBObjectCollection();
                ((BlockReference)br.Clone()).Explode(entIds);

                List <Entity> ents = new List <Entity>();
                foreach (DBObject obj in entIds)
                {
                    Entity ent = (Entity)obj;
                    ent.TransformBy(br.BlockTransform);
                    ents.Add(ent);
                }
                List <string> attrVals = new List <string>();
                foreach (ObjectId id in br.AttributeCollection)
                {
                    AttributeReference ar = (AttributeReference)id.GetObject(OpenMode.ForRead, true, true);
                    attrVals.Add(ar.TextString);
                }
                ObjectId btrId = IgorKL.ACAD3.Model.AcadBlocks.BlockTools.CreateBlockTableRecordEx(Point3d.Origin, "*U", ents, AnnotativeStates.True);
                res            = IgorKL.ACAD3.Model.AcadBlocks.BlockTools.AddBlockRefToModelSpace(btrId, attrVals, position, br.BlockTransform);
            });
            Tools.StartTransaction(() =>
            {
                res.GetObjectForRead <BlockReference>().BlockTableRecord.GetObjectForRead <BlockTableRecord>().Update();
            });
            return(res);
        }
Ejemplo n.º 6
0
        public static void UserPlot(Document acDoc)
        {
            //Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            Editor   acDocEd = acDoc.Editor;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                DBObjectCollection acBlkTblRecSpcColl = GetBlockTableRecordSpaceCollection(acDoc);
                BlockTable         acBlkTbl           = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                if (acBlkRef == null)
                {
                    acBlkRef    = GetBlockReference(acDoc, "Pick a title block", "You must pick a title block!");
                    acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkRef.BlockTableRecord, OpenMode.ForRead);
                    AttributeID = GetAttributeID(acDoc, acBlkTblRec);
                    Point3d OriginBottomPoint = GetPoint3dFromPrompt(acDoc, "Pick first point");
                    Point3d OriginTopPoint    = GetPoint3dFromPrompt(acDoc, "Pick second point");
                    InsertPointToBottomPoint = acBlkRef.Position.GetVectorTo(OriginBottomPoint);
                    InsertPointToTopPoint    = acBlkRef.Position.GetVectorTo(OriginTopPoint);
                    acScl3d = acBlkRef.ScaleFactors;
                    string[] acPlDevCanMed = GetPlotDeviceAndCanonicalMediaName();
                    acPlDev = acPlDevCanMed[0]; acCanMed = acPlDevCanMed[1];

                    acBlkTblRec = (BlockTableRecord)acBlkTblRec.Clone();
                    acBlkRef    = (BlockReference)acBlkRef.Clone();
                }
                foreach (DBObject acDbBlkTblRec in acBlkTblRecSpcColl)
                {
                    BlockTableRecord acBlkTblRecSpc = (BlockTableRecord)acDbBlkTblRec;
                    foreach (ObjectId acObjId in acBlkTblRecSpc)
                    {
                        Entity acEnt = (Entity)acTrans.GetObject(acObjId, OpenMode.ForRead);
                        if (acEnt is BlockReference)
                        {
                            BlockReference   acBlkRef1    = (BlockReference)acEnt;
                            BlockTableRecord acBlkTblRec1 = (BlockTableRecord)acTrans.GetObject(acBlkRef1.BlockTableRecord, OpenMode.ForRead);
                            if (acBlkTblRec1.Name.Equals(acBlkTblRec.Name))
                            {
                                Extents2d acExt2d = GetPlotArea(acBlkRef1, acScl3d, InsertPointToBottomPoint, InsertPointToTopPoint);
                                string    path    = Path.Combine(DirectoryFolder(acDoc.Database.OriginalFileName), Path.GetFileName(GetAttributeString(acDoc, acBlkRef1, AttributeID)));
                                InKhungTen(acBlkTblRecSpc, acExt2d, path, acPlDev, acCanMed);
                            }
                        }
                    }
                }
                acTrans.Commit();
            }
        }
Ejemplo n.º 7
0
        private void _setEntitiesToBlock(bool erase)
        {
            Tools.StartTransaction(() => {
                var btrId = AcadBlocks.BlockTools.CreateBlockTableRecord("*U", _insertPoint, Entities, AnnotativeStates.True);
                //var brId = AcadBlocks.BlockTools.AppendBlockItem(_lowerPointUcs.TransformBy(_ucs.Inverse()), btrId, null, Matrix3d.Identity);
                var brId          = AcadBlocks.BlockTools.AppendBlockItem(_insertPoint, btrId, null, _ucs);
                BlockReference br = brId.GetObjectForRead <BlockReference>();
                Entities.Add((Entity)br.Clone());

                if (erase)
                {
                    br.UpgradeOpen();
                    br.Erase();
                }
            });
        }
Ejemplo n.º 8
0
        private void _setEntitiesToBlock(Point3d insertPointUcs, IEnumerable <Entity> entities, Dictionary <string, string> attrInfo, bool erase)
        {
            ObjectId btrId = AcadBlocks.BlockTools.CreateBlockTableRecord("*U", Point3d.Origin, entities, Annotative);
            ObjectId brId  = AcadBlocks.BlockTools.AppendBlockItem(insertPointUcs.TransformBy(Ucs), btrId, attrInfo);

            Tools.StartTransaction(() =>
            {
                BlockReference br = brId.GetObjectForRead <BlockReference>();
                br.UpgradeOpen();
                if (_arrowUpper != null)
                {
                    _arrowUpper.SaveToEntity(br);
                }
                br.RecordGraphicsModified(true);
                Entities.Add((Entity)br.Clone());
                if (erase)
                {
                    br.Erase(true);
                }
            });
        }
Ejemplo n.º 9
0
        public static void b()
        {
            DocumentCollection acDocMgr = Application.DocumentManager;
            Document           acDoc    = acDocMgr.MdiActiveDocument;
            Database           acCurDb  = acDocMgr.MdiActiveDocument.Database;
            Editor             acDocEd  = acDocMgr.MdiActiveDocument.Editor;

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                DBObjectCollection acBlkTblRecSpcColl = GetBlockTableRecordSpaceCollection(acDoc);
                BlockTable         acBlkTbl           = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
                if (acBlkRef == null)
                {
                    acBlkRef    = GetBlockReference(acDoc, "Pick a title block", "You must pick a title block!");
                    acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkRef.BlockTableRecord, OpenMode.ForRead);
                    AttributeID = GetAttributeID(acDoc, acBlkTblRec);
                    Point3d OriginBottomPoint = GetPoint3dFromPrompt(acDoc, "Pick first point");
                    Point3d OriginTopPoint    = GetPoint3dFromPrompt(acDoc, "Pick second point");
                    InsertPointToBottomPoint = acBlkRef.Position.GetVectorTo(OriginBottomPoint);
                    InsertPointToTopPoint    = acBlkRef.Position.GetVectorTo(OriginTopPoint);
                    acScl3d = acBlkRef.ScaleFactors;
                    string[] acPlDevCanMed = GetPlotDeviceAndCanonicalMediaName();
                    acPlDev     = acPlDevCanMed[0]; acCanMed = acPlDevCanMed[1];
                    acBlkTblRec = (BlockTableRecord)acBlkTblRec.Clone();
                    acBlkRef    = (BlockReference)acBlkRef.Clone();
                }
            }
            foreach (Document acDoc1 in acDocMgr)
            {
                acDocMgr.MdiActiveDocument = acDoc1;
                using (DocumentLock acDocLck1 = acDoc1.LockDocument())
                {
                    UserPlot2(acDoc1);
                }
            }
        }
Ejemplo n.º 10
0
        public void cmdAssemblyFromBlocks()
        {
            var doc = AcApp.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;
            var db  = doc.Database;

            var openFileDialog = new Microsoft.Win32.OpenFileDialog();

            openFileDialog.Filter      = "All files (*.*)|*.*|DWG files (*.dwg)|*.dwg";
            openFileDialog.FilterIndex = 2;
            if (openFileDialog.ShowDialog() != true)
            {
                return;
            }
            var filePath = openFileDialog.FileName;

            ImportBlocksFromExternalDrawing(db, filePath);

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var bt        = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                var ms        = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                var blockVLId = bt["vl"];
                var blockVSId = bt["vs"];
                var blockHLId = bt["hl"];
                var blockHSId = bt["hs"];

                CreateBlockReference(tr, ms, blockVLId, new Point3d(0, 0, 0));
                CreateBlockReference(tr, ms, blockVLId, new Point3d(300, 0, 0));
                CreateBlockReference(tr, ms, blockVSId, new Point3d(700, 0, 0));
                CreateBlockReference(tr, ms, blockVLId, new Point3d(0, 1600, 0));
                CreateBlockReference(tr, ms, blockVLId, new Point3d(300, 1600, 0));
                CreateBlockReference(tr, ms, blockVSId, new Point3d(700, 1600, 0));

                var level1Height = 100;
                var level2Height = 785;

                {
                    var hs = new BlockReference(new Point3d(0, 0, level1Height), blockHSId);
                    hs.TransformBy(Matrix3d.Rotation(90.0 / 180.0 * Math.PI, Vector3d.YAxis, new Point3d(0, 0, level1Height)));
                    var hs2 = hs.Clone() as BlockReference;
                    hs2.TransformBy(Matrix3d.Displacement(new Vector3d(0, 1600, 0)));
                    var hs3 = hs.Clone() as BlockReference;
                    hs3.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, level2Height - level1Height)));
                    var hs4 = hs2.Clone() as BlockReference;
                    hs4.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, level2Height - level1Height)));

                    ms.AppendEntity(hs);
                    tr.AddNewlyCreatedDBObject(hs, true);
                    ms.AppendEntity(hs2);
                    tr.AddNewlyCreatedDBObject(hs2, true);
                    ms.AppendEntity(hs3);
                    tr.AddNewlyCreatedDBObject(hs3, true);
                    ms.AppendEntity(hs4);
                    tr.AddNewlyCreatedDBObject(hs4, true);
                }

                {
                    var hl = new BlockReference(new Point3d(0, 0, level1Height), blockHLId);
                    hl.TransformBy(Matrix3d.Rotation(-90.0 / 180.0 * Math.PI, Vector3d.XAxis, new Point3d(0, 0, level1Height)));
                    var hl2 = hl.Clone() as BlockReference;
                    hl2.TransformBy(Matrix3d.Displacement(new Vector3d(300, 0, 0)));
                    var hl3 = hl.Clone() as BlockReference;
                    hl3.TransformBy(Matrix3d.Displacement(new Vector3d(700, 0, 0)));
                    var hl4 = hl.Clone() as BlockReference;
                    hl4.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, level2Height - level1Height)));
                    var hl5 = hl2.Clone() as BlockReference;
                    hl5.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, level2Height - level1Height)));
                    var hl6 = hl3.Clone() as BlockReference;
                    hl6.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, level2Height - level1Height)));

                    ms.AppendEntity(hl);
                    tr.AddNewlyCreatedDBObject(hl, true);
                    ms.AppendEntity(hl2);
                    tr.AddNewlyCreatedDBObject(hl2, true);
                    ms.AppendEntity(hl3);
                    tr.AddNewlyCreatedDBObject(hl3, true);
                    ms.AppendEntity(hl4);
                    tr.AddNewlyCreatedDBObject(hl4, true);
                    ms.AppendEntity(hl5);
                    tr.AddNewlyCreatedDBObject(hl5, true);
                    ms.AppendEntity(hl6);
                    tr.AddNewlyCreatedDBObject(hl6, true);
                }


                tr.Commit();
            }
        }
        static public void CmdInsertBlock()
        {
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            PromptStringOptions optName = new PromptStringOptions("\nEnter the name of the block: ");

            optName.AllowSpaces = true;

            if (_sLastBlock == string.Empty)
            {
                optName.UseDefaultValue = true;
                optName.DefaultValue    = _sLastBlock;
            }

            //Loop
            do
            {
                //Esk the user by block name
                PromptResult ProNameRes = ed.GetString(optName);

                if (ProNameRes.Status == PromptStatus.Cancel)
                {
                    break;//Command canceled, go out of loop
                }
                else
                {
                    //Get objId
                    ObjectId objId = GetBlockId(ProNameRes.StringResult);

                    if (objId.IsValid)
                    {
                        //Create BlockReference
                        BlockReference blockRef = new BlockReference(new Point3d(), objId);

                        //Strategy for Preview in PointMonitor
                        _PointMonitorStrategy = new PointMonitorStrategy(delegate(object sender, PointMonitorEventArgs e)
                        {
                            try
                            {
                                //Refresh gost block.
                                blockRef.Position = e.Context.ComputedPoint;
                                e.Context.DrawContext.Geometry.Draw(blockRef);
                            }
                            catch (System.Exception ex)
                            {
                            }
                        });


                        //add pointMonitor
                        ed.PointMonitor += new PointMonitorEventHandler(PointMonitor);

                        //Get Second point
                        PromptPointOptions opcoesPonto = new PromptPointOptions("\nClick on the place where block will be inserted: ");
                        opcoesPonto.AllowNone = false;

                        PromptPointResult ProPtRes = ed.GetPoint(opcoesPonto);

                        //remove pointMonitor
                        ed.PointMonitor -= new PointMonitorEventHandler(PointMonitor);

                        //Definitive insertion
                        switch (ProPtRes.Status)
                        {
                        case PromptStatus.OK:
                            //Create Grating
                            using (Transaction trans = db.TransactionManager.StartTransaction())
                            {
                                try
                                {
                                    //Set Position
                                    blockRef.Position = ProPtRes.Value;
                                    //We need clone the block reference to obtain a block wiht other objectID in each iteration
                                    BlockReference blockRefClone = blockRef.Clone() as BlockReference;
                                    //Get block table records
                                    BlockTableRecord currSpace = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                                    //Insert Block
                                    currSpace.AppendEntity(blockRefClone);
                                    trans.AddNewlyCreatedDBObject(blockRefClone, true);
                                    trans.Commit();
                                }
                                catch (System.Exception ex)
                                {
                                    trans.Abort();
                                }
                            }
                            break;

                        case PromptStatus.Cancel:
                            //Command Canceled
                            break;
                        }

                        //Save the name of inserted block
                        _sLastBlock = ProNameRes.StringResult;

                        //Go out of Loop
                        break;
                    }
                    else
                    {
                        ed.WriteMessage("\nNot foud any block with name \"" + ProNameRes.StringResult + "\".");
                    }
                }
            }while(true);
        }
        //Block Insertor
        static public void InsestBlock(BlockModel objBlockModel)
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;

            //InsertionState
            BlockInsetions insState = BlockInsetions.Insert;

            //Variables
            Point3d p3dInsetion     = new Point3d();
            Point3d p3dMatrixCorner = new Point3d();


            //Get objId
            ObjectId objId = ArCaRefMgrController.GetBlockId(objBlockModel);
            //Create BlockReference
            BlockReference blockRef = new BlockReference(new Point3d(), objId);
            //Get BlockPropertyModel
            BlockPropModel objBloPro = objBlockModel.LstBlockProp[0];

            //Set properties in BlockRefernce
            blockRef.Rotation     = ArCaUtils.DegreeToRadian(objBloPro.Angle);
            blockRef.ScaleFactors = new Scale3d(objBloPro.SclX, objBloPro.SclY, objBloPro.SclZ);

            //Mirror Settings
            bool bTop  = true;
            bool bLeft = true;

            //Strategy for Preview in PointMonitor
            _PointMonitorStrategy = new PointMonitorStrategy(delegate(object sender, PointMonitorEventArgs e)
            {
                try
                {
                    switch (insState)
                    {
                    case BlockInsetions.Insert:
                        blockRef.Position = e.Context.ComputedPoint;
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Rotate:
                        blockRef.Rotation = Vector3d.XAxis.GetAngleTo(p3dInsetion.GetVectorTo(e.Context.ComputedPoint), Vector3d.ZAxis);
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Scale:
                        blockRef.ScaleFactors = new Scale3d(p3dInsetion.DistanceTo(e.Context.ComputedPoint));
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Mirror:

                        if (e.Context.ComputedPoint.X < p3dInsetion.X && bLeft)
                        {
                            blockRef.ScaleFactors = new Scale3d(-(blockRef.ScaleFactors.X), blockRef.ScaleFactors.Y, blockRef.ScaleFactors.Z);
                            bLeft = false;
                        }
                        else if (e.Context.ComputedPoint.X > p3dInsetion.X && !bLeft)
                        {
                            blockRef.ScaleFactors = new Scale3d(-(blockRef.ScaleFactors.X), blockRef.ScaleFactors.Y, blockRef.ScaleFactors.Z);
                            bLeft = true;
                        }
                        if (e.Context.ComputedPoint.Y < p3dInsetion.Y && bTop)
                        {
                            blockRef.ScaleFactors = new Scale3d(blockRef.ScaleFactors.X, -(blockRef.ScaleFactors.Y), blockRef.ScaleFactors.Z);
                            bTop = false;
                        }
                        else if (e.Context.ComputedPoint.Y > p3dInsetion.Y && !bTop)
                        {
                            blockRef.ScaleFactors = new Scale3d(blockRef.ScaleFactors.X, -(blockRef.ScaleFactors.Y), blockRef.ScaleFactors.Z);
                            bTop = true;
                        }
                        e.Context.DrawContext.Geometry.Draw(blockRef);
                        break;

                    case BlockInsetions.Matrix:
                        //Get pt array
                        Point3dCollection pt3DColl = Utils.ArCaUtils.GetPtArray(p3dInsetion, e.Context.ComputedPoint, objBloPro.MatrixHeight, objBloPro.MatrixWidth);
                        double iLimitator          = objBloPro.MatrixMaxQuant;
                        foreach (Point3d pt3D in pt3DColl)
                        {
                            //Insert Block
                            blockRef.Position = pt3D;
                            e.Context.DrawContext.Geometry.Draw(blockRef);
                            //Limitator to evoid chash in machine
                            iLimitator--;
                            if (iLimitator < 1)
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
                catch (System.Exception ex)
                {
                }
            });

            //add pointMonitor
            ed.PointMonitor += new PointMonitorEventHandler(PointMonitor);

            //Looping for Insertion in Loop
            do
            {
                //***Insertion point***
                insState = BlockInsetions.Insert;

                PromptPointOptions opcPt = new PromptPointOptions("\nClick on the insertion point: ");
                opcPt.AllowNone = false;
                PromptPointResult ProPtRes = ed.GetPoint(opcPt);

                if (ProPtRes.Status != PromptStatus.OK)
                {
                    //Command Canceled
                    break;
                }

                p3dInsetion     = ProPtRes.Value;
                p3dMatrixCorner = ProPtRes.Value;

                //***ROTATE***
                if (objBloPro.Rotate)
                {
                    insState = BlockInsetions.Rotate;

                    PromptAngleOptions opcAng = new PromptAngleOptions("\nDefine the rotation angle: ");
                    opcAng.AllowNone    = true;
                    opcAng.UseBasePoint = true;
                    opcAng.BasePoint    = p3dInsetion;
                    opcAng.DefaultValue = 0;
                    PromptDoubleResult ProAngRes = ed.GetAngle(opcAng);

                    if (ProAngRes.Status == PromptStatus.Cancel)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***SCALE***
                if (objBloPro.Scale)
                {
                    insState = BlockInsetions.Scale;

                    PromptDistanceOptions opcScl = new PromptDistanceOptions("\nDefine the scale factor: ");
                    opcScl.AllowNone    = true;
                    opcScl.UseBasePoint = true;
                    opcScl.BasePoint    = p3dInsetion;
                    opcScl.DefaultValue = 1;
                    PromptDoubleResult ProSclRes = ed.GetDistance(opcScl);

                    if (ProSclRes.Status == PromptStatus.Cancel)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***MIRROR***
                if (objBloPro.Mirror)
                {
                    insState = BlockInsetions.Mirror;

                    PromptPointOptions opcMatCor = new PromptPointOptions("\nClick on the point that define the mirror direction: ");
                    opcMatCor.AllowNone    = false;
                    opcMatCor.UseBasePoint = true;
                    opcMatCor.BasePoint    = p3dInsetion;
                    PromptPointResult ProMatCorRes = ed.GetPoint(opcMatCor);

                    if (ProMatCorRes.Status != PromptStatus.OK)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }
                }

                //***MATRIX***
                if (objBloPro.Matrix)
                {
                    insState = BlockInsetions.Matrix;

                    PromptPointOptions opcMatCor = new PromptPointOptions("\nClick on the corner point of the matrix: ");
                    opcMatCor.AllowNone = false;
                    PromptPointResult ProMatCorRes = ed.GetPoint(opcMatCor);

                    if (ProMatCorRes.Status != PromptStatus.OK)
                    {
                        //Command Canceled, exit to "Loopin"
                        break;
                    }

                    p3dMatrixCorner = ProMatCorRes.Value;
                }

                //***Insertion of Block***
                //Get pt array
                Point3dCollection pt3DColl   = Utils.ArCaUtils.GetPtArray(p3dInsetion, p3dMatrixCorner, objBloPro.MatrixHeight, objBloPro.MatrixWidth);
                double            iLimitator = objBloPro.MatrixMaxQuant;
                foreach (Point3d pt3D in pt3DColl)
                {
                    //Set Position
                    blockRef.Position = pt3D;
                    //We need clone the block reference to obtain a block wiht other objectID in each iteration
                    BlockReference blockRefClone = blockRef.Clone() as BlockReference;
                    //Insert Block
                    Utils.ArCaUtils.InserBlock(db, objBloPro.Explode, blockRefClone);
                    //Limitator to evoid chash in machine
                    iLimitator--;
                    if (iLimitator < 1)
                    {
                        break;
                    }
                }
            } while (objBloPro.Loop);

            //remove pointMonitor
            ed.PointMonitor -= new PointMonitorEventHandler(PointMonitor);
        }
Ejemplo n.º 13
0
            public BlockReference GetRedirectBlockReferenceCopy(BlockReference br, Point3d directionPoint)
            {
                using (Transaction trans = Tools.StartTransaction())
                {
                    br = (BlockReference)br.Id.GetObject(OpenMode.ForRead, true, true);
                    double ang = 0d;
                    if (Mode == DirectionMode.Horizontal)
                    {
                        ang = br.BlockTransform.CoordinateSystem3d.Xaxis.GetAngleTo(br.Position.GetVectorTo(directionPoint));
                    }
                    else
                    {
                        ang = br.BlockTransform.CoordinateSystem3d.Yaxis.GetAngleTo(br.Position.GetVectorTo(directionPoint));
                    }

                    Polyline arrow = (Polyline)this.ArrowLine.Clone();
                    arrow.AddVertexAt(0, this.Origin);
                    arrow.AddVertexAt(4, new Point3d(
                                          arrow.EndPoint.X + arrow.GetFirstDerivative(0d).X *defSpaceLength,
                                          arrow.EndPoint.Y + arrow.GetFirstDerivative(0d).Y *defSpaceLength,
                                          arrow.EndPoint.Z));
                    arrow.TransformBy(br.BlockTransform);


                    if (Math.Abs(ang) > Math.PI / 2d)
                    {
                        Matrix3d mat;
                        if (this.Mode == DirectionMode.Horizontal)
                        {
                            Vector3d vector;
                            if (br.BlockTransform.CoordinateSystem3d.Xaxis.X >= 0)
                            {
                                vector = br.Position - arrow.EndPoint;
                            }
                            else
                            {
                                vector = arrow.EndPoint - br.Position;
                            }
                            mat = Matrix3d.Displacement(vector.MultiplyBy(br.BlockTransform.CoordinateSystem3d.Xaxis.X));
                            _transformBy(mat);
                        }
                        else
                        {
                            Vector3d vector;
                            if (br.BlockTransform.CoordinateSystem3d.Yaxis.Y >= 0)
                            {
                                vector = br.Position - arrow.EndPoint;
                            }
                            else
                            {
                                vector = arrow.EndPoint - br.Position;
                            }
                            mat = Matrix3d.Displacement(vector.MultiplyBy(br.BlockTransform.CoordinateSystem3d.Yaxis.Y));
                            _transformBy(mat);
                        }

                        return((BlockReference)br.Clone());
                    }
                    else
                    {
                        return(null);
                    }
                }
            }