http://www.theswamp.org/index.php?topic=31886.new#new
 - [System.Security.SuppressUnmanagedCodeSecurity]
- [DllImport("acad.exe", EntryPoint = "acedCmd",
- CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
- extern static private int acedCmd(IntPtr resbuf);
- /// <summary>
- /// Call an AutoCAD command (works synchronously).
- /// </summary>
- /// <param name="args">A ResultBuffer containing the command name followed by command inputs.</param>
- public static void Command(ResultBuffer args)
- {
- acedCmd(args.UnmanagedObject);
- }
- /// <summary>
- /// Call 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);
- }
|