basepointdesignz
Programmer
Hi all,
I've asked this question before, but had no real good replies from it to with VBA.. Now I got some of the code I'm constructing to show you..
The story so far is....
I'm trying to write a small VBA program that the user can use to get the area of any shape and then it'll format the results to show in metre-squared (this is for calculating floor area). So far I've got the 'Select Entity part down, which simply asks the user to select a polyline object already drawn, then the program displays the formatted result on the form, then if needed, the user can insert the result as Text..
The problem I have is that I'd like the user to be able to select as many point as required (will always be random) to draw the desired shape of the room or whatever. Then the progam draws a polyline using the points selected as it's vertexes and then get the area of the polyline. Then it deletes the polyline so all the user sees is the results..
What I can't do is set up the program to accept all the selected points into the vertex list for the polyline..
Anyway, here's a selection of the code. All it does so far is to add a AcadPoint at each selected point, then show the number of points (a msgbox purely for my purposes to show me that the code is working OK), then the polyline is only drawn from 0,0 to the last selected point!!
Anyway, any ideas would be very much appreciated..
Cheers,
Renegade..
BULLET-PROOF DESiGNZ
renegade@tiscali.co.uk
I've asked this question before, but had no real good replies from it to with VBA.. Now I got some of the code I'm constructing to show you..
The story so far is....
I'm trying to write a small VBA program that the user can use to get the area of any shape and then it'll format the results to show in metre-squared (this is for calculating floor area). So far I've got the 'Select Entity part down, which simply asks the user to select a polyline object already drawn, then the program displays the formatted result on the form, then if needed, the user can insert the result as Text..
The problem I have is that I'd like the user to be able to select as many point as required (will always be random) to draw the desired shape of the room or whatever. Then the progam draws a polyline using the points selected as it's vertexes and then get the area of the polyline. Then it deletes the polyline so all the user sees is the results..
What I can't do is set up the program to accept all the selected points into the vertex list for the polyline..
Anyway, here's a selection of the code. All it does so far is to add a AcadPoint at each selected point, then show the number of points (a msgbox purely for my purposes to show me that the code is working OK), then the polyline is only drawn from 0,0 to the last selected point!!
Code:
' SELECT AREA (BY POINTS)..
Private Sub CommandButton7_Click()
Dim pointx As AcadPoint 'Add an AcadPoint at each selected point, to show where user has already picked..
Dim ptx As Variant 'Point array (multiple if necessary)..
Dim polyXX As AcadLWPolyline ' Polyline to be drawn from the points array..
Dim countx As Integer 'Counter for loop..
Dim countxx As Double 'Counter value * 2 (to get correct point array numbers (X,Y))..
countx = 0 'Set counter to nothing..
areaform.hide 'Hide form to allow user to slect points from AutoCAD..
ptx = ThisDrawing.Utility.GetPoint(, "Pick the first point..") 'Getpoint method..
'*******************************
'** Start the point pick loop **
'*******************************
Do
countx = countx + 1 'Add 1 to the counter..
Set pointx = ThisDrawing.ModelSpace.AddPoint(ptx)
countxx = countx * 2 'Multiply count number by 2 (to get correct array numbers)..
ReDim Preserve ptx(0 To countxx - 1) 'Re-dimension the ptx variable..
ptx = ThisDrawing.Utility.GetPoint(, "Pick another point. (Press ENTER to get area)..") 'Getpoint method..
On Error GoTo END_DO 'Exit the loop if ENTER or another key is hit (basically an error)..
Loop
'*******************************
'******** End the loop *********
'*******************************
END_DO:
'Show number of points selected.
' (This is purely for code construction purposes to check that
' the correct number of points has been accounted for)..
MsgBox "Number of points selected is " & countx & ".."
Set polyXX = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptx) 'Draw a polyline from the points array..
areaform.Show 'Show the form again..
End Sub
Anyway, any ideas would be very much appreciated..
Cheers,
Renegade..
BULLET-PROOF DESiGNZ
renegade@tiscali.co.uk