7
60
3
初露锋芒
//C# Usings using System; using System.Collections; using SC = System.Collections; using System.Collections.Generic; using SCG = System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Diagnostics; using System.IO; using System.Windows.Forms; using SWF = System.Windows.Forms; using System.ComponentModel; using System.Drawing; using System.Runtime.InteropServices; using System.Xml; using System.Xml.Serialization; using SM = System.Math; using System.Linq; //AutoCad Usings #if ACAD using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using AcAp = Autodesk.AutoCAD.ApplicationServices.Application; using Autodesk.AutoCAD.EditorInput; using AcEd = Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.DatabaseServices; using AcDb = Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using AcGe = Autodesk.AutoCAD.Geometry; using AcCo = Autodesk.AutoCAD.Colors; using Autodesk.AutoCAD.Windows; using AcWn = Autodesk.AutoCAD.Windows; using Autodesk.AutoCAD.GraphicsInterface; using Autodesk.AutoCAD.Interop; using Autodesk.AutoCAD.Customization; #endif #if BCAD using Teigha.DatabaseServices; using AcDb = Teigha.DatabaseServices; using Bricscad.EditorInput; using AcEd = Bricscad.EditorInput; using Teigha.Geometry; using AcGe = Teigha.Geometry; using AcCo = Teigha.Colors; using Teigha.Runtime; using Teigha.GraphicsInterface; using Bricscad.Runtime; using Bricscad.ApplicationServices; using AcAp = Bricscad.ApplicationServices.Application; using Bricscad.Windows; using AcWn = Bricscad.Windows; #endif [assembly: CommandClass(typeof(ProgTestingAcad.Program2))] namespace ProgTestingAcad { public class Program2 { [CommandMethod("TESTPTS2")] public static void GetPts() { Document dwg = AcAp.DocumentManager.MdiActiveDocument; Editor ed = dwg.Editor; MyptCmd cmd = new MyptCmd(dwg); cmd.GetPts(); } } public class MyptCmd { private Document _dwg; private Editor _editor; private List _points; private List _origpoints = new List(); private Point2d _resPt; private AcDb.Polyline _pline = null; public MyptCmd(Document dwg) { _dwg = dwg; _editor = _dwg.Editor; } public void GetPts() { _points = new List(); //get first point PromptPointOptions opt = new PromptPointOptions("\nPick Point: "); PromptPointResult res = _editor.GetPoint(opt); if (res.Status == PromptStatus.OK) { _origpoints.Add(new AcGe.Point2d(res.Value.X, res.Value.Y)); try { //Handling mouse cursor moving during picking _editor.PointMonitor += new PointMonitorEventHandler(_editor_PointMonitor); bool loop = true; //get more points while (loop) { if (!PickNewPoint()) loop = false; //no point else _origpoints.Add(_resPt); } } catch { throw; } finally { ClearTransientGraphics(); //Remove PointMonitor handler _editor.PointMonitor -= new PointMonitorEventHandler(_editor_PointMonitor); } } } private bool PickNewPoint() { PromptPointOptions opt = new PromptPointOptions("\nPick Point: "); PromptPointResult res = _editor.GetPoint(opt); if (res.Status == PromptStatus.OK) { _resPt = new AcGe.Point2d(res.Value.X, res.Value.Y); return true; } else { return false; } } private void ClearTransientGraphics() { TransientManager.CurrentTransientManager.EraseTransients(