BIM World
A Professional BIM Learning Platform


Troubleshooting Font Issues in Revit Secondary Development

Setting text fonts in Revit’s secondary development is relatively straightforward thanks to the available APIs.

First, you need to obtain the system font name. Here’s a simple way to do that:

https://zhidao.baidu.com/question/69549353.html

Once you have the system font name, you can apply it in Revit’s API like this:

textNoteType.get_Parameter(BuiltInParameter.TEXT_FONT).Set("宋体");

This sets your text style to the Song typeface.

Next, let’s discuss some peculiar issues related to text rendering in Revit.

To start, Chinese characters are typically twice as wide as English letters, which is expected.

Revit Secondary Development - Font Issues

Now, the second issue concerns inconsistent text heights:

Revit Secondary Development - Font Issues

This example shows a 5mm Song typeface with a width factor of 0.7. Ignoring the 1:100 scale, the actual height and width exceed 5mm and 3.5mm respectively, which is unreasonable. How does this compare to font sizes in CAD or Word? Even more frustrating, different fonts have completely different width and height dimensions.

System.Windows.Forms.Control control = new System.Windows.Forms.Control();
System.Drawing.Graphics g = control.CreateGraphics();
System.Drawing.SizeF sizeFOrigin = g.MeasureString("宋", new System.Drawing.Font("宋体", 5));
System.Drawing.SizeF sizeF = g.MeasureString(titleTextSet.Font, new System.Drawing.Font(titleTextSet.Font, 5));
g.Dispose();
double r1 = 1.48 * (sizeF.Width / sizeFOrigin.Width); // width coefficient
double r2 = 1.8 * (sizeF.Height / sizeFOrigin.Height); // height coefficient

In practice, only one font needs to be measured accurately. Here, Song typeface is used. For a 5mm font, the actual font height measures about 9mm, which corresponds to a coefficient of 1.8. The width coefficient is 0.7, and the final width factor is multiplied by 1.48. For other fonts, the MeasureString method is used to calculate relative coefficients compared to the Song typeface, enabling precise control over text height and width.

Once the size is controlled, determining the font size becomes simpler. Since Revit does not explicitly define font sizes, you need to convert them manually. Below is a reference table for corresponding font sizes.

Note: The above code has not been professionally tested, so further refinement and testing are recommended.

http://www.360doc.com/content/18/0201/14/48110419_726936679.shtml

xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat
Like(0) 打赏
BIM WORLD » Troubleshooting Font Issues in Revit Secondary Development

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up