dbroada Posted April 16, 2013 Share Posted April 16, 2013 (edited) forgot to mention, this is in VB.Net. I need to draw a polyline between two selected points (and then do some stuff to it). What is my best way forwards? The book I am "learning" (you learn from your mistakes don't you) shows me how to manipulate 2d polylines and how to select 3d points. What I can't do is convert my 3d points into 2d ones. What am I missing? Edited April 16, 2013 by dbroada clarification added Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted April 16, 2013 Share Posted April 16, 2013 Are you saying you want to draw a 2D polyline, but you want to snap to 3D points and ignore the Z elevation? Quote Link to comment Share on other sites More sharing options...
dbroada Posted April 16, 2013 Author Share Posted April 16, 2013 That was quick! I have also just realised I missed out the important point that I am coding in VB.Net. (sorry) All I need is a 2d (z=0) polyline. [font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]Dim[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] myPline [/size][/font][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]As[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]New[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]Polyline[/color][/size][/font] [/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2]myPline.AddVertexAt(0, [/size][/font][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]New[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]Point2d[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2](0, 0), 0, 0, 0) [/size][/font][/size][/font][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000]' myStartPoint[/color][/size][/font] [/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2]myPline.AddVertexAt(1, [/size][/font][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]New[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]Point2d[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2](10, 10), 0, 0, 0) [/size][/font][/size][/font][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000]'myNextPoint[/color][/size][/font] [/color][/size][/font][/color][/size][/font] The only commands I (currently) know get me 3d points.... [font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]Dim[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] my3dStartPoint [/size][/font][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]As[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]Point3d[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] = DocumentManager.MdiActiveDocument.Editor.GetPoint([/size][/font][/size][/font][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515]"start "[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2]).Value[/size][/font] [/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]Dim[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] my2dStartPoint [/size][/font][/size][/font][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]As[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af][font=Consolas][size=2][color=#2b91af]Point2d[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2] = DocumentManager.MdiActiveDocument.Editor.GetPoint([/size][/font][/size][/font][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515][font=Consolas][size=2][color=#a31515]"start "[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2]).Value[/size][/font][/size][/font] The first one works, the second one doesn't. I am not sure if I am missing a simple conversion or if I have used the wrong components or have just missed a bit with my syntax. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 16, 2013 Share Posted April 16, 2013 Dave, The Value Property of EditorInput.PromptResult... Which is what is returned by Editor.GetPoint()... returns a Point3d, which is why your attempt to cast as Point2d fails. To obtain a single Point2d from a Point3d, consider using the X, and Y values of the Point3d to create a new Point2d. If you have List and want to convert to List, Tony offers some good advice here. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 16, 2013 Share Posted April 16, 2013 Here's a simple Extension Method for your use, that will allow you to immediately extract the Point2d from any Point3d Type (even from EditorInput.PromptResult.Value as I'll show below): namespace Autodesk.AutoCAD.Geometry { public static class Point3dExtensionMethods { public static Point2d GetPoint2d(this Point3d pt) { return new Point2d(pt.X, pt.Y); } } } ... And here's a quick example of it's use: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; [color="blue"]using Autodesk.AutoCAD.Geometry.Point3dExtensionMethods;[/color] namespace CADTutor.Sample.PointUtilities { class Foo { [CommandMethod("FOO")] void FOO() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptPointOptions opts = new PromptPointOptions(""); opts.Message = "\nSpecify a point: "; PromptPointResult ppr = ed.GetPoint(opts); if (ppr.Status == PromptStatus.OK) { Point3d pt = ppr.Value; ed.WriteMessage( "\n** [Point3d] = {0}, [Point2d] = {1} ** ", pt.ToString(), pt.[color="blue"]GetPoint2d()[/color].ToString() ); } } } } Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 16, 2013 Share Posted April 16, 2013 You may also find this ADNDevBlog article useful: Extension methods in AutoCAD 2013 Quote Link to comment Share on other sites More sharing options...
fixo Posted April 16, 2013 Share Posted April 16, 2013 Hi Dave, see simple code in attachment, this is an oldie but it's working for me yet loop_points.txt Quote Link to comment Share on other sites More sharing options...
dbroada Posted April 16, 2013 Author Share Posted April 16, 2013 thanks both, I'll have a proper look tomorrow when I get back to work. Yet again I didn't look for the simple solution of just dropping the z component of a 3d point! On the way home it occured to me that I would also have to work out how to "announce" that the pline should be closed - it looks like fixo has that already in his code. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 16, 2013 Share Posted April 16, 2013 Tony offers some good advice here. .......... For a simple conversion (e.g, Z = 0.0), don't use Convert2d() because it transforms the input point into the plane argument. It's more efficient to just return a new Point2d. Quote Link to comment Share on other sites More sharing options...
dbroada Posted April 17, 2013 Author Share Posted April 17, 2013 ..........I see, you are commenting on fixo's use of Convert2d(). I can see this will take a little time.... Quote Link to comment Share on other sites More sharing options...
BlackBox Posted April 17, 2013 Share Posted April 17, 2013 I see, you are commenting on fixo's use of Convert2d(). I can see this will take a little time.... That is correct... Fixo is one of my heroes, and I have learned a great deal from him (and am sure I will continue to do so in the future), I only ventured out on the branch of credibility to correct one of my heroes as a result of Tony's explicit comment regarding efficiency... Tony being someone both Fixo and I greatly respect. I certainly do not mean to sound argumentative, nor am I suggesting that Fixo's code is insufficient in any way (it obviously works), but given Tony's comments on efficiency, I chose to offer the above Extension Method. Feel free to use whatever you feel appropriate, as I am very much still a student. Cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.