Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with code

Status
Not open for further replies.

hoja

Technical User
Dec 3, 2003
102
US
Hi, I wrote some code but it doesn't work. What I want to acomplish is that by the user typing in one # into a text box, this would automatically insert a rectangle into model space, by the same width all the time. so if you type in 20, this would automatically draw a rec that's 20 by the default 100 number. If you type 50, it would draw a rec that's 50 by 100. So far i have this code; Can someone help!

Private Sub cmdDim_Click()
Dim line As AcadLine
Dim ob
ob = ThisDrawing.ModelSpace.AddLine
line.StartPoint = txtDim.text
line.EndPoint = 100
End Sub
 
Hi,

Try this instead. It makes a 1 polyline rectangle instead of using 4 lines. Just a little less code involvment..

Code:
Private Sub cmdDim_Click()

Dim PlineX As AcadPolyline  'Polyline..
Dim PointsX(0 To 11) As Double  'Points array for Polyline co-ordinates..
Dim DimX As Double  'Dimension taken from txtDim..

DimX = txtDim.Text  'DimX is taken from textbox value..

' Set Pointsx values and co-ordinates..
PointsX(0) = 0: PointsX(1) = 0: PointsX(2) = 0
PointsX(3) = 0 + DimX: PointsX(4) = 0: PointsX(5) = 0
PointsX(6) = 0 + DimX: PointsX(7) = 0 + DimX: PointsX(8) = 0
PointsX(9) = 0: PointsX(10) = 0 + DimX: PointsX(11) = 0

Set PlineX = ThisDrawing.ModelSpace.AddPolyline(PointsX)  'Draw the polyline using the pointsX co-ordinates..
PlineX.Closed = True  'Close the polyline..

End Sub

This is based on a starting point of the World UCS 0,0,0 co-ordinate..
You can also use the GetPoint fucntion to allow the user to select the start point themselves from AutoCAD. If you want, email me @ help@bpdesignz.com and I'll send you the code and instructions..


I hope this helps..

Cheers,

Paul @ basepoint designz..


basepoint designz
renegade@bpdesignz.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top