- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've previously only programmed in vlisp and I'm making my transition to .net C#, so a lot of this is new to me. I'm trying to make a basic dimension command which will be similar to the out of the box commands "dimlinear" and "dimaligned."
In vlisp i can just do a (command "dimlinear" pause pause pause) and do entlast to modify the dimension afterwards, in .net I don't have this ability anymore.
So i have two questions, first one is simple, then the second one is more complex.
- While creating a RotatedDimension all the examples in the AutoCAD SDK and online forums just hard type in the angle for ".rotation" property. How do I get the user to input the ".rotation" at the same time I'm getting the input for the ".DimLinePoint" like the original "dimlinear" command? Keeping the dimension ortho to the ucs?
- The first question will answer my immediate issue, but my second question is in AutoCAD 2016 how does the new command "DIM" work that it dynamically changes from dimlinear and dimaligned depending on where the user's cursor is before selecting the ".DimLinePoint"? If someone can point me in the right direction or what to research would be really helpful. This would be a neet feature to use, rather than creating two different commands for linear vs aligned dimensions.
Here's the code I have so far for my first question. (I used an example from online with a jig and modified from there):
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Windows; using MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application; using MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document; using AcWindowsNS = Autodesk.AutoCAD.Windows; [assembly: CommandClass(typeof(Test.MyCommand))] namespace Test { public class MyCommand { [CommandMethod("TestRotJigger")] public static void TestRotJigger() { Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor; if (RotDimJigger.Jig()) { ed.WriteMessage("\nA rotated dimension has been successfully jigged and added to the database.\n"); } else { ed.WriteMessage("\nIt failed to jig and add a rotated dimension to the database.\n"); } } public class RotDimJigger : EntityJig { #region Fields public Point3d mLinePoint = new Point3d(); // Factor #1 #endregion #region Constructors public RotDimJigger(RotatedDimension ent) : base(ent) { } #endregion #region Overrides protected override bool Update() { (Entity as RotatedDimension).DimLinePoint = mLinePoint; return true; } protected override SamplerStatus Sampler(JigPrompts prompts) { JigPromptPointOptions prOptions1 = new JigPromptPointOptions("\nDimension line point:"); prOptions1.UserInputControls = UserInputControls.Accept3dCoordinates | UserInputControls.AnyBlankTerminatesInput | UserInputControls.GovernedByUCSDetect | UserInputControls.UseBasePointElevation | UserInputControls.InitialBlankTerminatesInput | UserInputControls.NullResponseAccepted | UserInputControls.GovernedByOrthoMode; PromptPointResult prResult1 = prompts.AcquirePoint(prOptions1); if (prResult1.Status == PromptStatus.Cancel) return SamplerStatus.Cancel; if (prResult1.Value.Equals(mLinePoint)) { return SamplerStatus.NoChange; } else { mLinePoint = prResult1.Value; return SamplerStatus.OK; } } #endregion #region Method to Call public static bool Jig() { try { Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor; Database db = HostApplicationServices.WorkingDatabase; Point3dCollection colPts = new Point3dCollection(); PromptPointOptions ppo = new PromptPointOptions(""); // Prompt for the first point PromptPointResult ppr = ed.GetPoint("\nSpecify first point of the dimension"); if (ppr.Status != PromptStatus.OK) return false; colPts.Add(ppr.Value); // Prompt for the second point ppo.Message = "\nSpecify second point of the dimension: "; ppo.UseBasePoint = true; ppo.BasePoint = colPts[0]; ppr = ed.GetPoint(ppo); if (ppr.Status != PromptStatus.OK) return false; colPts.Add(ppr.Value); // Create entity of rotated dimension RotatedDimension ent = new RotatedDimension(0,colPts[0],colPts[1],colPts[0],"<>",db.Dimstyle); RotatedDimension rotDim = new RotatedDimension(); rotDim.DimLinePoint // Create jigger ent.TransformBy(MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem); RotDimJigger jigger = new RotDimJigger(ent); PromptResult pr = ed.Drag(jigger); if (pr.Status == PromptStatus.OK) { using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); btr.AppendEntity(jigger.Entity); tr.AddNewlyCreatedDBObject(jigger.Entity, true); tr.Commit(); } } else { ent.Dispose(); return false; } return true; } catch { return false; } } #endregion } } }
Solved! Go to Solution.