- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2017-2-13 16:49 编辑
论坛开源函数有个 xd::list:groupbyindex , 在 ARX 下这个索引就要自己定义一个 class 或者 struct ,下面这个例子已消除重复图块为例,以 STL 标准库的 vector 及其标准函数为基础,首先定义一个 struct 即 索引,说明哪些特性相同的时候视为重复,测试中只写了插入点,实际中可以再增加其它属性(名称、比例等)
首先定义一个数据,
- typedef struct blockInfo{
- AcGePoint3d position;//插入点
- AcDbObjectId id;
- AcGeTol tol;
- bool operator < (const blockInfo &a) const//排序比较函数,X 由小到大,Y由小到大, 相当于按行左下角点起始
- {
- if (fabs((this->position).y-a.position.y)<1e-6)
- {
- return this->position.x<a.position.x;
- }
- else
- return this->position.y<a.position.y;
- }
- bool operator > (const blockInfo &a) const//
- {
- if (fabs(this->position.y-a.position.y)<1e-6)
- {
- return this->position.x>a.position.x;
- }
- else
- return this->position.y>a.position.y;
- }
- bool operator == (const blockInfo &a) const
- {
- return this->position.isEqualTo(a.position,tol);
- }
- }BLOCKINFO;
复制代码
这里面定义一个 operator < 用于 sort 排序即可, == 操作符是用于 unique 函数“消除重复" , 实测环境 XP + VS2002 + AutoCAD 2004 中 struct 中 == 操作符不起作用的,还需要单独定义一个比较函数
- bool myfunction (const blockInfo &a,const blockInfo &b)//比较是否重复
- {
- return a==b;
- }
复制代码
主程序
运行结果
命令: test02
选择对象: 指定对角点: 找到 16 个
选择对象:
2130145760
2130145752
2130145744
2130145736
2130145728
2130145720
2130145712
2130145704
2130145696
2130145688
2130145680
2130145672
2130145664
2130145656
2130145648
2130145640
=====sort=====
2130145664,(470.99,372.57)
2130145656,(470.99,372.57)
2130145648,(470.99,372.57)
2130145640,(470.99,372.57)
2130145696,(544.59,372.57)
2130145688,(544.59,372.57)
2130145680,(544.59,372.57)
2130145672,(544.59,372.57)
2130145760,(617.74,372.57)
2130145752,(617.74,372.57)
2130145744,(617.74,372.57)
2130145736,(617.74,372.57)
2130145728,(711.04,372.57)
2130145720,(711.04,372.57)
2130145712,(711.04,372.57)
2130145704,(711.04,372.57)
=====unique=====
2130145664,(470.99,372.57)
2130145696,(544.59,372.57)
2130145760,(617.74,372.57)
2130145728,(711.04,372.57)
2130145696,(544.59,372.57)
2130145688,(544.59,372.57)
2130145680,(544.59,372.57)
2130145672,(544.59,372.57)
2130145760,(617.74,372.57)
2130145752,(617.74,372.57)
2130145744,(617.74,372.57)
2130145736,(617.74,372.57)
2130145728,(711.04,372.57)
2130145720,(711.04,372.57)
2130145712,(711.04,372.57)
2130145704,(711.04,372.57)
|
|