https://www.mcadtools.net/show.asp?id=256作者: leexianfeng 时间: 2009-11-11 20:50
根本不用那么麻烦,直接在api帮助里找到 increase width of text 实例教程下的代码,然后在SolidWorks中新建一个宏,然后把代码贴进去,就OK了。方便的话自己建个按钮,并指定宏。其中字体的长宽比可自己修改宏代码中的值。具体代码如下:
使用时选中要修改的字体,然后运行宏即可。
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.modelDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swAnnObj As Object
Dim swAnnotation As SldWorks.Annotation
Dim swTextFormat As SldWorks.textFormat
Dim dWidth As Double
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swAnnObj = swSelMgr.GetSelectedObject5(1)
Set swAnnotation = swAnnObj.GetAnnotation
Set swTextFormat = swAnnotation.GetTextFormat(0)
dWidth = swTextFormat.WidthFactor
Debug.Print "Old width = " & dWidth
swTextFormat.WidthFactor = 2# * dWidth
bRet = swAnnotation.SetTextFormat(0, False, swTextFormat)
dWidth = swTextFormat.WidthFactor
Debug.Print "New width = " & dWidth
End Sub