明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 15296|回复: 20

[选集] ResultBuffer简化类

  [复制链接]
发表于 2010-1-4 14:31 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2010-7-9 18:30:24 编辑

经常要做些选择集的过滤器,然而.Net的过滤器写起来真的很繁琐
所以。。。
ResultList类,原创是TonyT,:)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Runtime;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.Geometry;
  8. namespace TlsCad.Collections
  9. {
  10.     /// <summary>
  11.     /// TypedValue Collection
  12.     /// </summary>
  13.     public class ResultList : List<TypedValue>, IFormattable
  14.     {
  15.         public ResultList(){ }
  16.         public ResultList(IEnumerable<TypedValue> values) : base(values)
  17.         { }
  18.         public ResultList(ResultBuffer rb) : base(rb.AsArray())
  19.         { }
  20.         #region Add
  21.         public void Add(int typeCode, object obj)
  22.         {
  23.             base.Add(new TypedValue(typeCode, obj));
  24.         }
  25.         public void Add(LispDataType type, object obj)
  26.         {
  27.             base.Add(new TypedValue((int)type, obj));
  28.         }
  29.         public void Add(DxfCode type, object obj)
  30.         {
  31.             base.Add(new TypedValue((int)type, obj));
  32.         }
  33.         #endregion
  34.         #region Convert
  35.         public static implicit operator TypedValue[](ResultList rlst)
  36.         {
  37.             return rlst.ToArray();
  38.         }
  39.         public static implicit operator ResultBuffer(ResultList rlst)
  40.         {
  41.             return new ResultBuffer(rlst.ToArray());
  42.         }
  43.         public static implicit operator SelectionFilter(ResultList rlst)
  44.         {
  45.             return new SelectionFilter(rlst.ToArray());
  46.         }
  47.         #endregion
  48.         #region IFormattable 成员
  49.         public override string ToString()
  50.         {
  51.             var rb = new ResultBuffer(ToArray());
  52.             return rb.ToString();
  53.         }
  54.         string IFormattable.ToString(string format, IFormatProvider formatProvider)
  55.         {
  56.             var rb = new ResultBuffer(ToArray());
  57.             return rb.ToString(format, formatProvider);
  58.         }
  59.         #endregion
  60.     }
  61. }
ResultTree类,原创飞狐
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Autodesk.AutoCAD.DatabaseServices;
  6. using Autodesk.AutoCAD.Runtime;
  7. using Autodesk.AutoCAD.EditorInput;
  8. using Autodesk.AutoCAD.Geometry;
  9. using System.Collections;
  10. namespace TlsCad.Collections
  11. {
  12.    
  13.     public enum ResultTreeType
  14.     {
  15.         Node,
  16.         List,
  17.         DottedPair,
  18.         RelationalOperator,
  19.         LogicalOperator,
  20.     }
  21.    
  22.     /// <summary>
  23.     /// TypedValue Tree
  24.     /// </summary>
  25.     public class ResultTree : IEnumerable<ResultTree>, IFormattable
  26.     {
  27.         ResultTreeType _treeType;
  28.         ResultTree _owner;
  29.         TypedValue _typedValue;
  30.         List<ResultTree> _lst = new List<ResultTree>();
  31.         static readonly List<string> _relationalOperatorNames =
  32.             new List<string> { "not", "and", "or", "xor" };
  33.         #region Properties
  34.         public ResultTree this[int index]
  35.         {
  36.             get
  37.             {
  38.                 if (_lst.Count == 0)
  39.                 {
  40.                     if(index == 0)
  41.                     {
  42.                         return this;
  43.                     }
  44.                 }
  45.                 else
  46.                 {
  47.                     if (index >= 0 && index < _lst.Count)
  48.                     {
  49.                         return _lst[index];
  50.                     }
  51.                 }
  52.                 return null;
  53.             }
  54.         }
  55.         public ResultTreeType TreeType
  56.         {
  57.             get { return _treeType; }
  58.         }
  59.         public TypedValue TypedValue
  60.         {
  61.             get { return _typedValue; }
  62.         }
  63.         public short TypeCode
  64.         {
  65.             get { return _typedValue.TypeCode; }
  66.         }
  67.         public LispDataType LispDataType
  68.         {
  69.             get { return (LispDataType)TypeCode; }
  70.         }
  71.         public DxfCode DxfCode
  72.         {
  73.             get { return (DxfCode)TypeCode; }
  74.         }
  75.         public object Value
  76.         {
  77.             get { return _typedValue.Value; }
  78.         }
  79.         public T GetValue<T>()
  80.         {
  81.             return (T)_typedValue.Value;
  82.         }
  83.         #endregion
  84.         #region Constructor
  85.         public ResultTree()
  86.         {
  87.             _treeType = ResultTreeType.Node;
  88.         }
  89.         public ResultTree(TypedValue value)
  90.             :this()
  91.         {
  92.             _typedValue = value;
  93.         }
  94.         public ResultTree(int typeCode, object obj)
  95.             : this(new TypedValue(typeCode, obj))
  96.         { }
  97.         public ResultTree(LispDataType type, object obj)
  98.             : this(new TypedValue((int)type, obj))
  99.         { }
  100.         public ResultTree(DxfCode type, object obj)
  101.             : this(new TypedValue((int)type, obj))
  102.         { }
  103.         public ResultTree(string operatorContext)
  104.         {
  105.             operatorContext = operatorContext.ToLower();
  106.             _treeType =
  107.                 _relationalOperatorNames.Contains(operatorContext) ?
  108.                 ResultTreeType.RelationalOperator : ResultTreeType.LogicalOperator;
  109.             _typedValue = new TypedValue(-4, operatorContext);
  110.         }
  111.         public ResultTree(ResultTreeType type)
  112.         {
  113.             _treeType = type;
  114.         }
  115.         private enum ResultNodeType
  116.         {
  117.             Node,
  118.             ListBegin,
  119.             ListEnd,
  120.             DottedPairEnd,
  121.             LogicalOperator,
  122.             RelationalOperatorBegin,
  123.             RelationalOperatorEnd,
  124.         }
  125.         private ResultNodeType GetNodeType(TypedValue tvalue, out ResultTree rt)
  126.         {
  127.             short typeCode = tvalue.TypeCode;
  128.             object value = tvalue.Value;
  129.             rt = null;
  130.             
  131.             if (typeCode == -4)
  132.             {
  133.                 string s = ((string)value).ToLower();
  134.                 if(s[0] == '<' && _relationalOperatorNames.Contains(s.Substring(1)))
  135.                 {
  136.                     rt = new ResultTree(s.Substring(1));
  137.                     return ResultNodeType.RelationalOperatorBegin;
  138.                 }
  139.                 else if(s[s.Length - 1] == '>' && _relationalOperatorNames.Contains(s.Substring(0, s.Length - 1)))
  140.                 {
  141.                     return ResultNodeType.RelationalOperatorEnd;
  142.                 }
  143.                 else
  144.                 {
  145.                     rt = new ResultTree(s);
  146.                     return ResultNodeType.LogicalOperator;
  147.                 }
  148.             }
  149.             else if(typeCode == (short)LispDataType.ListBegin)
  150.             {
  151.                 rt = new ResultTree(ResultTreeType.List);
  152.                 return ResultNodeType.ListBegin;
  153.             }
  154.             else if(typeCode == (short)LispDataType.ListEnd)
  155.             {
  156.                 return ResultNodeType.ListEnd;
  157.             }
  158.             else if(typeCode == (short)LispDataType.DottedPair)
  159.             {
  160.                 return ResultNodeType.DottedPairEnd;
  161.             }
  162.             else
  163.             {
  164.                 rt = new ResultTree(tvalue);
  165.                 return ResultNodeType.Node;
  166.             }
  167.         }
  168.         public ResultTree(ResultBuffer rb)
  169.         {
  170.             ResultTree rt = this;
  171.             foreach (TypedValue tv in rb)
  172.             {
  173.                 ResultTree trt;
  174.                 switch (GetNodeType(tv, out trt))
  175.                 {
  176.                     case ResultNodeType.LogicalOperator:
  177.                     case ResultNodeType.RelationalOperatorBegin:
  178.                     case ResultNodeType.ListBegin:
  179.                         rt = rt.Add(trt);
  180.                         break;
  181.                     case ResultNodeType.DottedPairEnd:
  182.                         rt._treeType = ResultTreeType.DottedPair;
  183.                         rt = rt._owner;
  184.                         break;
  185.                     case ResultNodeType.RelationalOperatorEnd:
  186.                     case ResultNodeType.ListEnd:
  187.                         rt = rt._owner;
  188.                         break;
  189.                     default:
  190.                         rt.Add(trt);
  191.                         if (rt._treeType == ResultTreeType.RelationalOperator)
  192.                             rt = rt._owner;
  193.                         break;
  194.                 }
  195.             }
  196.             if (_lst.Count == 1)
  197.             {
  198.                 rt = _lst[0];
  199.                 _lst.Remove(rt);
  200.                 _lst.AddRange(rt);
  201.                 _treeType = rt._treeType;
  202.                 _typedValue = rt._typedValue;
  203.             }
  204.         }
  205.         #endregion
  206.         #region Set
  207.         public void Set(int typeCode, object obj)
  208.         {
  209.             _typedValue = new TypedValue(typeCode, obj);
  210.         }
  211.         public void Set(LispDataType type, object obj)
  212.         {
  213.             _typedValue = new TypedValue((int)type, obj);
  214.         }
  215.         public void Set(DxfCode type, object obj)
  216.         {
  217.             _typedValue = new TypedValue((int)type, obj);
  218.         }
  219.         public void Set(int typeCode)
  220.         {
  221.             _typedValue = new TypedValue(typeCode);
  222.         }
  223.         public void Set(LispDataType type)
  224.         {
  225.             _typedValue = new TypedValue((int)type);
  226.         }
  227.         public void Set(DxfCode type)
  228.         {
  229.             _typedValue = new TypedValue((int)type);
  230.         }
  231.         #endregion
  232.         #region Add
  233.         public ResultTree Add(TypedValue value)
  234.         {
  235.             return Add(new ResultTree(value));
  236.         }
  237.         public ResultTree Add(int typeCode, object obj)
  238.         {
  239.             return Add(new ResultTree(typeCode, obj));
  240.         }
  241.         public ResultTree Add(LispDataType type, object obj)
  242.         {
  243.             return Add(new ResultTree(type, obj));
  244.         }
  245.         public ResultTree Add(DxfCode type, object obj)
  246.         {
  247.             return Add(new ResultTree(type, obj));
  248.         }
  249.         public ResultTree Add(ResultTree rt)
  250.         {
  251.             rt._owner = this;
  252.             _lst.Add(rt);
  253.             return rt;
  254.         }
  255.         #region Add LispData
  256.         public ResultTree Add(short value)
  257.         {
  258.             return Add(new ResultTree(LispDataType.Int16, value));
  259.         }
  260.         public ResultTree Add(int value)
  261.         {
  262.             return Add(new ResultTree(LispDataType.Int32, value));
  263.         }
  264.         public ResultTree Add(double value)
  265.         {
  266.             return Add(new ResultTree(LispDataType.Double, value));
  267.         }
  268.         public ResultTree Add(string value)
  269.         {
  270.             return Add(new ResultTree(LispDataType.Text, value));
  271.         }
  272.         public ResultTree Add(Point2d value)
  273.         {
  274.             return Add(new ResultTree(LispDataType.Point2d, value));
  275.         }
  276.         public ResultTree Add(Point3d value)
  277.         {
  278.             return Add(new ResultTree(LispDataType.Point3d, value));
  279.         }
  280.         public ResultTree Add(ObjectId value)
  281.         {
  282.             return Add(new ResultTree(LispDataType.ObjectId, value));
  283.         }
  284.         public ResultTree Add(SelectionSet value)
  285.         {
  286.             return Add(new ResultTree(LispDataType.SelectionSet, value));
  287.         }
  288.         //public void Add(ResultType type, params object[] values)
  289.         //{
  290.         //    ResultTree rt = new ResultTree(type);
  291.         //    foreach (object value in values)
  292.         //    {
  293.         //        if (value is short)
  294.         //        {
  295.         //            rt.Add((short)value);
  296.         //        }
  297.         //        else if (value is int)
  298.         //        {
  299.         //            rt.Add((int)value);
  300.         //        }
  301.         //        else if (value is double)
  302.         //        {
  303.         //            rt.Add((double)value);
  304.         //        }
  305.         //        else if (value is string)
  306.         //        {
  307.         //            rt.Add((string)value);
  308.         //        }
  309.         //        else if (value is Point2d)
  310.         //        {
  311.         //            rt.Add((Point2d)value);
  312.         //        }
  313.         //        else if (value is Point3d)
  314.         //        {
  315.         //            rt.Add((Point3d)value);
  316.         //        }
  317.         //        else if (value is ObjectId)
  318.         //        {
  319.         //            rt.Add((ObjectId)value);
  320.         //        }
  321.         //        else if (value is SelectionSet)
  322.         //        {
  323.         //            rt.Add((SelectionSet)value);
  324.         //        }
  325.         //    }
  326.         //}
  327.         #endregion
  328.         #endregion
  329.         #region Convert
  330.         private void GetValues(List<TypedValue> values)
  331.         {
  332.             switch (_treeType)
  333.             {
  334.                 case  ResultTreeType.Node:
  335.                     if (_lst.Count == 0)
  336.                     {
  337.                         values.Add(_typedValue);
  338.                     }
  339.                     else
  340.                     {
  341.                         _lst.ForEach(rtree => rtree.GetValues(values));
  342.                     }
  343.                     break;
  344.                 case ResultTreeType.List:
  345.                     values.Add(new TypedValue((int)LispDataType.ListBegin));
  346.                     _lst.ForEach(rtree => rtree.GetValues(values));
  347.                     values.Add(new TypedValue((int)LispDataType.ListEnd));
  348.                     break;
  349.                 case ResultTreeType.DottedPair:
  350.                     values.Add(new TypedValue((int)LispDataType.ListBegin));
  351.                     _lst.ForEach(rtree => rtree.GetValues(values));
  352.                     values.Add(new TypedValue((int)LispDataType.DottedPair));
  353.                     break;
  354.                 case ResultTreeType.LogicalOperator:
  355.                     values.Add(_typedValue);
  356.                     _lst.ForEach(rtree => rtree.GetValues(values));
  357.                     break;
  358.                 case ResultTreeType.RelationalOperator:
  359.                     values.Add(new TypedValue(-4, "<" + _typedValue.Value));
  360.                     _lst.ForEach(rtree => rtree.GetValues(values));
  361.                     values.Add(new TypedValue(-4, _typedValue.Value + ">"));
  362.                     break;
  363.             }
  364.         }
  365.         public TypedValue[] ToArray()
  366.         {
  367.             List<TypedValue> values = new List<TypedValue>();
  368.             GetValues(values);
  369.             return values.ToArray();
  370.         }
  371.         public static implicit operator SelectionFilter(ResultTree rtree)
  372.         {
  373.             return new SelectionFilter(rtree.ToArray());
  374.         }
  375.         public static implicit operator ResultBuffer(ResultTree rtree)
  376.         {
  377.             return new ResultBuffer(rtree.ToArray());
  378.         }
  379.         #endregion
  380.         #region RelationalOperator
  381.         private void MakeRelationalOperator(string operatorContext, ResultTree res)
  382.         {
  383.             if (_treeType == ResultTreeType.RelationalOperator && _typedValue.Value.ToString() == operatorContext)
  384.             {
  385.                 res._lst.AddRange(_lst);
  386.             }
  387.             else
  388.             {
  389.                 res.Add(this);
  390.             }
  391.         }
  392.         public static ResultTree operator !(ResultTree rt1)
  393.         {
  394.             ResultTree rt = new ResultTree("not") { rt1 };
  395.             return rt;
  396.         }
  397.         public static ResultTree operator &(ResultTree rt1, ResultTree rt2)
  398.         {
  399.             ResultTree rt = new ResultTree("and");
  400.             rt1.MakeRelationalOperator("and", rt);
  401.             rt2.MakeRelationalOperator("and", rt);
  402.             return rt;
  403.         }
  404.         public static ResultTree operator |(ResultTree rt1, ResultTree rt2)
  405.         {
  406.             ResultTree rt = new ResultTree("or");
  407.             rt1.MakeRelationalOperator("or", rt);
  408.             rt2.MakeRelationalOperator("or", rt);
  409.             return rt;
  410.         }
  411.         public static ResultTree operator ^(ResultTree rt1, ResultTree rt2)
  412.         {
  413.             return
  414.                 new ResultTree("xor")
  415.                 {
  416.                     rt1,
  417.                     rt2
  418.                 };
  419.         }
  420.         #endregion
  421.         
  422.         #region IFormattable 成员
  423.         public override string ToString()
  424.         {
  425.             var rb = new ResultBuffer(ToArray());
  426.             return rb.ToString();
  427.         }
  428.         string IFormattable.ToString(string format, IFormatProvider formatProvider)
  429.         {
  430.             var rb = new ResultBuffer(ToArray());
  431.             return rb.ToString(format, formatProvider);
  432.         }
  433.         #endregion
  434.         #region IEnumerable<ResultTree> 成员
  435.         #region IEnumerable 成员
  436.         IEnumerator IEnumerable.GetEnumerator()
  437.         {
  438.             return _lst.GetEnumerator();
  439.         }
  440.         #endregion
  441.         IEnumerator<ResultTree> IEnumerable<ResultTree>.GetEnumerator()
  442.         {
  443.             return _lst.GetEnumerator();
  444.         }
  445.         #endregion
  446.     }
  447. }

扩展方法
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using TlsCad.Collections;
  6. using Autodesk.AutoCAD.DatabaseServices;
  7. namespace TlsCad.ExtendMethods
  8. {
  9.     public static class ResultBufferEx
  10.     {
  11.         public static ResultList ToList(this ResultBuffer rb)
  12.         {
  13.             return new ResultList(rb);
  14.         }
  15.         public static ResultTree ToTree(this ResultBuffer rb)
  16.         {
  17.             return new ResultTree(rb);
  18.         }
  19.     }
  20. }

示例代码
  1.         [CommandMethod("t9")]
  2.         public static void Test9()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Database db = doc.Database;
  6.             Editor ed = doc.Editor;
  7.             PromptSelectionResult res1 =
  8.                 ed.SelectAll(
  9.                     new ResultTree
  10.                     {
  11.                         new ResultTree(">,>,*")
  12.                         {
  13.                             {10, new Point3d()}
  14.                         },
  15.                         new ResultTree("<,<,*")
  16.                         {
  17.                             {10, new Point3d(10,10,0)}
  18.                         }
  19.                     });
  20.             PromptSelectionResult res2 =
  21.                 ed.SelectAll(
  22.                     new ResultList
  23.                     {
  24.                         {-4, ">,>,*"},
  25.                         {10, new Point3d()},
  26.                         {-4, "<,<,*"},
  27.                         {10, new Point3d(10,10,0)}
  28.                     });
  29.             PromptSelectionResult res3 =
  30.                 ed.SelectAll(
  31.                     new ResultTree("or")
  32.                     {
  33.                         new ResultTree("and")
  34.                         {
  35.                             {0, "Line"},
  36.                             {8, "01"}
  37.                         },
  38.                         new ResultTree("and")
  39.                         {
  40.                             {0, "Circle"},
  41.                             {8, "02"}
  42.                         }
  43.                     });
  44.             PromptSelectionResult res4 =
  45.                 ed.SelectAll(
  46.                     new ResultList
  47.                     {
  48.                         {-4, "<or"},
  49.                             {-4, "<and"},
  50.                                 {0, "Line"},
  51.                                 {8, "01"},
  52.                             {-4, "and>"},
  53.                             {-4, "<and"},
  54.                                 {0, "Circle"},
  55.                                 {8, "02"},
  56.                             {-4, "and>"},
  57.                         {-4, "or>"}
  58.                     });
  59.         }
  60.         [CommandMethod("t10")]
  61.         public static void Test10()
  62.         {
  63.             Document doc = Application.DocumentManager.MdiActiveDocument;
  64.             Database db = doc.Database;
  65.             Editor ed = doc.Editor;
  66.             PromptEntityResult res = ed.GetEntity("Select a Entity:");
  67.             using (DBTransaction tr = new DBTransaction())
  68.             {
  69.                 tr.OpenRegAppTable(OpenMode.ForWrite);
  70.                 tr.RegApp("MyApp");
  71.                 Entity ent = tr.GetObject(res.ObjectId, OpenMode.ForWrite) as Entity;
  72.                 ent.XData =
  73.                     new ResultList
  74.                     {
  75.                         {1001, "MyApp"},
  76.                         {1000, "This is a Test"},
  77.                         {DxfCode.ExtendedDataInteger16, 12}
  78.                     };
  79.             }
  80.         }
  81.         [CommandMethod("t11")]
  82.         public static void Test11()
  83.         {
  84.             Document doc = Application.DocumentManager.MdiActiveDocument;
  85.             Database db = doc.Database;
  86.             Editor ed = doc.Editor;
  87.             PromptEntityResult res1 = ed.GetEntity("\nSelect a Entity:");
  88.             InvokeArx.CmdEcho = false;
  89.             InvokeArx.Command(
  90.                 false,
  91.                 new ResultTree
  92.                 {
  93.                     "break",
  94.                     new ResultTree(ResultType.List)
  95.                     {
  96.                         res1.ObjectId,
  97.                         res1.PickedPoint
  98.                     },
  99.                     res1.PickedPoint
  100.                 });
  101.             InvokeArx.CmdEcho = true;
  102.         }
  103.         [LispFunction("lsptest1")]
  104.         public static ResultBuffer LTest1(ResultBuffer rb)
  105.         {
  106.             ResultTree rtree =
  107.                 new ResultTree(ResultType.List)
  108.                 {
  109.                     1,
  110.                     new ResultTree(ResultType.DottedPair)
  111.                     {
  112.                         10,
  113.                         new Point3d(10, 10, 0)
  114.                     }
  115.                 };
  116.             return rtree;
  117.         }

评分

参与人数 1威望 +1 明经币 +2 金钱 +20 贡献 +5 激情 +5 收起 理由
ahlzl + 1 + 2 + 20 + 5 + 5 【精华】好程序

查看全部评分

 楼主| 发表于 2010-1-4 14:33 | 显示全部楼层
不过,简化写法必须在VS2008及以上版本才支持
 楼主| 发表于 2010-1-4 21:24 | 显示全部楼层
ResultTree的操作符重载版本(一楼代码已更改),这样写挺好玩的,:)
测试代码
  1.             ResultTree rt =
  2.                 new ResultTree(0, "Line") & new ResultTree(8, "01") & !new ResultTree(10, new Point3d())
  3.                 |
  4.                 new ResultTree(0, "Circle") & new ResultTree(8, "02");
  5.             ed.WriteMessage(rt.ToString());
复制代码
返回:
((-4,<or)(-4,<and)(0,Line)(8,01)(-4,<not)(10,(0,0,0))(-4,not>)(-4,and>)(-4,<and)
(0,Circle)(8,02)(-4,and>)(-4,or>))


发表于 2010-1-4 21:36 | 显示全部楼层
个人觉得还是太麻烦。实际可能少用到。我就没有这样用过。
发表于 2010-1-4 21:37 | 显示全部楼层

顶我们的狐老大,哈哈!

 楼主| 发表于 2010-7-9 15:53 | 显示全部楼层
本帖最后由 作者 于 2010-7-9 18:44:37 编辑

更新版本,增加与ResultBuffer的互相转换,增强Lisp相关操作
简化选择集中逻辑表达式的写法(见示例)

LispFunction的相关示例
  1.         [LispFunction("mylisp1")]
  2.         public object lsptest11(ResultBuffer rb)
  3.         {
  4.             ResultTree rt = rb.ToTree();
  5.             switch (rt.TreeType)
  6.             {
  7.                 case ResultTreeType.Node:
  8.                     switch (rt.LispDataType)
  9.                     {
  10.                         case LispDataType.Point2d:
  11.                             Point2d pt2d = rt.GetValue<Point2d>();
  12.                             rt.Set(LispDataType.Point2d, new Point2d(10, pt2d.Y));
  13.                             break;
  14.                         case LispDataType.Point3d:
  15.                             Point3d pt3d = rt.GetValue<Point3d>();
  16.                             rt.Set(LispDataType.Point3d, new Point3d(10, pt3d.Y, pt3d.Z));
  17.                             break;
  18.                     }
  19.                     break;
  20.                 case ResultTreeType.List:
  21.                 case ResultTreeType.DottedPair:
  22.                     rt[0].Set(LispDataType.Int16, 10);
  23.                     return (ResultBuffer)rt;
  24.             }
  25.             return rt.TypedValue;
  26.         }

效果:
  1. 命令: (mylisp1 '(1 2))
  2. (10.0 2.0)
  3. 命令: (mylisp1 '(1 2 3))
  4. (10.0 2.0 3.0)
  5. 命令: (mylisp1 '(1 2 3 4))
  6. (10 2 3 4)
  7. 命令: (mylisp1 3)
  8. 3
复制代码
发表于 2010-7-13 22:01 | 显示全部楼层

 好。

发表于 2010-8-24 17:32 | 显示全部楼层
必须留言 .... 好东西呀
发表于 2010-10-2 15:35 | 显示全部楼层

好东西,学习中

发表于 2011-1-24 10:01 | 显示全部楼层
lisp传递参数的ResultBuffer,有时表被当成点对,如何解决?

//Lisp:第二个参数是四个整数
(TTT "AAA" (list 10 20 30 40) 12.36)

//.NET:把(list 10 20 30 40)当成点对,得到一个Point3D(20,30,40),显然不对
<LispFunction("TTT")> Public Sub TTT(ByVal rbArgs As ResultBuffer)
     'rbArgs
End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-26 09:24 , Processed in 0.353102 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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