Hello, is there anywhere a .NET implementation for (some of) the existing AutoCAD (object creation) commands. For example, would it be possible to create LINE command with .NET to work the same way as the built-in one (with mouse interaction etc.)?
All the examples I found so far are implemented with hard coded parameters. Keyboard input is fine but mouse input would be the preferable solution, the same way as it works with all the built-in commands.
Thanks.
Solved! Go to Solution.
Hello, is there anywhere a .NET implementation for (some of) the existing AutoCAD (object creation) commands. For example, would it be possible to create LINE command with .NET to work the same way as the built-in one (with mouse interaction etc.)?
All the examples I found so far are implemented with hard coded parameters. Keyboard input is fine but mouse input would be the preferable solution, the same way as it works with all the built-in commands.
Thanks.
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
Prompting the user for a point with Editor.PromptPointOptions and Editor.PromptPointResult allows the user to specify the point either with the mouse or with the keybord.
You can test it by yourself.
[CommandMethod("TEST")] public static void Test() { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; var options = new PromptPointOptions("\nSpecify start point: "); var result = ed.GetPoint(options); if (result.Status != PromptStatus.OK) return; var startPoint = result.Value; options.Message = "\nSpecify end point: "; options.BasePoint = startPoint; options.UseBasePoint = true; result = ed.GetPoint(options); if (result.Status != PromptStatus.OK) return; var endPoint = result.Value; using (var tr = db.TransactionManager.StartTransaction()) { var line = new Line(startPoint, endPoint); line.TransformBy(ed.CurrentUserCoordinateSystem); var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); curSpace.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); tr.Commit(); } }
Hi,
Prompting the user for a point with Editor.PromptPointOptions and Editor.PromptPointResult allows the user to specify the point either with the mouse or with the keybord.
You can test it by yourself.
[CommandMethod("TEST")] public static void Test() { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; var options = new PromptPointOptions("\nSpecify start point: "); var result = ed.GetPoint(options); if (result.Status != PromptStatus.OK) return; var startPoint = result.Value; options.Message = "\nSpecify end point: "; options.BasePoint = startPoint; options.UseBasePoint = true; result = ed.GetPoint(options); if (result.Status != PromptStatus.OK) return; var endPoint = result.Value; using (var tr = db.TransactionManager.StartTransaction()) { var line = new Line(startPoint, endPoint); line.TransformBy(ed.CurrentUserCoordinateSystem); var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); curSpace.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); tr.Commit(); } }
You should have a look at the Prompt for User Input section of the developer's documentation, and particulary the GetPoint Method.
You should have a look at the Prompt for User Input section of the developer's documentation, and particulary the GetPoint Method.
Thanks a lot Gilles.
I meanwhile bumped into EntityJig class and found some examples with it. Your solution is simpler, but it might be that EntityJig offers more flexibility (like adding the arc as in the built-in LINE command).
Still investigating...
Thanks a lot Gilles.
I meanwhile bumped into EntityJig class and found some examples with it. Your solution is simpler, but it might be that EntityJig offers more flexibility (like adding the arc as in the built-in LINE command).
Still investigating...
@Anonymous wrote:
Thanks a lot Gilles.
I meanwhile bumped into EntityJig class and found some examples with it. Your solution is simpler, but it might be that EntityJig offers more flexibility (like adding the arc as in the built-in LINE command).
Still investigating...
The built-in _LINE command does not offer any Arc option. It looks like you confuse with the _PLINE command.
Anyway, using a jig and keyword options was not your first request which only talk about using the mouse while prompting the user for a point.
Please, if you want to get help, try to make your questions as clear and detailed as possible.
@Anonymous wrote:
Thanks a lot Gilles.
I meanwhile bumped into EntityJig class and found some examples with it. Your solution is simpler, but it might be that EntityJig offers more flexibility (like adding the arc as in the built-in LINE command).
Still investigating...
The built-in _LINE command does not offer any Arc option. It looks like you confuse with the _PLINE command.
Anyway, using a jig and keyword options was not your first request which only talk about using the mouse while prompting the user for a point.
Please, if you want to get help, try to make your questions as clear and detailed as possible.
Sorry for misunderstanding Gilles, I thought of the arc which is being shown while picking up the next point of the line (in LINE command) (it's AutoCAD 2020)
I'm still quite new in API, so at the moment I suppose that I would have to use EntityJig for this "effect".
Once I figure out how to do this, my next goal will be to "implement" CIRCLE command with .NET.
Thanks for your help.
Sorry for misunderstanding Gilles, I thought of the arc which is being shown while picking up the next point of the line (in LINE command) (it's AutoCAD 2020)
I'm still quite new in API, so at the moment I suppose that I would have to use EntityJig for this "effect".
Once I figure out how to do this, my next goal will be to "implement" CIRCLE command with .NET.
Thanks for your help.
Here's a sample to start with 'dynamic dimensions'.
You can google for 'DynamicDimensionDataCollection' to get more advanced examples.
[CommandMethod("TEST")] public static void Test() { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; var options = new PromptPointOptions("\nSpecify start point: "); var result = ed.GetPoint(options); if (result.Status != PromptStatus.OK) return; var startPoint = result.Value; using (var tr = db.TransactionManager.StartTransaction()) using (var line = new Line(startPoint, startPoint)) { line.TransformBy(ed.CurrentUserCoordinateSystem); var jig = new LineJig(line); var pr = ed.Drag(jig); if (pr.Status == PromptStatus.OK) { var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); curSpace.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); } tr.Commit(); } } class LineJig : EntityJig { Line line; Point3d startPt, dragPt; DynamicDimensionDataCollection dynDimDataCol; public LineJig(Line line) : base(line) { this.line = line; startPt = line.StartPoint; dynDimDataCol = new DynamicDimensionDataCollection(); var angleDim = new LineAngularDimension2 { DynamicDimension = true }; var angleDynDim = new DynamicDimensionData(angleDim, false); dynDimDataCol.Add(angleDynDim); var lengthDim = new AlignedDimension { DynamicDimension = true }; var lengthDynDim = new DynamicDimensionData(lengthDim, false); dynDimDataCol.Add(lengthDynDim); } protected override SamplerStatus Sampler(JigPrompts prompts) { var options = new JigPromptPointOptions("\nSpecify end point: "); options.UserInputControls = UserInputControls.Accept3dCoordinates; var result = prompts.AcquirePoint(options); if (result.Value.IsEqualTo(dragPt)) return SamplerStatus.NoChange; dragPt = result.Value; return SamplerStatus.OK; } protected override bool Update() { var ed = Application.DocumentManager.MdiActiveDocument.Editor; double height; using (var view = ed.GetCurrentView()) { height = view.Height / 20.0; } line.EndPoint = dragPt; var direction = startPt.GetVectorTo(dragPt).GetNormal() * height; var angleDim = (LineAngularDimension2)dynDimDataCol[0].Dimension; var lengthDim = (AlignedDimension)dynDimDataCol[1].Dimension; lengthDim.XLine1Point = startPt; lengthDim.XLine2Point = dragPt; if (Math.PI < line.Angle) { angleDim.XLine1Start = startPt; angleDim.XLine1End = dragPt; angleDim.XLine2Start = startPt; angleDim.XLine2End = startPt + Vector3d.XAxis * line.Length * 0.01; angleDim.ArcPoint = startPt + line.Length * Vector3d.XAxis.RotateBy((line.Angle + 2 * Math.PI) / 2, Vector3d.ZAxis); lengthDim.DimLinePoint = startPt + direction.RotateBy(Math.PI * 1.5, Vector3d.ZAxis); } else { angleDim.XLine1Start = startPt; angleDim.XLine1End = startPt + Vector3d.XAxis * line.Length * 0.01; angleDim.XLine2Start = startPt; angleDim.XLine2End = dragPt; angleDim.ArcPoint = startPt + line.Length * Vector3d.XAxis.RotateBy(line.Angle / 2, Vector3d.ZAxis); lengthDim.DimLinePoint = startPt + direction.RotateBy(Math.PI * 0.5, Vector3d.ZAxis); } return true; } protected override DynamicDimensionDataCollection GetDynamicDimensionData(double dimScale) { base.GetDynamicDimensionData(dimScale); return dynDimDataCol; } }
Here's a sample to start with 'dynamic dimensions'.
You can google for 'DynamicDimensionDataCollection' to get more advanced examples.
[CommandMethod("TEST")] public static void Test() { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; var options = new PromptPointOptions("\nSpecify start point: "); var result = ed.GetPoint(options); if (result.Status != PromptStatus.OK) return; var startPoint = result.Value; using (var tr = db.TransactionManager.StartTransaction()) using (var line = new Line(startPoint, startPoint)) { line.TransformBy(ed.CurrentUserCoordinateSystem); var jig = new LineJig(line); var pr = ed.Drag(jig); if (pr.Status == PromptStatus.OK) { var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); curSpace.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); } tr.Commit(); } } class LineJig : EntityJig { Line line; Point3d startPt, dragPt; DynamicDimensionDataCollection dynDimDataCol; public LineJig(Line line) : base(line) { this.line = line; startPt = line.StartPoint; dynDimDataCol = new DynamicDimensionDataCollection(); var angleDim = new LineAngularDimension2 { DynamicDimension = true }; var angleDynDim = new DynamicDimensionData(angleDim, false); dynDimDataCol.Add(angleDynDim); var lengthDim = new AlignedDimension { DynamicDimension = true }; var lengthDynDim = new DynamicDimensionData(lengthDim, false); dynDimDataCol.Add(lengthDynDim); } protected override SamplerStatus Sampler(JigPrompts prompts) { var options = new JigPromptPointOptions("\nSpecify end point: "); options.UserInputControls = UserInputControls.Accept3dCoordinates; var result = prompts.AcquirePoint(options); if (result.Value.IsEqualTo(dragPt)) return SamplerStatus.NoChange; dragPt = result.Value; return SamplerStatus.OK; } protected override bool Update() { var ed = Application.DocumentManager.MdiActiveDocument.Editor; double height; using (var view = ed.GetCurrentView()) { height = view.Height / 20.0; } line.EndPoint = dragPt; var direction = startPt.GetVectorTo(dragPt).GetNormal() * height; var angleDim = (LineAngularDimension2)dynDimDataCol[0].Dimension; var lengthDim = (AlignedDimension)dynDimDataCol[1].Dimension; lengthDim.XLine1Point = startPt; lengthDim.XLine2Point = dragPt; if (Math.PI < line.Angle) { angleDim.XLine1Start = startPt; angleDim.XLine1End = dragPt; angleDim.XLine2Start = startPt; angleDim.XLine2End = startPt + Vector3d.XAxis * line.Length * 0.01; angleDim.ArcPoint = startPt + line.Length * Vector3d.XAxis.RotateBy((line.Angle + 2 * Math.PI) / 2, Vector3d.ZAxis); lengthDim.DimLinePoint = startPt + direction.RotateBy(Math.PI * 1.5, Vector3d.ZAxis); } else { angleDim.XLine1Start = startPt; angleDim.XLine1End = startPt + Vector3d.XAxis * line.Length * 0.01; angleDim.XLine2Start = startPt; angleDim.XLine2End = dragPt; angleDim.ArcPoint = startPt + line.Length * Vector3d.XAxis.RotateBy(line.Angle / 2, Vector3d.ZAxis); lengthDim.DimLinePoint = startPt + direction.RotateBy(Math.PI * 0.5, Vector3d.ZAxis); } return true; } protected override DynamicDimensionDataCollection GetDynamicDimensionData(double dimScale) { base.GetDynamicDimensionData(dimScale); return dynDimDataCol; } }
Can't find what you're looking for? Ask the community or share your knowledge.