明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 742|回复: 14

[其它] 求怎么把C#生成的图元列表传递给LISP使用?

[复制链接]
发表于 2024-3-9 09:53 | 显示全部楼层 |阅读模式
比如用C#生成了N个图元,怎么传递给LISP遍历使用?
发表于 2024-3-9 18:30 | 显示全部楼层
Bao_lai 发表于 2024-3-9 14:13
这样不知道为啥不行,也不会。

无论如何,返回值必须套ResultBuffer,
https://www.cnblogs.com/JJBox/p/11532752.html
回复 支持 1 反对 0

使用道具 举报

发表于 2024-3-9 14:12 | 显示全部楼层
        [LispFunction("GetEntNames")]
        public List<ObjectId> GetEntNames(ResultBuffer args)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            List<ObjectId> objectIds = new List<ObjectId>();

            PromptSelectionResult psr = ed.GetSelection();
            if (psr.Status == PromptStatus.OK)
            {
                SelectionSet sSet = psr.Value;
                objectIds= sSet.GetObjectIds().ToList();
                return objectIds;
            }
            else
            {
                return null;
            }
        }
发表于 2024-3-9 19:15 | 显示全部楼层
本帖最后由 Bao_lai 于 2024-3-9 19:18 编辑

  1. [LispFunction("GetEntNames")]
  2. public ResultBuffer GetEntNames(ResultBuffer args=null)
  3. {
  4.   Document doc = Application.DocumentManager.MdiActiveDocument;
  5.   Database db = doc.Database;
  6.   Editor ed = doc.Editor;
  7.   
  8.   ResultBuffer rbrtn = new ResultBuffer();

  9.   PromptSelectionResult psr = ed.GetSelection();
  10.   if (psr.Status == PromptStatus.OK)
  11.   {
  12.     SelectionSet sSet = psr.Value;
  13.     int i = 0;
  14.     TypedValue[] ty = new TypedValue[sSet.Count];
  15.     foreach (ObjectId id in sSet.GetObjectIds())
  16.     {  
  17.       ty = new TypedValue((int)LispDataType.ObjectId, id);
  18.       i++;
  19.     }
  20.     rbrtn = new ResultBuffer(ty);
  21.     return rbrtn;
  22.   }
  23.   else
  24.   {
  25.     return null;
  26.   }
  27. }

发表于 2024-3-9 14:13 | 显示全部楼层
Bao_lai 发表于 2024-3-9 14:12
[LispFunction("GetEntNames")]
        public List GetEntNames(ResultBuffer args)
        { ...

这样不知道为啥不行,也不会。
发表于 2024-3-9 19:14 | 显示全部楼层
你有种再说一遍 发表于 2024-3-9 18:30
无论如何,返回值必须套ResultBuffer,
https://www.cnblogs.com/JJBox/p/11532752.html

感谢惊佬,好像可以了。
发表于 2024-3-9 19:22 | 显示全部楼层

  1. (defun C:TT()
  2.   (setq ents (GetEntNames))
  3.   (setq i 0)
  4.   (repeat (length ents)
  5.     (vla-put-Color (vlax-ename->vla-object (nth i ents)) 1)
  6.     (setq i (1+ i))
  7.   )
  8. )


发表于 2024-3-9 19:30 来自手机 | 显示全部楼层
本帖最后由 你有种再说一遍 于 2024-3-9 19:32 编辑
Bao_lai  2024-3-9 19:15

你发完帖子之后看一次帖子,有些地方坏掉了,第八行..还有多用卫语句if(不ok)return
 楼主| 发表于 2024-3-9 20:27 | 显示全部楼层

测试成功,非常感谢
发表于 2024-3-9 21:45 | 显示全部楼层
你有种再说一遍 发表于 2024-3-9 19:30
你发完帖子之后看一次帖子,有些地方坏掉了,第八行..还有多用卫语句if(不ok)return

  1. if (psr.Status != PromptStatus.OK)
  2. { return; }
  3. //下面再写正常的操作


感谢惊佬指导,我理解是这样的意思么:先把不OK的情况给return掉,然后集中精力写OK的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-9 06:29 , Processed in 0.247800 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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