Hi anyone
Although having a good knowledge of AutoCAD since AutoCAD 2000, I don't know much about ACAD.NET.
I'd simply like to learn using object snap for construction purposes within VB.NET.
Starting with two polylines 'acPoly1' and 'acPoly2' I'd like to generate a third polyline 'acPolyMidPoints' from the midpoint of 'acPoly1' to the midpoint of 'acPoly2'. How can I do this using AutoCAD object snap?
I found something called "GetObjectSnapPoints..." but don't know how it works.
Could somebody help me with the lines of code necessary for this small example?
Thanks in advance!
= = = = =
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim acPoly1 As Polyline = New Polyline()
acPoly1.AddVertexAt(0, New Point2d(0, 0), 0, 0, 0)
acPoly1.AddVertexAt(1, New Point2d(0, 10), 0, 0, 0)
acBlkTblRec.AppendEntity(acPoly1)
acTrans.AddNewlyCreatedDBObject(acPoly1, True)
Dim acPoly2 As Polyline = New Polyline()
acPoly2.AddVertexAt(0, New Point2d(10, 0), 0, 0, 0)
acPoly2.AddVertexAt(1, New Point2d(10, 10), 0, 0, 0)
acBlkTblRec.AppendEntity(acPoly2)
acTrans.AddNewlyCreatedDBObject(acPoly2, True)
acTrans.Commit()
= = = = =
Firstly, in spite the name of this forum (Visual Basic Customization), this forum is traditionally for AutoCAD VBA discussion. For .NET API questions, such as yours, would get better chance being responded.
To your question. You may want to better describe what you want to do and what you expect the user to do when running your code and why you need to use Object Snap.
In your code, as you described, you have 2 segments of lines, and then you need to construct another line that touches the mid-point of thoese 2 lines. If you contruct the third line with code, why you need Object Snap, which is meant to provide user some visual hint/convenience for the potential points they may use? After the first 2 line segments are created, you have already known the 2 mid-points mathematically, and you can go ahead to create the third line.
If the third line has to be created by user, you would use Editor.GetPoint() to let user to pick. In this case, AutoCAD would automatically show Object Snap (if it is enabled, or you can code it to enable/disable it. Better let user decides).
Finally, you can look into Editor.Snap().
Norman Yuan