字体形文件问题
如何获取当前图形中所有字体的形支持文件及其路径?先谢了! 注意字体文件必须在Fonts字体目录下。而字体文件在文字样式中可得到。 想实现此功能的本意是这样的,有时候经常拷图给别人,但别人可能没有此图相应的字体形支持文件,打开图形时会出现乱码或者是字位置不对,如果通过程序查找当前图形中所有字体的形支持文件及其路径,然后将所有字体的形支持文件及图形一起拷给别人就很方便了。当然这种功能通过手动在CAD的支持目录里查找是可以实现的,但假如图形中的形支持文件较多时就非常不方便了。 实现该功能的程序已写完,现将代码上传,欢迎大家试用并批评指正。
Sub getfontfilepath()<BR> <BR> '返回图形支持文件目录<BR> Dim supportfilepath As String<BR> Dim supportfilepaths() As String<BR> Dim i, j, m, n As Integer<BR> <BR> supportfilepath = ThisDrawing.Application.preferences.Files.supportpath<BR> Do<BR> j = InStr(i + 1, supportfilepath, ";")<BR> If j = 0 Then<BR> n = Len(supportfilepath)<BR> ReDim Preserve supportfilepaths(m)<BR> supportfilepaths(m) = Right(supportfilepath, n - i)<BR> Exit Do<BR> Else<BR> ReDim Preserve supportfilepaths(m)<BR> supportfilepaths(m) = Mid(supportfilepath, i + 1, j - i - 1)<BR> i = j<BR> m = m + 1<BR> End If<BR> Loop<BR> <BR> Dim element As AcadTextStyle<BR> Dim fontfilepath As String<BR> Dim fontfile As String<BR> Dim fontfiles() As String<BR> Dim bigfontfilepath As String<BR> Dim bigfontfile As String<BR> Dim bigfontfiles() As String<BR> Dim k, l As Integer<BR> '返回图形fontfile字体支持文件目录<BR> n = 0<BR> For Each element In ThisDrawing.TextStyles<BR> fontfile = element.fontfile<BR> For i = 0 To m<BR> fontfilepath = supportfilepaths(i) + "\" + fontfile<BR> fontfilepath = Dir(fontfilepath)<BR> If fontfilepath <> "" Then<BR> If k = 0 Then<BR> ReDim Preserve fontfiles(k)<BR> fontfiles(k) = supportfilepaths(i) + "\" + fontfile<BR> k = k + 1<BR> Else<BR> ReDim Preserve fontfiles(k)<BR> fontfiles(k) = supportfilepaths(i) + "\" + fontfile<BR> For j = 0 To k - 1<BR> If LCase(fontfiles(k)) = LCase(fontfiles(j)) Then<BR> n = n + 1<BR> End If<BR> Next j<BR> If n = 0 Then<BR> k = k + 1<BR> Else<BR> n = 0<BR> End If<BR> End If<BR> Exit For<BR> End If<BR> Next i<BR> Next<BR> '返回图形bigfontfile字体支持文件目录<BR> For Each element In ThisDrawing.TextStyles<BR> bigfontfile = element.bigfontfile<BR> For i = 0 To m<BR> bigfontfilepath = supportfilepaths(i) + "\" + bigfontfile<BR> bigfontfilepath = Dir(bigfontfilepath)<BR> If bigfontfilepath <> "" Then<BR> If l = 0 Then<BR> ReDim Preserve bigfontfiles(k)<BR> bigfontfiles(k) = supportfilepaths(i) + "\" + bigfontfile<BR> l = l + 1<BR> Else<BR> ReDim Preserve bigfontfiles(l)<BR> bigfontfiles(l) = supportfilepaths(i) + "\" + bigfontfile<BR> For j = 0 To l - 1<BR> If LCase(bigfontfiles(l)) = LCase(bigfontfiles(j)) Then<BR> n = n + 1<BR> End If<BR> Next j<BR> If n = 0 Then<BR> l = l + 1<BR> Else<BR> n = 0<BR> End If<BR> End If<BR> Exit For<BR> End If<BR> Next i<BR> Next<BR> '显示图形中fontfile和bigfontfile字体支持文件目录<BR> ThisDrawing.Utility.Prompt vbCrLf & "fontfile字体支持文件:" & vbCrLf<BR> For i = 0 To k - 1<BR> ThisDrawing.Utility.Prompt fontfiles(i) & vbCrLf<BR> Next i<BR> ThisDrawing.Utility.Prompt "bigfontfile字体支持文件:"<BR> For i = 0 To l - 1<BR> ThisDrawing.Utility.Prompt bigfontfiles(i) & vbCrLf<BR> Next i<BR> <BR>End Sub<BR> 不错的东西,不过还没来得及运行 新增功能:将字体支持文件拷贝至指定文件夹。
Option Explicit<BR>Function getfontfile(fontfilepath As String) As String<BR> <BR> '返回图形fontfile字体支持文件目录下的字体支持文件<BR> Dim fontfilepaths() As String<BR> Dim i, j, m, n As Integer<BR> Do<BR> j = InStr(i + 1, fontfilepath, "\")<BR> If j = 0 Then<BR> n = Len(fontfilepath)<BR> getfontfile = Right(fontfilepath, n - i)<BR> Exit Do<BR> Else<BR> ReDim Preserve fontfilepaths(m)<BR> fontfilepaths(m) = Mid(fontfilepath, i + 1, j - i - 1)<BR> i = j<BR> m = m + 1<BR> End If<BR> Loop<BR> <BR>End Function<BR>Sub getfontfilepath()<BR> <BR> Dim supportfilepath As String<BR> Dim supportfilepaths() As String<BR> Dim i, j, m, n As Integer<BR> '返回图形支持文件目录<BR> supportfilepath = ThisDrawing.Application.preferences.Files.supportpath<BR> Do<BR> j = InStr(i + 1, supportfilepath, ";")<BR> If j = 0 Then<BR> n = Len(supportfilepath)<BR> ReDim Preserve supportfilepaths(m)<BR> supportfilepaths(m) = Right(supportfilepath, n - i)<BR> Exit Do<BR> Else<BR> ReDim Preserve supportfilepaths(m)<BR> supportfilepaths(m) = Mid(supportfilepath, i + 1, j - i - 1)<BR> i = j<BR> m = m + 1<BR> End If<BR> Loop<BR> <BR> Dim element As AcadTextStyle<BR> Dim fontfilepath As String<BR> Dim fontfile As String<BR> Dim fontfiles() As String<BR> Dim bigfontfilepath As String<BR> Dim bigfontfile As String<BR> Dim bigfontfiles() As String<BR> Dim k, l As Integer<BR> '返回图形fontfile字体支持文件目录<BR> n = 0<BR> For Each element In ThisDrawing.TextStyles<BR> fontfile = element.fontfile<BR> For i = 0 To m<BR> fontfilepath = supportfilepaths(i) + "\" + fontfile<BR> fontfilepath = Dir(fontfilepath)<BR> If fontfilepath <> "" Then<BR> If k = 0 Then<BR> ReDim Preserve fontfiles(k)<BR> fontfiles(k) = supportfilepaths(i) + "\" + fontfile<BR> k = k + 1<BR> Else<BR> ReDim Preserve fontfiles(k)<BR> fontfiles(k) = supportfilepaths(i) + "\" + fontfile<BR> For j = 0 To k - 1<BR> If LCase(fontfiles(k)) = LCase(fontfiles(j)) Then<BR> n = n + 1<BR> End If<BR> Next j<BR> If n = 0 Then<BR> k = k + 1<BR> Else<BR> n = 0<BR> End If<BR> End If<BR> Exit For<BR> End If<BR> Next i<BR> Next<BR> '返回图形bigfontfile字体支持文件目录<BR> For Each element In ThisDrawing.TextStyles<BR> bigfontfile = element.bigfontfile<BR> If bigfontfile <> "" Then<BR> For i = 0 To m<BR> bigfontfilepath = supportfilepaths(i) + "\" + bigfontfile<BR> bigfontfilepath = Dir(bigfontfilepath)<BR> If bigfontfilepath <> "" Then<BR> If l = 0 Then<BR> ReDim Preserve bigfontfiles(k)<BR> bigfontfiles(k) = supportfilepaths(i) + "\" + bigfontfile<BR> l = l + 1<BR> Else<BR> ReDim Preserve bigfontfiles(l)<BR> bigfontfiles(l) = supportfilepaths(i) + "\" + bigfontfile<BR> For j = 0 To l - 1<BR> If LCase(bigfontfiles(l)) = LCase(bigfontfiles(j)) Then<BR> n = n + 1<BR> End If<BR> Next j<BR> If n = 0 Then<BR> l = l + 1<BR> Else<BR> n = 0<BR> End If<BR> End If<BR> Exit For<BR> End If<BR> Next i<BR> End If<BR> Next<BR> '显示图形中fontfile和bigfontfile字体支持文件目录<BR> ThisDrawing.Utility.Prompt vbCrLf & "fontfile字体支持文件:" & vbCrLf<BR> For i = 0 To k - 1<BR> ThisDrawing.Utility.Prompt fontfiles(i) & vbCrLf<BR> Next i<BR> ThisDrawing.Utility.Prompt "bigfontfile字体支持文件:"<BR> For i = 0 To l - 1<BR> ThisDrawing.Utility.Prompt bigfontfiles(i) & vbCrLf<BR> Next i<BR> <BR> '选择是否将字体支持文件拷贝至指定文件夹<BR> Dim kwordList As String<BR> Dim destpath, destpath0 As String<BR> On Error Resume Next<BR> kwordList = "Yes No"<BR> ThisDrawing.Utility.InitializeUserInput 1, kwordList<BR> Dim returnString As String<BR> returnString = ThisDrawing.Utility.GetKeyword("是否将字体支持文件拷贝至指定文件夹:")<BR> If returnString = "Yes" Then<BR> destpath = InputBox("请输入目标文件夹!", "字体文件", ThisDrawing.Path)<BR> destpath0 = destpath<BR> destpath = Dir(destpath, vbDirectory)<BR> If destpath <> "" Then<BR> For i = 0 To k - 1<BR> FileCopy fontfiles(i), destpath0 & "\" & getfontfile(fontfiles(i))<BR> Next i<BR> For i = 0 To l - 1<BR> FileCopy bigfontfiles(i), destpath0 & "\" & getfontfile(bigfontfiles(i))<BR> Next i<BR> ThisDrawing.Utility.Prompt vbCrLf & "图形字体支持文件已拷贝至指定文件夹" & vbCrLf<BR> Else<BR> MsgBox "请输入正确的目标文件夹!"<BR> Exit Sub<BR> End If<BR> Else<BR> Exit Sub<BR> End If<BR> <BR>End Sub
页:
[1]