Hi All
Can anyone tell me were I am going wrong ,it returns a mismatch?
thanks in advance
Private Sub CommandButton6_Click()
Dim plineObj As AcadLWPolyline
Dim pts(0 To 7) As Double
Me.Hide
pts(1) = ThisDrawing.Utility.GetPoint(, "Pick lowerleft Corner")
pts(2) = Val(TextBox63.Text): pts(2) = Val(TextBox64.Text)
pts(4) = Val(TextBox65.Text): pts(5) = Val(TextBox66.Text)
pts(6) = Val(TextBox67.Text): pts(7) = Val(TextBox68.Text)
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
plineObj.Closed = True
End Sub
Solved! Go to Solution.
Solved by grobnik. Go to Solution.
Hi @Anonymous
First of all you sized Dim pts(0 To 7) As Double so the variable name is pts, and sized for 8 rows (0 to 7).
later you assign value:
pts(1) = ThisDrawing.Utility.GetPoint(, "Pick lowerleft Corner")
pts(2) = Val(TextBox63.Text): pts(2) = Val(TextBox64.Text)
pts(4) = Val(TextBox65.Text): pts(5) = Val(TextBox66.Text)
pts(6) = Val(TextBox67.Text): pts(7) = Val(TextBox68.Text)
but you start from 1, without assigning the 0 array rows, and 2nd row it's has been assigned 2 times with different value I guess pts(2) = Val(TextBox64.Text) and pts(2)= Val(TextBox63.Text)
then you insert the polyline, by using the variable POINTS, instead pts
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(pts)
It's so easy or something it's wrong in my understanding ?
Let me know
Regards
Hi
Apologies I rushed the code out, and never checked it.I think I have corrected it,but still not getting it to run
Private Sub CommandButton6_Click()
Dim plineObj As AcadLWPolyline
Dim pts(0 To 😎 As Double
Dim pt As Variant
Me.Hide
pts(0) = ThisDrawing.Utility.GetPoint(, "Pick lowerleft Corner")
pts(1) = Val(TextBox63.Text): pts(2) = Val(TextBox64.Text)
pts(3) = Val(TextBox65.Text): pts(4) = Val(TextBox66.Text)
pts(5) = Val(TextBox67.Text): pts(6) = Val(TextBox68.Text)
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(pts)
plineObj.Closed = True
End Sub
Ok,
Some error messagge displayed?? No line drawn ?? Try to run the code step by step F8 checkining all coords values, x,y,z, the text conversion and so on. On my side I'll do the same.
With text conversion I mean :
You input data in a text box on the form, so return a string.
The coordinates array an later vertex of polyline require a number double format, so you convert the text to number by val function
This is what I mean with text conversion.
Hi Chris @Anonymous
Private Sub CommandButton6_Click()
Dim plineObj As AcadLWPolyline
Dim pts(0 To 5) As Double
Dim Point(0 To 11) As Double
Dim pt As Variant
Me.Hide
pt = ThisDrawing.Utility.GetPoint(, "Pick lowerleft Corner")
pts(0) = Val(TextBox63.Text): pts(1) = Val(TextBox64.Text)
pts(2) = Val(TextBox65.Text): pts(3) = Val(TextBox66.Text)
pts(4) = Val(TextBox67.Text): pts(5) = Val(TextBox68.Text)
Point(0) = pt(0)
Point(1) = pt(1)
Point(2) = pt(2)
Point(3) = pts(0)
Point(4) = pts(1)
Point(5) = 0
Point(6) = pts(2)
Point(7) = pts(3)
Point(8) = 0
Point(9) = pts(4)
Point(10) = pts(5)
Point(11) = 0
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(Point)
plineObj.Closed = True
End sub
The main issue was into Getpoint, which return an array of 3 points coordinates, so you cannot assign to a single array point.
So what I have done is:
- Assign a different array to get point,
- Copy value from text box
- Include z coord
- pass the coordinates to polyline.
Should be work now
Thank you for your hard work,I think you are correct about the getpoint
I put a measurement of 0-555 555-555 555-0 in the textboxes, its drawing to screen at 0,0 and not from base point I am working on this at the moment.
Hi Chris, @Anonymous
Do not forget to insert also Z coordinate, even if do not used, shall be set to 0, as I show you.
So when you retrive data from text box, I guess you are inserting X, and Y coords, but as I show you before you have to insert Z value too, then pass to insert LWPolyline every vertex as 3 points coords.
Hi have I got this right as i am not getting anything draw on screen?
Private Sub CommandButton7_Click()
Dim plineObj As AcadLWPolyline
Dim pts(0 To 5) As Double
Dim Point(0 To 11) As Double
Dim pt As Variant
Me.Hide
pt = ThisDrawing.Utility.GetPoint(, "Pick lowerleft Corner")
Point(0) = pt(0) = Val(TextBox63.Text)
Point(1) = pt(1) = Val(TextBox64.Text)
Point(2) = 0
Point(3) = pts(0) = Val(TextBox65.Text)
Point(4) = pts(1) = Val(TextBox66.Text)
Point(5) = 0
Point(6) = pts(2) = Val(TextBox67.Text)
Point(7) = pts(3) = Val(TextBox68.Text)
Point(8) = 0
Point(9) = pts(4)
Point(10) = pts(5)
Point(11) = 0
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(Point)
plineObj.Closed = True
End Sub
Hi Chris @Anonymous
Private Sub CommandButton7_Click()
Dim plineObj As AcadLWPolyline
Dim pt() As Double
Me.Hide
pt = ThisDrawing.Utility.GetPoint(, "Pick lowerleft Corner")
ReDim Preserve pt(0 To 15) As Double
pt(3) = Val(TextBox63.Text)
pt(4) = Val(TextBox64.Text)
pt(5) = 0
pt(6) = Val(TextBox65.Text)
pt(7) = Val(TextBox66.Text)
pt(8) = 0
pt(9) = Val(TextBox67.Text)
pt(10) = Val(TextBox68.Text)
pt(11) = 0
pt(12) = 0 'pts(4)
pt(13) = 90 ' pts(5)
pt(14) = 100
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(pt)
plineObj.Closed = True
End Sub
First of all, it's useful to use the same variable for coordinates, in order to avoid confusion, so I used getpoint return coordinates into pt variabile and then I used the same pt array variable with Redim Preserve option in order to maintain the coordinates obtained from Getpoint and assign text boxes contents for other array variable rows.
Delete all previously declaration and insert only Dim pt() As Double:
'Dim pts(0 To 5) As Double'Dim Point(0 To 11) As Double
As second issue, the AddLightWeightPolyline require the coordinates array sized as multiple of three, otherwise you got an error, this is the reason due to I sized the array 0 to 15.
Finally I don't understand pts(4) and pts(5) so I inserted some random number, I guess they are coming from some other parts of code, in case check the declaration method.
See above the image result.
Hi thanks again I am struggling to place the shape and close it,I think the code is being dragged back to the 0,0 Point when placed on screen?
With this code (It is Polar but as an example)it places the rectangle on screen and closes the shape back to first point
Private Sub CommandButton4_Click()
pi = 3.xxx-xxxxxxxx
Me.Hide
pt1 = ThisDrawing.Utility.GetPoint(, "Pick lowerleft Corner")
pt2 = ThisDrawing.Utility.PolarPoint(pt1, 0, Val(TextBox53.Text))
pt3 = ThisDrawing.Utility.PolarPoint(pt2, pi / 2, Val(TextBox54.Text))
pt4 = ThisDrawing.Utility.PolarPoint(pt1, pi / 2, Val(TextBox54.Text))
ThisDrawing.ModelSpace.AddLine pt1, pt2
ThisDrawing.ModelSpace.AddLine pt2, pt3
ThisDrawing.ModelSpace.AddLine pt3, pt4
ThisDrawing.ModelSpace.AddLine pt4, pt1
End Sub
Hi Chris @Anonymous ,
Really I'm confused, I can support you if you explain me what you have to do.
If your shape It's no regular shall be used a pline otherwhise could be used a rectangulare shape without problem of close that. We cannot modify the code everytime.
Let me know perhaps a sample dwg could be useful to share.
Hi sorry to confuse the situation, what I want to do is basically is to make a shape its not 90 degree and to place it anywhere on screen with the getpoint 1st picture I don't want it to snap back to 0,0 which it keeps doing Second picture hope that makes sense
Many thanks for your help
Hi Chris @Anonymous ,
I'm very sorry, after further investigation the coordinates of a lwpolyline are 2D not 3D as I wrote.
Here below an example of closed polyline with getpoint, please note that you can input data directly on getpoint pointer if you need.
Sub Example_AddLightWeightPolyline()
' This example creates a lightweight polyline in model space.
Dim plineObj As AcadLWPolyline
Dim points(0 To 7) As Double
' Define the 2D polyline points
pt = ThisDrawing.Utility.GetPoint(, "Pick lowerleft Corner")
points(0) = pt(0): points(1) = pt(1)
points(2) = 1: points(3) = 2
points(4) = 3: points(5) = 2
points(6) = 3: points(7) = 1
' Create a lightweight Polyline object in model space
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
plineObj.Closed = True
ZoomAll
End Sub
So this should really works.
I'll offer you a drink for stress.
Bye
Hi Many thanks for this yes I think its working good,I just have to get the right direction to turn it into a sq or rectangle
I have to go out at the moment but will try it fully on return
Kind regards
Chris
Can't find what you're looking for? Ask the community or share your knowledge.