で、GetString メソッドですが、オンライン ヘルプにあったサンプルはこんな感じです。
< CommandMethod("GetStringFromUser") > _
Public Sub GetStringFromUser()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim pStrOpts As PromptStringOptions = New PromptStringOptions(vbLf & _
"Enter your name: ")
pStrOpts.AllowSpaces = True
Dim pStrRes As PromptResult = acDoc.Editor.GetString(pStrOpts)
Application.ShowAlertDialog("The name entered was: " & _
pStrRes.StringResult)
End Sub
これを実行すると、入力した文字がダイアログに表示されるのですが、それだけじゃおもしろくないので、入力した内容の MTEXT を作成するようにしてみました。
また、MTEXT の基点を GetPoint で取得するようにもしてみました。
<CommandMethod("ACVD_Blog", "_ACVD_CreateMtext", "ACVD_CreateMtext", CommandFlags.Modal)> _
Public Sub ACVD_CreateMtext()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = acDoc.Database
Dim ed As Editor = acDoc.Editor
Dim trans As Transaction = db.TransactionManager.StartTransaction
Try
Dim pStrOpts As PromptStringOptions = New PromptStringOptions(vbLf & "文字を入力: ")
pStrOpts.AllowSpaces = True
Dim pStrRes As PromptResult = ed.GetString(pStrOpts)
If pStrRes.Status <> PromptStatus.OK Then
Return
End If
Dim ppo As PromptPointOptions = New PromptPointOptions(vbLf & "基点を指定: ")
ppo.AllowNone = False
Dim pr As PromptPointResult = ed.GetPoint(ppo)
If pr.Status <> PromptStatus.OK Then
Return
End If
Dim blkTbl As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim br As BlockTableRecord = trans.GetObject(blkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim mt As MText = New MText()
mt.Location = pr.Value
mt.TextHeight = 5.0
mt.ColorIndex = 1
mt.Contents = pStrRes.StringResult
br.AppendEntity(mt)
trans.AddNewlyCreatedDBObject(mt, True)
trans.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Application.ShowAlertDialog(ex.ToString)
Finally
trans.Dispose()
End Try
End Sub
0 件のコメント:
コメントを投稿