再加几句支持实体或者选择集
![](source/plugin/imc_colorcode/images/loading.gif) - [LispFunction("ssbox")]
- public static ResultBuffer SelectionBox(ResultBuffer rb)
- {
- Document document = Application.DocumentManager.MdiActiveDocument;
- Editor editor = document.Editor;
- Transaction transaction = document.TransactionManager.StartTransaction();
- if (rb == null) return null;
- TypedValue[] tvValues = rb.AsArray();
- using (transaction)
- {
- try
- {
- ResultBuffer result = new ResultBuffer();
- if (tvValues.Length == 1 && tvValues[0].TypeCode == (int)LispDataType.SelectionSet | tvValues [0].TypeCode == (int)LispDataType .ObjectId )
- {
- switch (tvValues[0].TypeCode)
- {
- case 5006:
- {
- Entity entity =
- (Entity) transaction.GetObject((ObjectId) tvValues[0].Value, OpenMode.ForRead);
- Extents3d tmpExtents3D = entity.GeometricExtents;
- Point3d maxpt = tmpExtents3D.MaxPoint;
- Point3d minpt = tmpExtents3D.MinPoint;
- result.Add(new TypedValue((int)LispDataType.Point3d, minpt));
- result.Add(new TypedValue((int)LispDataType.Point3d, maxpt));
- break;
- }
- case 5007:
- {
- SelectionSet ssSet = tvValues[0].Value as SelectionSet;
- var ids = ssSet.GetObjectIds();
- Entity ent = (Entity)transaction.GetObject(ids[0], OpenMode.ForRead);
- Extents3d tmpExtents3D = ent.GeometricExtents;
- for (int i = 1; i < ids.Length; i++)
- {
- Entity entity = (Entity)transaction.GetObject(ids[i], OpenMode.ForRead);
- Extents3d tmp = entity.GeometricExtents;
- tmpExtents3D.AddExtents(tmp);
- }
- Point3d maxpt = tmpExtents3D.MaxPoint;
- Point3d minpt = tmpExtents3D.MinPoint;
- result.Add(new TypedValue((int)LispDataType.Point3d, minpt));
- result.Add(new TypedValue((int)LispDataType.Point3d, maxpt));
- break;
- }
- }
- }
- transaction.Commit();
- return result ;
- }
- catch (Autodesk .AutoCAD .Runtime .Exception ex)
- {
- return null;
- }
- }
- }
|