private static void ReadBlock(XmlReader objReader, ref MainModel objMain, ref BlockModel objBlock) { if (!objReader.IsEmptyElement) { //set product properties while (objReader.Read()) { //if it's the end Element if (objReader.NodeType == XmlNodeType.EndElement && objReader.Name.Equals(CONST_S_NODE_BLOCK, StringComparison.CurrentCultureIgnoreCase)) { break; } if (objReader.Name.Equals(CONST_S_NODE_BLOCK_PROPERTY, StringComparison.CurrentCultureIgnoreCase)) { BlockPropModel objBlockProp = new BlockPropModel(objReader.GetAttribute(CONST_S_ATT_NAME)); //Insertions objBlockProp.Rotate = System.Convert.ToBoolean(objReader.GetAttribute(CONST_S_ATT_ROTATE)); objBlockProp.Angle = double.Parse(objReader.GetAttribute(CONST_S_ATT_ANGLE)); objBlockProp.Scale = System.Convert.ToBoolean(objReader.GetAttribute(CONST_S_ATT_SCALE)); objBlockProp.SclX = double.Parse(objReader.GetAttribute(CONST_S_ATT_SCLX)); objBlockProp.SclY = double.Parse(objReader.GetAttribute(CONST_S_ATT_SCLY)); objBlockProp.SclZ = double.Parse(objReader.GetAttribute(CONST_S_ATT_SCLZ)); objBlockProp.Mirror = System.Convert.ToBoolean(objReader.GetAttribute(CONST_S_ATT_MIRROR)); objBlockProp.Loop = System.Convert.ToBoolean(objReader.GetAttribute(CONST_S_ATT_LOOP)); objBlockProp.Explode = System.Convert.ToBoolean(objReader.GetAttribute(CONST_S_ATT_EXPLODE)); objBlockProp.Matrix = System.Convert.ToBoolean(objReader.GetAttribute(CONST_S_ATT_MATRIX)); objBlockProp.MatrixWidth = double.Parse(objReader.GetAttribute(CONST_S_ATT_MATRIXWIDTH)); objBlockProp.MatrixHeight = double.Parse(objReader.GetAttribute(CONST_S_ATT_MATRIXHEIGHT)); objBlockProp.MatrixMaxQuant = double.Parse(objReader.GetAttribute(CONST_S_ATT_MATRIXMAXQUANT)); //Add objBlock.LstBlockProp.Add(objBlockProp); } else { throw new Exception("Unexpected element: '" + objReader.Name + "'"); } } } }
//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); }