马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[ 本帖最后由 csharp 于 2014-5-10 16:27 编辑 ]\n\n- [LispFunction("Entity_Transformedcopy")]
- public object EntityTransformedcopy(ResultBuffer rb)
- {
- TypedValue[] values = rb.AsArray();
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Transaction tr = doc.TransactionManager.StartTransaction();
- if (rb != null)
- {
- if (values[0].TypeCode == (int)LispDataType.ObjectId | values[0].TypeCode == (int)LispDataType.SelectionSet)
- {
- Double[] data = new double[16];
- int j = 0;
- for (int i = 0; i < values.Count(); i++)
- {
- if (values[i].TypeCode == (int)LispDataType.Double)
- {
- data[j] = (double)values[i].Value;
- j++;
- }
- }
- Matrix3d matrix3D = new Matrix3d(data);
- using (tr)
- try
- {
- if (values[0].TypeCode == (int)LispDataType.ObjectId)
- {
- ObjectId id = (ObjectId)values[0].Value;
- Entity ent = (Entity)id.GetObject(OpenMode.ForWrite);
- Entity nent = (Entity)ent.Clone();
- nent.TransformBy(matrix3D);
- tr.Commit();
- return Tools .MyAppendEntity( nent)[0];
- }
- else
- {
- SelectionSet sset = (SelectionSet)values[0].Value;
- ObjectId[] ids = sset.GetObjectIds();
- ObjectId[] nIds = new ObjectId[ids.Count()];
- Entity[] ents = new Entity[ids.Count()];
- for (int i = 0; i < ids.Count(); i++)
- {
- Entity ent = (Entity)ids[i].GetObject(OpenMode.ForRead);
- ents[i] = (Entity)ent.GetTransformedCopy(matrix3D);
- }
- ObjectIdCollection idCollection = Tools.MyAppendEntity( ents);
- for (int i = 0; i < idCollection.Count; i++)
- {
- nIds[i] = idCollection[i];
- }
- tr.Commit();
- SelectionSet nsSet = SelectionSet.FromObjectIds(nIds);
- return nsSet;
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- return null;
- }
添加实体
- public static ObjectIdCollection MyAppendEntity (params Entity[] ents)
- {
- ObjectIdCollection ids = new ObjectIdCollection();
- Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- var trans = db.TransactionManager;
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite);
- foreach (var ent in ents)
- {
- ids.Add(btr.AppendEntity(ent));
- trans.AddNewlyCreatedDBObject(ent, true);
- }
- btr.DowngradeOpen();
- return ids;
- }
只有 translation.Commit();后才可以有SelectionSet.FromObjectIds(ids);
(entity_transformedcopy (ssget) (xdrx_matrix_settranslation (matrix_identity) '(100. 100. 0.))) |