Call an Autocad command with vba

Call an Autocad command with vba

StevGerrard
Contributor Contributor
1,215 Views
5 Replies
Message 1 of 6

Call an Autocad command with vba

StevGerrard
Contributor
Contributor

Bonjour,

 

Dans le cadre d'un projet, j'aimerai quelque peu automatiser une opération et ainsi éviter le plus possible l'action "manuelle". J'aimerai alors durant ma macro vba, faire appel à une commande autocad (EXTRACDONNEES en l'occurence)  sans avoir à l'écrire dans la barre de commande. Sauriez-vous le code correspondant ?

Merci pour votre aide ! 

 

Moderator translation:

Remarque, veuillez utiliser un traducteur pour poster en anglais. Note, please use a translator to post in English.

 

Hello

As part of a project, I would like to somewhat automate an operation and thus avoid as much as possible the "manual" action. I would then like during my vba macro, to use an autocad command (EXTRACDONNEES in this case) without having to write it in the command bar. Would you know the corresponding code?

Thank you for your help!

0 Likes
Accepted solutions (1)
1,216 Views
5 Replies
Replies (5)
Message 2 of 6

Ed__Jobe
Mentor
Mentor
Accepted solution

You would use the ThisDrawing.SendCommand method to send some text to the command line. Be aware that this method is asynchronous, meaning that the command will execute after all your VBA code has finished running. This may not work if you need the command to execute before the rest of your code runs. In VBA or .NET, if you need this to be synchronous, you need to create your own method that does what the native command does.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 6

StevGerrard
Contributor
Contributor
Understood ! Thank you for your answer !
0 Likes
Message 4 of 6

sanganaksakha
Advocate
Advocate

I think saying 'ThisDrawing.SendCommand method ...  is asynchronous, meaning that the command will execute after all your VBA code has finished running.' seems to be not correct.

 

Here is an example where the task in SendCmmand is completed before the last VBA command is executed

Open a fresh drawing and run the following code. The 'SendCommand' will generate a wipeout. The last VBA command displays the ObjectName of the wipeout. Thus the VBA statement executes after the SendCommand is completed. Thus 'SendCommand' is executed before all the VBA code is executed. 

Am I missing something?

 

Public Sub test()
    
    Dim pt1(0 To 2) As Double
    Dim pt2(0 To 2) As Double
    Dim pt3(0 To 2) As Double
    Dim pt4(0 To 2) As Double
    
    pt1(0) = 0: pt1(1) = 0: pt1(2) = 0
    pt2(0) = 10: pt2(1) = 0: pt2(2) = 0
    pt3(0) = 10: pt3(1) = 10: pt3(2) = 0
    pt4(0) = 0: pt4(1) = 10: pt4(2) = 0
    
    'This will not work, because those "pt" are not the correct format for SendCommand inputs
    AcadApplication.ActiveDocument.SendCommand "wipeout" & vbCr & pt1(0) & "," & pt1(1) & vbCr _
    & pt2(0) & "," & pt2(1) & vbCr & pt3(0) & "," & pt3(1) & vbCr & pt4(0) & "," & pt4(1) & vbCr _
    & vbCr
    
    'MsgBox "Done"
    
    MsgBox ThisDrawing.ModelSpace(0).ObjectName
    '''' Displays AcDbWipeout

End Sub

 

 

 

0 Likes
Message 5 of 6

Ed__Jobe
Mentor
Mentor

It appears that the behavior has changed and I didn't notice it. It's not totally synchronous though.

 


ActiveX Help wrote:

This method is generally synchronous. However, if the command sent with this method requires any user interaction (such as picking a point on the screen) then this method will continue as soon as the user input begins. The command will then continue to be processed asynchronously.

 

When this method is called from an event handler it is processed asynchronously.


 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 6

sharpl
Advocate
Advocate

I have sent you a private question about the method. My command is sitting on the command line and not executing without me hitting enter.

 

0 Likes