Beispiel #1
0
        private void CreateText(
            PSAutomation powerSHAPE,
            double height,
            string fontName,
            double pitch,
            TextOrigins textOrigin,
            TextJustifications textJustification,
            Point position,
            string text)
        {
            //Clear the list of CreatedItems
            _powerSHAPE.ActiveModel.ClearCreatedItems();

            //Set preferences to be able to introduce text by commands
            powerSHAPE.DoCommand("TOOLS PREFERENCES");
            powerSHAPE.DoCommand("UNITPREFS");
            powerSHAPE.DoCommand("TEXTPREFS");
            powerSHAPE.DoCommand("TEXT LIVETEXT OFF");
            powerSHAPE.DoCommand("ACCEPT");

            //Create the text
            powerSHAPE.SetActivePlane(Planes.XY);
            powerSHAPE.DoCommand("CREATE TEXT TEXT HORIZONTAL YES");
            powerSHAPE.DoCommand(string.Format("TEXT HEIGHT {0}", height));
            powerSHAPE.DoCommand(string.Format("TEXT FONT {0}", fontName));
            powerSHAPE.DoCommand(string.Format("TEXT PITCH {0}", pitch));
            powerSHAPE.DoCommand(string.Format("TEXT ORIGIN {0}", ConvertToString(textOrigin)));
            powerSHAPE.DoCommand(string.Format("TEXT JUSTIFICATION {0}", ConvertToString(textJustification)));
            powerSHAPE.DoCommand(string.Format("{0} {1} {2}", position.X, position.Y, position.Z));
            powerSHAPE.DoCommand(string.Format("ScrolledText {0}", text));
            powerSHAPE.DoCommand("ACCEPT");
        }
        /// <summary>
        /// Mirrors entities about the specifed plane.
        /// </summary>
        /// <param name="entitiesToMirror">The entities that are to be mirrored.</param>
        /// <param name="mirrorPlane">The plane about which to mirror the entities.</param>
        /// <param name="mirrorPoint">The origin of the mirror plane.</param>
        public static void MirrorEntities(
            List <IPSMirrorable> entitiesToMirror,
            Planes mirrorPlane,
            Geometry.Point mirrorPoint)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = ((PSEntity)entitiesToMirror[0]).PowerSHAPE;

            // Carry out operation
            // Create a temporary workplane (store the current workplane, to restore after mirror)
            PSWorkplane activeWP = _powerSHAPE.ActiveModel.ActiveWorkplane;

            _powerSHAPE.SetActivePlane(Planes.XY);

            // Ensures that the orientation of tempWP matches activeWP
            _powerSHAPE.ActiveModel.CreateTemporaryWorkplane(mirrorPoint);

            // Add all IPSMirrorables to selection
            ((PSEntity)entitiesToMirror[0]).AddToSelection(true);
            int numberOfEntities = entitiesToMirror.Count();

            for (int i = 0; i <= numberOfEntities - 1; i++)
            {
                ((PSEntity)entitiesToMirror[i]).AddToSelection(false);
            }

            // Clear updated items
            _powerSHAPE.ActiveModel.ClearUpdatedItems();

            // Mirror in this temporary workplane
            _powerSHAPE.DoCommand("EDIT MIRROR");
            _powerSHAPE.DoCommand("NOKEEP");

            _powerSHAPE.DoCommand(mirrorPlane.ToString());

            // This command is needed only for build 11 upward
            if (_powerSHAPE.Version >= new Version("11.2"))
            {
                _powerSHAPE.DoCommand("APPLY");
            }
            _powerSHAPE.DoCommand("CANCEL");

            int numberOfNonSolids = 0;

            for (int i = 0; i <= numberOfEntities - 1; i++)
            {
                if (!(entitiesToMirror[i] is PSSolid))
                {
                    numberOfNonSolids += 1;
                }
            }

            // Check that entities were mirrored, but only if non-solids were passed in, as powershape does not add altered solids to the updated set
            if (numberOfNonSolids > 0)
            {
                if (_powerSHAPE.ActiveModel.UpdatedItems.Count == 0)
                {
                    throw new ApplicationException("No entities were mirrored");
                }
                if (_powerSHAPE.ActiveModel.UpdatedItems.Count != numberOfNonSolids)
                {
                    throw new ApplicationException("Not all entities were mirrored");
                }
            }

            // Delete the temporary workplane that was created for the operation
            _powerSHAPE.ActiveModel.DeleteTemporaryWorkplane();

            // Restore the active workplane
            _powerSHAPE.ActiveModel.ActiveWorkplane = activeWP;
        }
        /// <summary>
        /// Rotates a group of entities by a specified angle around a specified axis.
        /// </summary>
        /// <param name="entitiesToRotate">The group of entities that are to be rotated.</param>
        /// <param name="rotationAxis">The axis around which the entities are to be rotated.</param>
        /// <param name="rotationAngle">The angle by which the entities are to be rotated.</param>
        /// <param name="copiesToCreate">The number of copies to create of the original entities.</param>
        /// <param name="rotationOrigin">The origin of the rotation axis.</param>
        /// <returns>A list of entities created by the operation.  If numberOfCopies is 0, an .empty list is returned.</returns>
        public static List <PSEntity> RotateEntities(
            List <IPSRotateable> entitiesToRotate,
            Axes rotationAxis,
            DG.Degree rotationAngle,
            int copiesToCreate,
            DG.Point rotationOrigin = null)
        {
            // Get PowerSHAPE instance
            _powerSHAPE = ((PSEntity)entitiesToRotate.First()).PowerSHAPE;

            // Add all IRotatables
            ((PSEntity)entitiesToRotate.First()).AddToSelection(true);
            int numberOfEntities = entitiesToRotate.Count();

            for (int i = 1; i <= numberOfEntities - 1; i++)
            {
                ((PSEntity)entitiesToRotate[i]).AddToSelection(false);
            }

            // Carry out operation
            _powerSHAPE.DoCommand("EDIT ROTATE");

            // Determine whether a copy is to be created
            if (copiesToCreate == 0)
            {
                _powerSHAPE.DoCommand("NOKEEP");
            }
            else
            {
                _powerSHAPE.DoCommand("KEEP");
                _powerSHAPE.DoCommand("COPIES " + copiesToCreate);
            }

            // If a different rotation origin has been defined, set it within PowerSHAPE
            if (rotationOrigin != null)
            {
                _powerSHAPE.DoCommand("AXIS");
                _powerSHAPE.DoCommand(rotationOrigin.ToString());
            }

            // Set the active plane, which determines the axis of rotation
            _powerSHAPE.SetActivePlane(rotationAxis.AxisToPlane());

            // Enter rotation angle
            _powerSHAPE.DoCommand("ANGLE " + rotationAngle);
            if (_powerSHAPE.Version >= new Version("11.2"))
            {
                _powerSHAPE.DoCommand("APPLY", "DISMISS");
            }
            else
            {
                _powerSHAPE.DoCommand("CANCEL");
            }

            // If no copies were made, return an empty list
            if (copiesToCreate == 0)
            {
                return(new List <PSEntity>());
            }

            // If copies were made, add them to their appropriate collections and return new entities
            List <PSEntity> copiedEntities = new List <PSEntity>();

            foreach (PSEntity copiedEntity in _powerSHAPE.ActiveModel.CreatedItems)
            {
                _powerSHAPE.ActiveModel.Add(copiedEntity);
                copiedEntities.Add(copiedEntity);
            }

            return(copiedEntities);
        }