马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[ 本帖最后由 csharp 于 2014-5-6 06:36 编辑 ]\n\n- [LispFunction("ssInters")]
- public ResultBuffer GeSelectionsetInters(ResultBuffer rb)
- {
- Document document = Application.DocumentManager.MdiActiveDocument;
- Transaction transaction = document.TransactionManager.StartTransaction();
- if (rb != null)
- {
- TypedValue[] values = rb.AsArray();
- if (values.Count() == 1 && values[0].TypeCode == (int) LispDataType.SelectionSet)
- {
- using (transaction)
- {
- try
- {
- SelectionSet ss = (SelectionSet) values[0].Value;
- ObjectId[] ids = ss.GetObjectIds() ;
- int count = ids.Count();
- Entity[] ents = new Entity[count];
- for (int i = 0; i < count; i++)
- {
- ents[i] = (Entity) ids[i].GetObject(OpenMode.ForRead);//Entity Array
- }
- if (count > 1)
- {
- List<Point3dCollection> pnts = new List<Point3dCollection>();
- for (int i = 0; i < count ; i++)
- {
- Entity ent = ents[i];
- for (int j = i + 1; j < count; j++)
- {
- Point3dCollection npts = new Point3dCollection();
- Entity ent1 = ents[j];
- ent.IntersectWith(ent1, Intersect.OnBothOperands,npts,IntPtr.Zero ,IntPtr .Zero );
- if (npts.Count > 0)
- {
- pnts.Add(npts);
- }
- }
- }
-
- int tl = pnts.Count;
- if (tl > 0)
- {
- int listTotleLenth = 0;
- for (int i = 0; i < tl; i++)
- {
- listTotleLenth += pnts[i].Count;
- }
- TypedValue[] nvalues = new TypedValue[listTotleLenth + 2];
- nvalues [0]= new TypedValue((int)LispDataType .ListBegin );
- int m = 1;
- for (int k = 0; k < tl ; k++)
- {
- Point3dCollection tmpPoint3DCollection = pnts[k];
- Point3d [] pntArr = new Point3d[tmpPoint3DCollection .Count ];
- pnts[k].CopyTo(pntArr,0);
- for (int j = 0; j < pntArr .Length ; j++)
- {
- nvalues[m] = new TypedValue((int)LispDataType.Point3d, pntArr [j]);
- m++;
- }
-
- }
- nvalues[listTotleLenth + 1] = new TypedValue((int)LispDataType.ListEnd);
- ResultBuffer ret = new ResultBuffer(nvalues);
- return ret;
- }
- else
- {
- return null;
- }
- }
- else
- {
- return null;
- }
-
- }
- catch (Exception)
- {
- throw;
- return null;
- }
- }
- }
- else
- {
- return null;
- }
- }
- else
- {
- return null;
- }
- }
命令: (setq l (length (ssinters (ssget))))(princ l)(princ)
选择对象: 指定对角点: 找到 2575 个选择对象:
GetInters Time Used: 5524
TypeValue Time Used: 195
ResultBuffer time used: 5
32745
IntersectWith 和 List<T> 是比较耗时间的!(测试全部 为 Line)时间为毫秒(千分之一秒) |