- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2014-7-11 18:30:09
|
显示全部楼层
本帖最后由 雪山飞狐_lzh 于 2014-7-11 18:35 编辑
下面是我的测试(用自己的封装,没有2015)
- #region Command
- private static void AddValueToResultBuffer(ref ResultBuffer rb, object obj)
- {
- if (obj == null)
- {
- rb.Add(new TypedValue((int)LispDataType.Text, ""));
- }
- else
- {
- if (obj is string)
- {
- rb.Add(new TypedValue((int)LispDataType.Text, obj));
- }
- else if (obj is Point2d)
- {
- rb.Add(new TypedValue((int)LispDataType.Text, "_non"));
- rb.Add(new TypedValue((int)LispDataType.Point2d, obj));
- }
- else if (obj is Point3d)
- {
- rb.Add(new TypedValue((int)LispDataType.Text, "_non"));
- rb.Add(new TypedValue((int)LispDataType.Point3d, obj));
- }
- else if (obj is ObjectId)
- {
- rb.Add(new TypedValue((int)LispDataType.ObjectId, obj));
- }
- else if (obj is SelectionSet)
- {
- rb.Add(new TypedValue((int)LispDataType.SelectionSet, obj));
- }
- else if (obj is double)
- {
- rb.Add(new TypedValue((int)LispDataType.Double, obj));
- }
- else if (obj is short)
- {
- rb.Add(new TypedValue((int)LispDataType.Int16, obj));
- }
- else if (obj is int)
- {
- rb.Add(new TypedValue((int)LispDataType.Int32, obj));
- }
- else if (obj is TypedValue)
- {
- rb.Add(obj);
- }
- }
- }
- [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
- private static extern int acedCmd(IntPtr vlist);
- /// <summary>
- /// 调用AutoCad命令
- /// </summary>
- /// <param name="endCommandByUser">命令结束方式</param>
- /// <param name="rb">参数</param>
- public static void Command(bool endCommandByUser, ResultBuffer rb)
- {
- ResultBuffer rbend = new ResultBuffer();
- try
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- string currCmdName = doc.CommandInProgress;
- acedCmd(rb.UnmanagedObject);
- if (endCommandByUser)
- {
- rbend.Add(new TypedValue((int)LispDataType.Text, "\\"));
- }
- while (doc.CommandInProgress != currCmdName)
- {
- acedCmd(rbend.UnmanagedObject);
- }
- }
- catch { }
- finally
- {
- rb.Dispose();
- rbend.Dispose();
- }
- }
- /// <summary>
- /// 调用AutoCad命令
- /// </summary>
- /// <param name="endCommandByUser">命令结束方式</param>
- /// <param name="args">参数</param>
- public static void Command(bool endCommandByUser, params object[] args)
- {
- ResultBuffer rb = new ResultBuffer();
- foreach (object val in args)
- {
- AddValueToResultBuffer(ref rb, val);
- }
- Command(endCommandByUser, rb);
- }
- #endregion
测试代码
- var doc = Application.DocumentManager.MdiActiveDocument;
- var db = doc.Database;
- var ed = doc.Editor;
- ObjectId id1,id2;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- Line l1 = new Line(new Point3d(1, 1, 0), Point3d.Origin);
- Line l2 = new Line(Point3d.Origin,new Point3d(-1,-1,0));
- id1 = btr.AppendEntity(l1);
- tr.AddNewlyCreatedDBObject(l1,true);
- id2 = btr.AppendEntity(l2);
- tr.AddNewlyCreatedDBObject(l2,true);
- tr.Commit();
- }
- EdEx.Command(
- false,
- "._join",
- id1,
- SelectionSet.FromObjectIds(new ObjectId[] { id2 }),
- null);
|
|