Тема: C# Копирование объекта вдоль заданной 2-мя точками линии
/* * Created by SharpDevelop. * User: fixo * Date: 02.08.2010 * Time: 12:43 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ //System using System; using System.Collections.Generic; using System.Text; //Acad using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Geometry; using acadApp = Autodesk.AutoCAD.ApplicationServices.Application; [assembly: CommandClass(typeof(GeomTools.Divider))] namespace GeomTools { class Divider { [CommandMethod("ZX")] static public void CopyAlong() { Document doc = acadApp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); PromptPointResult ptres1 = ed.GetPoint("\nSpecify first point : ");//Укажите начальную точку if (ptres1.Status != PromptStatus.OK) return; Point3d pt1 = ptres1.Value; PromptPointOptions pto = new PromptPointOptions("\nSpecify second point : ");//Укажите конечную точку pto.UseBasePoint = true; pto.UseDashedLine = true; pto.BasePoint = pt1; PromptPointResult ptres2; ptres2 = ed.GetPoint(pto); if (ptres2.Status != PromptStatus.OK) return; Point3d pt2 = ptres2.Value; PromptEntityOptions pso = new PromptEntityOptions("\n >> Sel ect object to copy along line >> ");//Выбрать объект для копирования PromptEntityResult res = ed.GetEntity(pso); if (res.Status != PromptStatus.OK) return; ObjectId id = res.ObjectId; Point3d from = res.PickedPoint; Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead); if (ent == null) return; PromptIntegerOptions pio = new PromptIntegerOptions(""); pio.Message = "\nEnter the number of divisions: ";//Укажите количество объектов pio.AllowZero = false; pio.AllowNegative = false; pio.DefaultValue = 100;//dummy value for debug only//значение для теста, измените на своё pio.AllowNone = true; PromptIntegerResult ires = ed.GetInteger(pio); if (ires.Status != PromptStatus.OK) return; int num = ires.Value; Line3d ln = new Line3d(pt1, pt2); int cnt = 0; while (cnt <= num) { Point3d p = ln.EvaluatePoint((double)cnt / num); Entity en = (Entity)ent.Clone() as Entity; en.TransformBy(Matrix3d.Displacement(fr om.GetVectorTo(p))); btr.AppendEntity(en); tr.AddNewlyCreatedDBObject(en, true); cnt += 1; ; } tr.Commit(); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage("\nError: {0}\nTrace: {1}", ex.Message, ex.StackTrace); } } } } }
[FONT=Arial]~'J'~[/FONT]