Jump to content

Using SendCommand to pass a variable


Danny CADamarteri

Recommended Posts

I have a VBA macro that passes an argument to AutoCAD command line using the 'SendCommand' function as below;

 

ACAD.Visible = True

acadCmd = "-layout & d layout1"
ACAD.ActiveDocument.SendCommand acadCmd & vbCr

In this instance I can delete the layout tab 'layout1' however I would like to know if it is possible to pass a string variable as the argument.

 

I have an excel sheet with all the layout tab names that I want to delete, I then want to loop through this sheet and send the command to AutoCad to delete this tab, as below;

 

Sub delete_tabs()

On Error Resume Next
Dim acadCmd, match1name, match1 As String
Dim range1, total As Range
Dim I As Integer

If Err.Description > vbNullString Then
    Err.Clear
    Set ACAD = CreateObject("AutoCAD.Application")
End If

total = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row

For I = 2 To total
    
    Set ACAD = GetObject(, "AutoCAD.Application")
    ACAD.Visible = True
    match1 = Sheets(1).Range("C" & I).Value
    match1name = Sheets(1).Range("B" & I).Value
     
    
        If match1 < 1 Then
            acadCmd = (-layout & d, match1num)
            ACAD.ActiveDocument.SendCommand acadCmd & vbCr
            
        End If

Next I


End Sub

 

I cannot find any documentation on this SendCommand function, is it possible to do what I want?

 

Thanks in advance!

 

Danny

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...