Calling AutoCAD Commands Programmatically

Calling AutoCAD Commands Programmatically

Anonymous
Not applicable
856 Views
3 Replies
Message 1 of 4

Calling AutoCAD Commands Programmatically

Anonymous
Not applicable

I have two short methods which are both meant to call AutoCAD's UNDO command and pass in different parameters. They are:

 

/// <summary>
/// Method to mark the current position of the AutoCAD program
/// </summary>
public static void MarkPosition()
{
doc.SendStringToExecute("_UNDO ", true, false, false);
doc.SendStringToExecute("_M ", true, false, false);
}

/// <summary>
/// Method to step AutoCAD back to the marked position
/// </summary>
public static void BigUndo()
{
doc.SendStringToExecute("_UNDO ", true, false, false);
doc.SendStringToExecute("_B ", true, false, false);
}

 

However, when I call them they do not run like I expect them to. I suspect that I am doing this completely wrong but do not know what the right approach is

0 Likes
857 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

I know you can't inject a command while another command in running. i.e. You can't inject the _M option until after the _UNDO command is finished.

I have seen where people have used a string builder and assemble them together but I have never been able to get it to work.

 

Or you could do what I did. I needed to insert Surface Texture Symbols, but was unable to inject the L (library) option so I had to recreate the entire functionality. (As an added benefit, this allowed the code to be repeatable - something the current Surface Texture object can not do (it defaults back to the default symbols))

 

Sorry I can't give a more direct answer, hopefully someone will see this and get some idea of what to look for.

 

0 Likes
Message 3 of 4

Anonymous
Not applicable
What do you mean 'they do not run as expected'?
Are they executed at the wrong time, are they lost altogether?
And what's the purpose? Executing an UNDO and se t a Mark or just set the mark?
Have you tried just to combine the commands like "_UNDO _M "? And eventually postpone the single UNDO action if you also need to actually undo something at the same time...
0 Likes
Message 4 of 4

Anonymous
Not applicable

I would recommend an awesome library called [AutoCAD Code Pack](https://github.com/luanshixia/AutoCADCodePack).

 

Using this library, you can save a lot of code you would write directly with AutoCAD .NET API. To run a command (say "re"), you just say

 

Interaction.Command("re");

0 Likes