- 积分
- 2124
- 明经币
- 个
- 注册时间
- 2011-4-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 mrhvslisp 于 2011-10-23 21:42 编辑
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.EditorInput;
- namespace Base
- {
- public class Class1
- {
- //沿指定方向按指定距离复制实体
- #region supercopy
- [CommandMethod("supercopy")]
- public static void SuperCopy()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- using (Transaction trans = doc.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
- PromptSelectionResult result = ed.GetSelection();
- ObjectIdCollection idcoll = new ObjectIdCollection();
- if (result.Status == PromptStatus.OK)
- {
- SelectionSet ss = result.Value;
- foreach (SelectedObject obj in ss)
- {
- idcoll.Add(obj.ObjectId);
-
- }
- }
- PromptPointOptions ptoptions = new PromptPointOptions("");
- ptoptions.AllowArbitraryInput = false;
- ptoptions.Message = "\n请选择起点";
- PromptPointResult ptresult = ed.GetPoint(ptoptions);
- Point3dCollection ptcoll = new Point3dCollection();
- if(ptresult.Status==PromptStatus .OK)
- {
- Point3d pt1 = new Point3d(ptresult .Value.X,ptresult.Value.Y,0);
- ptcoll.Add(pt1);
- }
- else if (ptresult.Status == PromptStatus.Cancel)
- {
- return;
- }
- ptoptions.Message = "\n请选择终点";
- PromptPointResult pt2result = ed.GetPoint (ptoptions);
- if (pt2result.Status == PromptStatus.OK)
- {
- Point3d pt2 = new Point3d(pt2result.Value.X, pt2result.Value.Y,0);
- ptcoll.Add(pt2);
- }
- else if (ptresult.Status == PromptStatus.Cancel)
- {
- return;
- }
- Vector3d vec = new Vector3d(ptcoll[1].X-ptcoll[0].X,ptcoll[1].Y-ptcoll[0].Y,0);
- PromptDistanceOptions distanceoptions = new PromptDistanceOptions("");
- distanceoptions.Message = "\n请输入复制间隔";
- distanceoptions.AllowNone = true;
- distanceoptions.DefaultValue = 8;
- distanceoptions.AllowArbitraryInput = false;
- PromptDoubleResult distresult = ed.GetDistance(distanceoptions);
- if (distresult.Status == PromptStatus.OK | distresult.Status == PromptStatus.None)
- {
- double length = distresult.Value;
- int i = Convert.ToInt32(Math.Floor(vec.Length / length));
- vec = vec / i;
- for (int m = 1; m <= i; m++)
- {
- foreach (ObjectId id in idcoll)
- {
- Entity entity = trans.GetObject(id, OpenMode.ForWrite) as Entity;
- Matrix3d mt = Matrix3d.Displacement(vec*m);
- Entity entcopy = entity.GetTransformedCopy(mt);
- btr.AppendEntity(entcopy);
- trans.AddNewlyCreatedDBObject(entcopy, true);
- }
- }
- }
- ed.UpdateScreen();
- trans.Commit();
- }
-
- }
- #endregion
- }
- }
|
|