using System; using System.Collections.Generic; using System.Text; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.ApplicationServices; namespace XEIZ.AutoCAD.Util.Jig { public class demoDimensionJig:DrawJig { Database _db = HostApplicationServices.WorkingDatabase; Point3d _minpt; Point3d _oldpt; Point3d _startVertex; DBPoint _oriPt; private Feature feature = null; private Feature selFeature = null; AlignedDimension dimension; public DBPoint OrgPt { set { _oriPt = value; } } public Feature Feat { set { feature = value; } } public Feature SelFeat { set { selFeature = value; } } public Point3d StartVertex { set { _startVertex = value; } }
public void Excute() { ObjectId result = ObjectId.Null; BlockTable bt;
BlockTableRecord btr; try { DBPoint dbpt = (DBPoint)GeometryToEntityConverter.GeometryToEntity(feature.MapGeometry); _minpt = dbpt.Position; dimension = new AlignedDimension(); dimension.DimLinePoint = _minpt; dimension.XLine1Point = _startVertex; dimension.XLine2Point = _minpt; using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument()) { //Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = _db.TransactionManager; //using (Transaction trans = _db.TransactionManager.StartTransaction()) //{ // bt = (BlockTable)tm.GetObject(_db.BlockTableId, OpenMode.ForRead); // if ( bt.Has("xTextBlock")) // { // btr = (BlockTableRecord)trans.GetObject(bt["xTextBlock"], OpenMode.ForWrite); // _xValue = new BlockReference(new Point3d(0, 0, 0), btr.Id); // trans.Commit(); // } //} bool bCancel = false; PromptResult var = _ed.Drag(this); if (var.Status != PromptStatus.OK) { return; } } } catch(System.Exception e) { throw new System.Exception(e.ToString()); } } /// <summary> /// implementation of WorldDraw /// </summary> /// <param name="draw">WorldDraw</param> /// <returns>true:on success, false: on fail</returns> protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw) { draw.Geometry.Draw(dimension); return true; }//end of function WorldDraw() /// <summary> /// implementation of Sampler /// </summary> /// <param name="prompts">JigPrompts</param> /// <returns>SamplerStatus</returns> protected override SamplerStatus Sampler(JigPrompts prompts) { JigPromptPointOptions options = new JigPromptPointOptions("\nPosition"); options.UserInputControls = (UserInputControls.AcceptOtherInputString); PromptPointResult result = prompts.AcquirePoint(options); if (result.Status != PromptStatus.OK) { return SamplerStatus.NoChange; } //Point3d cur = result.Value; //if (_oldpt == cur) //{ // return SamplerStatus.NoChange; //} dimension.DimLinePoint = result.Value; dimension.XLine1Point = _startVertex; dimension.XLine2Point = _minpt; _oldpt = result.Value; return SamplerStatus.OK; }//end of function Sampler() } }
|