Jump to content

Help with VBA getPoint and Line


Recommended Posts

Ok guys, so, besides Lisp, I'm also working with VBA for Autocad.

Imagine this. I have a form with 1 textBox and 2 buttons (ok, cancel).

When the user clicks ok, the numeric value inside the texBox is stored in a variable let's say 'A'. Then the form is hidden, the user clicks inside the draw space for a start point of the line - for this I use getpoint. I then set a second point at a distance of A (vertical dirrection) from the start point and want to draw a line. What I have done is something like


Private Sub CommandButton1_Click()
'Declare the variable used for getting the info from the textBox
   Dim ALength As Double
'Get the value from inside the textBox
   ALength = CDbl(TextBox1.Text)

'Point declaration
   Dim p0 As Variant
   Dim p1 As Variant
'Hide the form
'Get point from user
   p0 = ThisDrawing.Utility.GetPoint()
'Set second point
   p1 = p0
   p1(1) = p0(0) + ALength
'Draw the line
   Dim p0p1Line As AcadLine
   p0p1Line = ThisDrawing.Application.ActiveDocument.ModelSpace.AddLine(p0, p1)
End Sub


The problem is, it does not work. First of all, i have problems with getPoint, but i think i can get around them. Secondly, the 2nd point should be at ALength away from the first on the Y axis. This does not happen..If p0(1) is let's say 50 and ALength is 100, p1(1) should be 150, no? In my case it's 66 or 120 or 111.23. Why is that? Lastly, when it gets to p0p1Line=....I get an error (91) saying it's value is NOTHING, but if i click END, i still get a line drawn in ACAD. Any HELP?

Link to comment
Share on other sites

'Set second point

p1 = p0

p1(1) = p0(0) + ALength


Please take care that you are adding the displacement to coordinate X of p0 point. Shouldn't your code be instead:


'Set second point
   p1 = p0
   p1(1) = p(1) + ALength


Also, since it is about an object should use:


Set p0p1Line = ThisDrawing.Application.ActiveDocument.ModelSpace.AddLine(p0, p1)



Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...