明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3465|回复: 10

为什么的确选择了光栅,函数SendStringToExecute却无法正常对光栅执行scale命令。看

[复制链接]
发表于 2009-9-4 22:39 | 显示全部楼层 |阅读模式
为什么的确选择了光栅,函数SendStringToExecute却无法正常对光栅执行scale命令。看代码:[br]

我在图中插入了一个光栅,为什么在提示选择对象后,我明明选择了光栅,函数SendStringToExecute却无法正常执行。


但在AutoCAD命令行中直接粘贴同样的 ._scale -93.147,421.096,0 0.6811 能正常缩放。

看代码:

        [CommandMethod("tt")]
        public static void tt()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptSelectionResult res = ed.GetSelection();
            if (res.Status == PromptStatus.OK)
            {   //如果选择了光栅
                acDoc.SendStringToExecute("._scale -93.147,421.096,0 0.6811", true, false, false);
                //acDoc.SendStringToExecute("._line 1000,1000,0 1100,1100,0", true, false, false);//这个画直线命令能正常执行。
            }
        }

发表于 2009-9-4 22:44 | 显示全部楼层
用矩阵变换试过么
 楼主| 发表于 2009-9-4 23:16 | 显示全部楼层
注:直接粘贴前需要先选中光栅,然后在粘贴,成功缩放了。
 楼主| 发表于 2009-9-4 23:19 | 显示全部楼层
lzh741206发表于2009-9-4 22:44:00用矩阵变换试过么

矩阵变换很麻烦,有命令想直接使用命令更简单

 楼主| 发表于 2009-9-4 23:21 | 显示全部楼层
lzh741206发表于2009-9-4 22:44:00用矩阵变换试过么

在CAD中使用矩阵变换还没有试过,请先生指点一二,不胜感激!谢谢!

发表于 2009-9-4 23:31 | 显示全部楼层
 楼主| 发表于 2009-9-5 06:53 | 显示全部楼层

症结所在:
关键在于执行SendStringToExecute时,在scale后面仍要求选择对象的缘故,但直接粘贴到命令行时为什么不要求选择对象,而能直接成功执行呢

以下是执行tt命令的过程:

命令: tt
请选择光栅: 找到 1 个
请选择光栅:
命令: ._scale
选择对象: -93.147,421.096,0 指定对角点: 0.6811 找到 0 个

(这时res.Status仍然是Ok,说明选择的光栅对象没有丢失)

发表于 2009-9-5 07:26 | 显示全部楼层

有点无语了。。。

发表于 2009-9-5 11:08 | 显示全部楼层
一定要用命令的话,试下下面的代码
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.DatabaseServices;
  8. using Autodesk.AutoCAD.Runtime;
  9. using Autodesk.AutoCAD.Geometry;
  10. using Autodesk.AutoCAD.ApplicationServices;
  11. [assembly: CommandClass(typeof(TlsTest.Class2))]
  12. namespace TlsTest
  13. {
  14.     class Class2
  15.     {
  16.         [DllImport("acad.exe")]
  17.         private static extern int acedCmd(IntPtr vlist);
  18.         public static void Command(params object[] args)
  19.         {
  20.             ResultBuffer rb = new ResultBuffer();
  21.             foreach (object val in args)
  22.             {
  23.                 if (val == null)
  24.                 {
  25.                     rb.Add(new TypedValue((int)LispDataType.Text, ""));
  26.                 }
  27.                 else
  28.                 {
  29.                     if (val is string)
  30.                         rb.Add(new TypedValue((int)LispDataType.Text, val));
  31.                     else if (val is Point2d)
  32.                         rb.Add(new TypedValue((int)LispDataType.Point2d, val));
  33.                     else if (val is Point3d)
  34.                         rb.Add(new TypedValue((int)LispDataType.Point3d, val));
  35.                     else if (val is ObjectId)
  36.                         rb.Add(new TypedValue((int)LispDataType.ObjectId, val));
  37.                     else if (val is SelectionSet)
  38.                         rb.Add(new TypedValue((int)LispDataType.SelectionSet, val));
  39.                     else if (val is double)
  40.                         rb.Add(new TypedValue((int)LispDataType.Double, val));
  41.                     else if (val is short)
  42.                         rb.Add(new TypedValue((int)LispDataType.Int16, val));
  43.                     else if (val is int)
  44.                         rb.Add(new TypedValue((int)LispDataType.Int32, val));
  45.                     else if (val is TypedValue)
  46.                         rb.Add(val);
  47.                 }
  48.             }
  49.             try
  50.             {
  51.                 acedCmd(rb.UnmanagedObject);
  52.             }
  53.             catch
  54.             { }
  55.             finally
  56.             {
  57.                 rb.Dispose();
  58.             }
  59.         }
  60.         [CommandMethod("ttss")]
  61.         public static void tt()
  62.         {
  63.             Document doc = Application.DocumentManager.MdiActiveDocument;
  64.             Database db = doc.Database;
  65.             Editor ed = doc.Editor;
  66.             PromptSelectionResult res = ed.GetSelection();
  67.             if (res.Status == PromptStatus.OK)
  68.             {
  69.                 Application.SetSystemVariable("CmdEcho", 0);
  70.                 Command(
  71.                     "_.scale",
  72.                     res.Value,
  73.                     "",
  74.                     new Point3d(-93.147, 421.096, 0),
  75.                     0.6811);
  76.                 Application.SetSystemVariable("CmdEcho", 1);
  77.             }
  78.         }
  79.     }
  80. }
 楼主| 发表于 2009-9-5 12:48 | 显示全部楼层
lzh741206发表于2009-9-5 11:08:00一定要用命令的话,试下下面的代码using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;using Autodesk.AutoCAD.Edito

先生,这个方法有效。但是需请教,res.Value 、 ""  这两个参数如何得知,哪里有介绍这方面的知识。看来你掌握的面很宽。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-13 06:05 , Processed in 0.152391 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表