supermab.com   HOME > AutoCad VBA コード置き場 > P.2

目次へ HOMEへ 

AutoCad VBA コード置き場 P.2


【文字スタイル変更】 2010/01/14

文字スタイルを変更するコードです。フォントファイルの場所などコードを変更して利用します。

'-------------------------------------------
' 文字スタイル変更
'-------------------------------------------
Public Sub TextStyleChange()
Dim style As AcadTextStyle
With ThisDrawing
 For Each style In .TextStyles
  style.BigFontFile = "C:/AutoCAD/Fonts/extfont.shx" 'ビッグフォントに変更
 Next
 .Regen (acAllViewports) '再描画
End With
End Sub


【文字抽出&変更】 2010/01/14

文字の内容から条件を満たす文字を抽出し変更するコードです。
図面にちりばめられた文字データから条件を満たす文字列を一括して変更します。

'-------------------------------------------
' 文字抽出&変更
'-------------------------------------------
Public Sub ChTxt()
Dim trgTxt As String
Dim ent As AcadEntity
Dim i As Long
Dim s As String
With ThisDrawing
 For Each ent In .ModelSpace
   If ent.ObjectName = "AcDbText" Then
    trgTxt = ent.TextString
    If Left(trgTxt, 3) = "ABC" Then   'txtの左3文字が「ABC」なら
      i = Len(trgTxt)           'txtの長さを取得
      trgTxt = Right(trgTxt, i - 3)   '左3文字を消去
      ent.TextString = trgTxt      '代入
    End If
  End If
Next
End With

目次へ HOMEへ 

Copyright © 2008-2011 supermab.com
All rights reserved.