示例#1
0
        /// <summary>
        ///     Method to get the rotation matrices of a solid, based on its Centroid
        /// </summary>
        /// <param name="acSol">The solid to be rotated</param>
        private void GetRotationMatrices(Solid3d acSol)
        {
            var center = acSol.GetBoxCenter();

            using (var brep = new Brep(acSol))
            {
                var centroid = brep.GetMassProperties().Centroid.RoundToTolerance();

                if (centroid != center)
                {
                    center = brep.GetMassProperties().Centroid;
                }
            }

            //Find the 90 degree rotation matrices
            X90 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(90), Vector3d.XAxis, center);
            Y90 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(90), Vector3d.YAxis, center);
            Z90 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(90), Vector3d.ZAxis, center);

            //Find the 180 degree rotation matrices
            X180 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(180), Vector3d.XAxis, center);
            Y180 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(180), Vector3d.YAxis, center);
            Z180 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(180), Vector3d.ZAxis, center);

            //Find the 180 degree rotation matrices
            X270 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(270), Vector3d.XAxis, center);
            Y270 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(270), Vector3d.YAxis, center);
            Z270 = Matrix3d.Rotation(CalcUnit.ConvertToRadians(270), Vector3d.ZAxis, center);
        }
示例#2
0
        public void Cmd_GenDims()
        {
            var acCurDoc = Application.DocumentManager.MdiActiveDocument;
            var acCurDb  = acCurDoc.Database;
            var acCurEd  = acCurDoc.Editor;

            var objIds = acCurEd.GetAllSelection(false);

            if (objIds.Length <= 0)
            {
                return;
            }

            using (var pWorker = new ProgressAgent("Generating Dimension: ", objIds.Length))
            {
                using (var acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    foreach (var obj in objIds)
                    {
                        if (!pWorker.Progress())
                        {
                            acTrans.Abort();
                            return;
                        }

                        var acEnt = acTrans.GetObject(obj, OpenMode.ForRead) as Entity;
                        if (acEnt == null)
                        {
                            continue;
                        }

                        var extents = acEnt.GeometricExtents;

                        var minPt = extents.MinPoint;
                        var maxPt = extents.MaxPoint;

                        // Create the rotated dimension
                        using (var acXDim = new RotatedDimension())
                        {
                            acXDim.XLine1Point    = new Point3d(minPt.X, minPt.Y, 0);
                            acXDim.XLine2Point    = new Point3d(maxPt.X, minPt.Y, 0);
                            acXDim.DimLinePoint   = new Point3d(minPt.X, minPt.Y - SettingsUser.AnnoSpacing, 0);
                            acXDim.DimensionStyle = acCurDb.Dimstyle;

                            // Add the new object to Model space and the transaction
                            acCurDb.AppendEntity(acXDim);
                        }

                        // Create the rotated dimension
                        using (var acYDim = new RotatedDimension())
                        {
                            acYDim.XLine1Point    = new Point3d(minPt.X, minPt.Y, 0);
                            acYDim.XLine2Point    = new Point3d(minPt.X, maxPt.Y, 0);
                            acYDim.Rotation       = CalcUnit.ConvertToRadians(90);
                            acYDim.DimLinePoint   = new Point3d(minPt.X - SettingsUser.AnnoSpacing, minPt.Y, 0);
                            acYDim.DimensionStyle = acCurDb.Dimstyle;

                            // Add the new object to Model space and the transaction
                            acCurDb.AppendEntity(acYDim);
                        }
                    }

                    acTrans.Commit();
                }
            }
        }