作成理由
モデル空間、レイアウト空間(=ペーパー空間)の中にある複数あるテキストにgoogle検索のハイパーリンクを付与したい。
条件
- windows10
- AutoCAD2017
- Google検索APIのURLのハイパーリンクを付与
- 自分の環境では動きました。
VBAその1:モデル空間にハイパーリンク付与
Sub モデル空間のテキストに一括ハイパーリンク()
Dim acDoc As AcadDocument
Dim acEnt As AcadEntity
Dim setdata As String
For Each acDoc In Documents
For Each acEnt In acDoc.ModelSpace'->ModelSpace(=モデル空間)の中のCad要素(acEnt)を抽出
If (TypeOf acEnt Is AcadText) Or (TypeOf acEnt Is AcadMText) Then
acEnt.Hyperlinks.Add "https://www.google.com/search?q=" & acEnt.TextString, acEnt.TextString
End If
Next acEnt
Next acDoc
MsgBox "終了"
End Sub
VBAその2:複数レイアウトにハイパーリンク付与
Sub 複数レイアウトテキストにハイパーリンク()
Dim acDoc As AcadDocument
Dim acEnt As AcadEntity
Dim setdata As String
Dim i, num As Integer
num = ThisDrawing.Layouts.Count'->レイアウト数を変数numに格納する。
MsgBox num & "レイアウト数"
For i = 0 To num
ThisDrawing.ActiveLayout = ThisDrawing.Layouts.Item(i)
Debug.Print ThisDrawing.Layouts.Item(i).Name
For Each acDoc In Documents
For Each acEnt In acDoc.modelSpace
If (TypeOf acEnt Is AcadText) Or (TypeOf acEnt Is AcadMText) Then
acEnt.color = acRed'終わったらチェックの為、テキストに赤色にしてみる。
acEnt.Hyperlinks.Add "https://www.google.com/search?q=" & acEnt.TextString, acEnt.TextString
End If
End If
Next acEnt
Next acDoc
Next i
MsgBox "終了"
End Sub