VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using AutoCAD object snap within VB.NET

2 REPLIES 2
Reply
Message 1 of 3
surfer96
1086 Views, 2 Replies

Using AutoCAD object snap within VB.NET

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()

 

= = = = =

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: surfer96

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

Drive CAD With Code

EESignature

Message 3 of 3
surfer96
in reply to: norman.yuan

Hi Norman,



I think what you mean is the following:

code simply doesn?t match with the osnap concept. code generates geometry in
an abstract mathematical manner whereas osnap always needs a ?given? point
as the basis for a ?second? point to get snapped.

The ?given? point normally being determined by the actual cursor position on
the screen this doesn?t have much to do with programming. Is that right?



I always thought osnap was important for AutoCAD.NET programming, but now I
think this was a wrong assumption.



Thanks for your help

Alex

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost