Hi,
This is due to SendStringToExecute() asynchronous execution.
If you realy want to do this with NET (should be easier with LISP), you have to P/Invoke acedCmd which works synchronously.
Code:
// Replace acad.exe with accore.dll for AutoCAD 2013
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", EntryPoint = "acedCmd",
CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
extern static private int acedCmd(IntPtr resbuf);
/// Calls an AutoCAD command (works synchronously).
/// </summary>
/// <param name="args">The command name followed by command inputs.</param>
public static void Command(params object[] args)
{
ResultBuffer resbuf = new ResultBuffer();
foreach (object obj in args)
{
switch (obj.GetType().Name)
{
case "String":
resbuf.Add(new TypedValue((int)LispDataType.Text, obj)); break;
case "Int16":
resbuf.Add(new TypedValue((int)LispDataType.Int16, obj)); break;
case "Int32":
resbuf.Add(new TypedValue((int)LispDataType.Int32, obj)); break;
case "Double":
resbuf.Add(new TypedValue((int)LispDataType.Double, obj)); break;
case "Point2d":
resbuf.Add(new TypedValue((int)LispDataType.Point2d, obj)); break;
case "Point3d":
resbuf.Add(new TypedValue((int)LispDataType.Point3d, obj)); break;
case "ObjectId":
resbuf.Add(new TypedValue((int)LispDataType.ObjectId, obj)); break;
case "ObjectId[]":
foreach (ObjectId id in (ObjectId[])obj)
resbuf.Add(new TypedValue((int)LispDataType.ObjectId, id));
break;
case "ObjectIdCollection":
foreach (ObjectId id in (ObjectIdCollection)obj)
resbuf.Add(new TypedValue((int)LispDataType.ObjectId, id));
break;
case "SelectionSetDelayMarshalled":
case "SelectionSetFullyMarshalled":
resbuf.Add(new TypedValue((int)LispDataType.SelectionSet, obj)); break;
default:
throw new InvalidOperationException("Unsupported type in Command() method");
}
}
acedCmd(resbuf.UnmanagedObject);
Then call:
Code:
Application.SetSystemVariable("FILEDIA", 0);
Command("._script", "c:\\UserScript.scr");
Application.SetSystemVariable("FILEDIA", 1);