sendcommand

sendcommand

Anonymous
Not applicable
3,891 Views
4 Replies
Message 1 of 5

sendcommand

Anonymous
Not applicable

hello,

am new at using vba to automate autocad drawings at my job.(topography)

my question here is about the rules of writing sendcommands, i have seen some examples of them but still cant see the logic behind the syntax.

example: .ThisDrawing.SendCommand "._-layer _m " & "TBlk" & vbCr & "_c 8 " & "TBlk" & vbCr & vbCr 

if someone can help me cover and understand the commands syntax at vba i will be gratefull.( vbCR, "_", "._" ...)

0 Likes
Accepted solutions (1)
3,892 Views
4 Replies
Replies (4)
Message 2 of 5

Ed__Jobe
Mentor
Mentor
Accepted solution

vbCr is the visual basic carriage return. It is equivalent to {Enter} key. It goes back to the old typewriter days. On a typewriter, a cr simply put the carriage back at the left, column 0. Or you could do a carriage return and a line feed at the same time. It put the carriage at column 0 and went to the next line down.  In vb it is vbCrLf. The other things you asked about are AutoCAD command macro characters. A space is equivalent to the user typing {Enter}. The period "." forces the command to use the standard command definition and not one that may have redefined the command. An underscore "_" forces the sequence to not use the localized version where the command options might vary.

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 5

Anonymous
Not applicable

thank you!

i will learn then about command macros.

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor

While @Ed__Jobe provided excellent explanation on string format to be used for SendCommand(), since you said you are new to VBA, I'd suggest to avoid to use SemdCommand() as much as possible in your VBA code. You should use the COM API to do things (i.e. to create your own command in VBA code, if existing built-in command does not fit your immediate need). For example, instead of calling SendCommand "_.-layer M ...." (creating a new layer), you should do

...

Set newLayer = ThisDrawing.Layers.Add("newLayerName")

...

Of course, before you adding new layer, you can have code to see if a layer with that name already exists...This is the power of writing VBA code with API, simple and easy and you have more control. 

 

Also, mixing SendCommand() in middle of other VBA code may have unexpected effect, especially if the execution of code following SendCommand() depending on the result of SendCommand().

 

If your goal is to create simple script based on existing commands, learning/using LISP would be better/easier way.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 5

Anonymous
Not applicable

thank you very much norman for ur advice and guidance!

0 Likes