private string ConvertToString(TextOrigins textOrigin) { switch (textOrigin) { case TextOrigins.BottomCentre: return("BOTTOMCENTRE"); case TextOrigins.BottomLeft: return("BOTTOMLEFT"); case TextOrigins.BottomRight: return("BOTTOMRIGHT"); case TextOrigins.Centre: return("CENTRE"); case TextOrigins.LeftCentre: return("CENTRELEFT"); case TextOrigins.RightCentre: return("CENTRERIGHT"); case TextOrigins.TopCentre: return("TOPCENTRE"); case TextOrigins.TopLeft: return("TOPLEFT"); case TextOrigins.TopRight: return("TOPRIGHT"); default: throw new ArgumentOutOfRangeException("Argument outside the range of values supported."); } }
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> /// Creates a new annotation in PowwerSHAPE. /// </summary> /// <param name="text">The text to introduce in PowerShape.</param> /// <param name="fontName"> /// The font type for the text (e.g. Arial, Times New Roman). The font Type must exist in /// PowerShape. /// </param> /// <param name="height">The font height.</param> /// <param name="pitch">The distance between each character in a line.</param> /// <param name="textJustification"> /// The wanted justify option. This is how the text in the block aligns with the left and /// right margins. /// </param> /// <param name="textOrigin"> /// The origin of the text block. The origin is the 'anchor point' used to position the text and /// can be set at any of the four corners of the text box, the mid points of the sides of the text box or the centre of the /// text box. Use the option menu to change the origin of the text. /// </param> /// <param name="position">The position of the text in the active workplane.</param> /// <remarks></remarks> public PSAnnotation CreateAnnotation( string text, string fontName, double height, Point position, double pitch, TextJustifications textJustification, TextOrigins textOrigin) { PSAnnotation annotation = new PSAnnotation(_powerSHAPE, text, fontName, height, position, pitch, textJustification, textOrigin); Add(annotation); return(annotation); }
/// <summary> /// Creates a new annotation in PowwerSHAPE. /// </summary> /// <param name="powerSHAPE">The base instance to interact with PowerShape.</param> /// <param name="text">The text to introduce in PowerShape.</param> /// <param name="fontName"> /// The font type for the text (e.g. Arial, Times New Roman). The font Type must exist in /// PowerShape. /// </param> /// <param name="height">The font height.</param> /// <param name="pitch">The distance between each character in a line.</param> /// <param name="textJustification"> /// The wanted justify option. This is how the text in the block aligns with the left and /// right margins. /// </param> /// <param name="textOrigin"> /// The origin of the text block. The origin is the 'anchor point' used to position the text and /// can be set at any of the four corners of the text box, the mid points of the sides of the text box or the centre of the /// text box. Use the option menu to change the origin of the text. /// </param> /// <param name="position">The position of the text in the active workplane.</param> /// <remarks></remarks> internal PSAnnotation( PSAutomation powerSHAPE, string text, string fontName, double height, Point position, double pitch, TextJustifications textJustification, TextOrigins textOrigin) : base(powerSHAPE) { // Create text in PowerSHape CreateText(powerSHAPE, height, fontName, pitch, textOrigin, textJustification, position, text); //Now get its Id PSAnnotation annotation = (PSAnnotation)_powerSHAPE.ActiveModel.CreatedItems[0]; _id = annotation.Id; _name = annotation.Name; }