長々ですみませんが 下記{ブロックエディタ もどき」をAutoCAD2023で使用出来るよう変更出来ませんでしょうか。
'ブロックエディタ もどき
Dim Acad
'このステートメントは必ずCreateObjectよりも
'前の位置に挿入する。
'========== ***** ↓↓↓↓↓ ***** ==========
If MustRun Then WScript.Quit '二重起動しているか?
'========== ***** ↑↑↑↑↑ ***** ==========
'Set Acad = CreateObject("AcadRemocon.Body")
'以下何らかの処理をするコード
Dim Cnt, Arr, LayoutName, Clayer, retHist
Dim i, j, Ctab, SPB, SPS, SPM, CVP
Dim ShowPrintBorder, ShowPlotSetup, ShowPaperMargins, CreateViewports
Call Main
Sub Main()
'AcadRemocon作成
Set Acad = CreateObject("AcadRemocon.Body")
'AutoCAD実行中のコマンドを終了させる
If Not Acad.acEscapeCommand() Then Er: Exit Sub
'バージョンチェック
If Not Acad.CheckVersion("314") Then Exit Sub
'ブロック選択
If Not Acad.acSendCommand("^C^Cundo be ") Then Er: Exit Sub
If Not Acad.acSelect("ブロックを選択", Cnt, "SGL", retCancel) Then Acad.acPostCommand "undo e u ": Er: Exit Sub
If Cnt = 0 Then Acad.acPostCommand "undo e u ": Exit Sub
If Not Acad.acDxfOut(, "PREV", , , "2000") Then Er: Exit Sub
If Not Acad.DxfExtract(Cnt, Arr, "ENTITIES", "", "ATTRIB", "8") Then Er: Exit Sub
If Cnt > 0 Then Acad.acPostCommand "undo e u ": Acad.acShowMessage "現在、属性付のブロックには対応していません。" & vbCrLf & "ごめんなさいm(__)m", , "BlockEditor": Exit Sub
If Not Acad.DxfExtract(Cnt, Arr, "ENTITIES", "", "INSERT", "2|8") Then Er: Exit Sub
If Cnt = 0 Then Acad.acPostCommand "undo e u ": Acad.acShowMessage "これはブロックじゃない!", , "BlockEditor": Exit Sub
If Not Acad.acGetVar("Ctab", Ctab) Then Er: Exit Sub
If Not Acad.acGetVar("Clayer", Clayer) Then Er: Exit Sub
If Not Acad.acPostCommand("setenv^MShowPrintBorder^M0^M") Then Er: Exit Sub
SPB = GetDefValue()
If Not Acad.acPostCommand("setenv^MShowPlotSetup^M0^M") Then Er: Exit Sub
SPS = GetDefValue()
If Not Acad.acPostCommand("setenv^MShowPaperMargins^M0^M") Then Er: Exit Sub
SPM = GetDefValue()
If Not Acad.acPostCommand("setenv^MCreateViewports^M0^M") Then Er: Exit Sub
CVP = GetDefValue()
If Not Acad.acSetVar("Clayer", Arr(2, 1)) Then Er: Exit Sub
LayoutName = "BlockEditor(" & Arr(1, 1) & ")^M"
If Not Acad.acPostCommand("-layout d " & LayoutName) Then Er: Exit Sub
If Not Acad.acPostCommand("-layout n " & LayoutName) Then Er: Exit Sub
If Not Acad.acPostCommand("CTAB " & LayoutName) Then Er: Exit Sub
If Not Acad.acPostCommand("^C^C-insert^M*" & Arr(1, 1) & "^M0,0^M1^M0^M^C^C^C") Then Er: Exit Sub
If Not Acad.acGetHistory(retHist, "-insert") Then Er: Exit Sub
If InStr(retHist, "XREF") > 0 Then Acad.acPostCommand "undo e u ": Modosu: Acad.acShowMessage "外部参照は処理できません。", , "BlockEditor": Exit Sub
If Not Acad.acPostCommand("^C^Czoom e ") Then Er: Exit Sub
'ダイアログ作成
CreateDialog
Acad.dlSetProperty "Label3", "Text", "[ " & Arr(1, 1) & " ]"
Acad.acActivate
'イベント監視ループ
Do
'イベント発生待ち(変化があるまでここで待ちます)
Acad.dlWaitEvent CtrlName, CtrlValue, CtrlListIndex
'イベント処理
Select Case DialogEvent(CtrlName, CtrlValue, CtrlListIndex)
Case vbOK: Exit Do
Case vbCancel: Acad.acPostCommand "undo e u ": Modosu: Exit Sub
End Select
Loop While True
'ダイアログアンロード
Acad.dlUnload
'ここで作図
If Not Acad.acPostCommand("^C^C-BLOCK " & Arr(1, 1) & "^MY non 0,0 ALL ") Then Er: Exit Sub
Modosu
' Acad.acShowMessage "作図が完了しました。"
'終了
End Sub
Sub Modosu()
If Not Acad.acPostCommand("-layout d " & LayoutName) Then Er: Exit Sub
If Not Acad.acSetVar("Clayer", Clayer) Then Er: Exit Sub
If Not Acad.acSetVar("Ctab", Ctab) Then Er: Exit Sub
If Not Acad.acPostCommand("setenv ShowPrintBorder^M" & SPB & " ") Then Er: Exit Sub
If Not Acad.acPostCommand("setenv ShowPlotSetup^M" & SPS & " ") Then Er: Exit Sub
If Not Acad.acPostCommand("setenv ShowPaperMargins^M" & SPM & " ") Then Er: Exit Sub
If Not Acad.acPostCommand("setenv CreateViewports^M" & CVP & " ") Then Er: Exit Sub
If Not Acad.acPostCommand("undo e ") Then Er: Exit Sub
End Sub
'エラー処理
Sub Er()
'ユーザーによるキャンセル
If Acad.ErrNumber = vbObjectError + 1000 Then
'ここにキャンセル時の処理を追加
Else
'エラー内容表示
Acad.ShowError
End If
End Sub
Function GetDefValue()
If Not Acad.acGetHistory(retHist, "値") Then Er: Exit Function
mae = InStr(retHist, "<")
ato = InStr(retHist, ">")
GetDefValue = Mid(retHist, mae + 1, ato - mae - 1)
End Function
'ダイアログイベント処理
Function DialogEvent(CtrlName, CtrlValue, CtrlListIndex)
'コントロール名で区別
Select Case CtrlName
Case "cmdOK": DialogEvent = vbOK: Exit Function
Case "cmdCancel": DialogEvent = vbCancel: Exit Function
Case "Button1": DialogEvent = vbOK: Exit Function
End Select
'再度イベント待ち
DialogEvent = vbRetry
End Function
'ダイアログ作成
Sub CreateDialog()
Acad.dlLoad "ブロックエディタ もどき", False, True
Acad.dlAddLabel "Label1", "編集後に↓ボタンを押す", 20, 1, 0
Acad.dlAddButton "Button1", "ブロック更新", 16, 1
Acad.dlAddLabel "Label2", "編集中のブロック名", 18, 1, 0
Acad.dlAddLabel "Label3", "", 20, 0, 0
Acad.dlShow 0, 0
End Sub
Public Function MustRun()
'実行している環境が64ビット環境か、32ビット環境か判断し、
'64ビット環境であれば、32ビット環境で自身の再起動を試みる。
'そして、Trueを返す。32ビット環境であれば、Falseを返す。
Const WSHOST = "wscript.exe"
Dim objWshShell 'WshShell オブジェクト
Dim ExecCmd '実行するコマンドライン
Set objWshShell = WScript.CreateObject("WScript.Shell")
If objWshShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") = "AMD64" Then
ExecCmd = objWshShell.ExpandEnvironmentStrings("%WINDIR%") & _
"\SysWOW64\" & WSHOST & " " & _
WScript.ScriptFullName
objWshShell.Exec(ExecCmd)
MustRun = True
Else 'x86
MustRun = False
End If
Set objWshShell = Nothing
Set ExecCmd = Nothing
End Function
ブロックエディタ もどきを修正出来ないでしょうか
- THIG
- 2026/05/11 (Mon) 10:41:38