Originally Posted by
estuyose791044
Hello Everyone
I want to get the texts that come after I activate the command "id". That says "Specify point: x=#### y=####"
how do I do it?
Here is the code.
Thanks
Public Sub tryer()
ThisDrawing.SendCommand "id" & vbCr
End Sub
To do this, you can use AutoCAD's COM API to interact with the command line and capture the text that is displayed there. Here's an example of how you can modify your code to achieve this:
Code:
Public Sub tryer()
Dim acadApp As Object
Dim acadDoc As Object
Dim cmdResult As String
' Get a reference to the AutoCAD application
On Error Resume Next
Set acadApp = GetObject(, "AutoCAD.Application")
On Error GoTo 0
' If AutoCAD is not running, start it
If acadApp Is Nothing Then
Shell "C:\Program Files\Autodesk\AutoCAD 2022\acad.exe", vbNormalFocus
' You may need to adjust the path to your AutoCAD executable
' and specify the correct AutoCAD version (e.g., AutoCAD 2022).
' Wait for AutoCAD to start (adjust the delay as needed)
Application.Wait (Now + TimeValue("00:00:05")) ' Wait for 5 seconds
Set acadApp = GetObject(, "AutoCAD.Application")
End If
' Get the active document
Set acadDoc = acadApp.ActiveDocument
' Send the "id" command
acadDoc.SendCommand "id" & vbCr
' Wait for a moment to allow AutoCAD to process the command
Application.Wait (Now + TimeValue("00:00:01")) ' Wait for 1 second
' Capture the text from the command line
cmdResult = acadApp.GetVariable("CmdLine")
' Display the result (you can modify this part as needed)
MsgBox "Command Line Result: " & cmdResult
' Release objects
Set acadDoc = Nothing
Set acadApp = Nothing
End Sub
This code first checks if AutoCAD is running, and if not, it starts it. It then sends the "id" command and waits for a moment to allow AutoCAD to process it. After that, it captures the text from the command line using the GetVariable method and displays it in a message box.
Please adjust the path to your AutoCAD executable and the delay times as needed to fit your specific setup and requirements.