C# - MicroStation Addin Font Style

Hello,

I'm trying to use font style upon creating a text node element however,  I encounterd an error which is No overload for method 'Find' takes '2' arguments.

Code snippet: app.ActiveSettings.TextStyle.Font = app.ActiveDesignFile.Fonts.Find(MsdFontType.WindowsTrueType, "Arial");

Do you have any idea for this one on how to set font style?

Best Regards,

Aldrin 

  • Fonts.Find method requires 3 arguments, Font = object.Find (Type, NamePattern [, PreviouslyFoundFont]), because C# version you use does not support optional arguments.
    Use:  app.ActiveDesignFile.Fonts.Find(MsdFontType.WindowsTrueType, "Arial", null);

    HTH

  • Hello sir Dan,

    I'll try this one later.

    Best Regards,

    Aldrin

  • Hello sir Dan,

    I tried this one but the font style of the text node I created did not changed. Below code snippet is using ActiveSettings from the source I get.

    Font savedFont = app.ActiveSettings.TextStyle.Font;

    app.ActiveSettings.TextStyle.Font = app.ActiveDesignFile.Fonts.Find(MsdFontType.WindowsTrueType, "Arial");

    app.ActiveSettings.TextStyle.Font = savedFont;

    Will  ActiveDesingFile do like this or is there any other way?

    Best Regards,

    Aldrin

  • I know what is your problem (thanks to subsequent post), active font must me set BEFORE you create an element.

        public static void TextAndTextNode(string unparsed)
        {
          Application app = Utilities.ComApp;

          Point3d origin = app.Point3dFromXYZ(583850, 639765, 9000);
          Matrix3d rMatrix = app.Matrix3dIdentity();

          Font saved_font = app.ActiveSettings.TextStyle.Font;
          double saved_height = app.ActiveSettings.TextStyle.Height;
          double saved_width = app.ActiveSettings.TextStyle.Width;

          app.ActiveSettings.TextStyle.Font = app.ActiveDesignFile.Fonts.Find(MsdFontType.WindowsTrueType, "Arial", null);
          app.ActiveSettings.TextStyle.Height = 83;
          app.ActiveSettings.TextStyle.Width = 70;

          TextNodeElement oTN = app.CreateTextNodeElement1(null, ref origin, ref rMatrix);
     
          oTN.AddTextLine("Text Node Line 1");
          oTN.AddTextLine("Text Node Line 2");
          oTN.AddTextLine("Text Node Line 3");
          oTN.Color = 1;

          app.ActiveSettings.TextStyle.Font = saved_font;
          app.ActiveSettings.TextStyle.Height = saved_height;
          app.ActiveSettings.TextStyle.Width = saved_width;

          app.ActiveModelReference.AddElement(oTN);
        }

    Answer Verified By: Aldrin Almia 

  • Hello sir Dan,

    Thanks a lot. It works.

    Best Regards,

    Aldrin