draw poly by getpoint , how to pass coords

Discussion in 'AutoCAD' started by John Coon, Jan 31, 2004.

  1. John Coon

    John Coon Guest

    Help from the group,
    Can someone explain why the line "Set polyObj =
    ThisDrawing.ModelSpace.AddPolyline(startpoint)(endpoint) " does not pickup
    the startpoint or endpoint coordinates collected by the getpoints. I'm
    looking to draw a polyline that will be offset later on in the routine. I'm
    using the startpoint as the first point (start)of the polyline and the
    endpoint as the second point (end) of the placement of the ployline.

    can you not pass a double with a polyline? or have I just made a mess of
    this?


    Sub drawpoly()
    Dim polyObj As AcadPolyline
    Dim varDataPnt1 As Variant
    Dim varDataPnt2 As Variant
    Dim dbldir As Double

    varDataPnt1 = ThisDrawing.Utility.GetPoint(, "Select First Threshold point:
    ")
    Dim startpoint(0 To 2) As Double
    startpoint(0) = varDataPnt1(0)
    startpoint(1) = varDataPnt1(1)
    varDataPnt1(2) = 0

    MsgBox "The Northing Easting Point Location:" & vbCrLf & _
    " Northing: " & varDataPnt1(1) & vbCrLf & _
    " Easting: " & varDataPnt1(0) & vbCrLf & vbCrLf & _
    " Direction: " & dbldir, vbInformation, "Approach Data"

    varDataPnt2 = ThisDrawing.Utility.GetPoint(, "Select Second Threshold point:
    ")
    Dim endpoint(0 To 2) As Double
    endpoint(0) = varDataPnt2(0)
    endpoint(1) = varDataPnt2(1)
    varDataPnt2(2) = 0

    MsgBox "The Northing Easting Point Location:" & vbCrLf & _
    " Northing: " & varDataPnt2(1) & vbCrLf & _
    " Easting: " & varDataPnt2(0) & vbCrLf & vbCrLf & _
    " Direction: " & dbldir, vbInformation, "Approach Data"
    Set polyObj = ThisDrawing.ModelSpace.AddPolyline(startpoint)(endpoint)
    polyObj.Update

    End Sub
     
    John Coon, Jan 31, 2004
    #1
  2. John Coon

    SpeedCAD Guest

    Hi...

    You need an ARRAY to draw the Polyline. Example:

    Private Sub Dibujar2DPolilinea()
    Dim polyObj As AcadPolyline
    Dim varDataPnt1 As Variant
    Dim varDataPnt2 As Variant
    Dim dbldir As Double
    Dim verPL() As Double
    Form1.Hide
    AppActivate autocadApp.Caption
    varDataPnt1 = autocadApp.ActiveDocument.Utility.GetPoint(, vbCr & "Select First Threshold point: ")
    varDataPnt2 = autocadApp.ActiveDocument.Utility.GetPoint(varDataPnt1, vbCr & "Select Second Threshold point: ")
    ReDim verPL(5)
    verPL(0) = varDataPnt1(0): verPL(1) = varDataPnt1(1): verPL(2) = varDataPnt1(2)
    verPL(3) = varDataPnt2(0): verPL(4) = varDataPnt2(1): verPL(5) = varDataPnt2(2)
    Set polyObj = autocadApp.ActiveDocument.ModelSpace.AddPolyline(verPL)
    Form1.Show
    End Sub

    But is better draw a LWPolyline ;).

    Private Sub DibujarLWPolilinea()
    Dim polyObj As AcadLWPolyline
    Dim varDataPnt1 As Variant
    Dim varDataPnt2 As Variant
    Dim dbldir As Double
    Dim verPL() As Double
    Form1.Hide
    AppActivate autocadApp.Caption
    varDataPnt1 = autocadApp.ActiveDocument.Utility.GetPoint(, vbCr & "Select First Threshold point: ")
    varDataPnt2 = autocadApp.ActiveDocument.Utility.GetPoint(varDataPnt1, vbCr & "Select Second Threshold point: ")
    ReDim verPL(3)
    verPL(0) = varDataPnt1(0): verPL(1) = varDataPnt1(1)
    verPL(2) = varDataPnt2(0): verPL(3) = varDataPnt2(1)
    Set polyObj = autocadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(verPL)
    Form1.Show
    End Sub

    NOTE: To AddPolyline you need too the coordinate 3D (Z=0). To AddLightWeightPolyline you need only 2D coordinates.

    Un saludo de SpeedCAD... :)
    CHILE
    FORO: http://www.hispacad.com/foro
     
    SpeedCAD, Jan 31, 2004
    #2
  3. John Coon

    Jeff Mishler Guest

    John,
    It's best to use a LWpoly in place of the old-style polylines. But either
    way, you need to pass the Add... method an array of coordinates. The
    polyline requires 3 ordinates for each vertex (x,y,z) and the LWpoly only
    requires 2 (x,y).
    Modifying your code for the LWpline, and removeing the msgbox portion, will
    give you this:

    Sub drawpoly()
    Dim polyObj As AcadLWPolyline
    Dim varDataPnt1 As Variant
    Dim varDataPnt2 As Variant
    Dim coordList() As Double
    Dim dbldir As Double

    varDataPnt1 = ThisDrawing.Utility.GetPoint(, "Select First Threshold point:
    ")
    ReDim coordList(0 To 1)
    coordList(0) = varDataPnt1(0)
    coordList(1) = varDataPnt1(1)

    varDataPnt2 = ThisDrawing.Utility.GetPoint(varDataPnt1, "Select Second
    Threshold point: ")
    ReDim Preserve coordList(0 To 3)
    coordList(2) = varDataPnt2(0)
    coordList(3) = varDataPnt2(1)

    Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(coordList)

    HTH,
    Jeff

    End Sub
     
    Jeff Mishler, Jan 31, 2004
    #3
  4. John Coon

    John Coon Guest

    Jeff,

    As always thank you for your help!
    Your correct, all I needed was the LWpoly. So to pass the coords to the
    LWpoly points you must create a list.
    How do you guys remember all this. How long have you been writing vb code?

    John Coon
     
    John Coon, Jan 31, 2004
    #4
  5. John Coon

    Jeff Mishler Guest

    Remember? Remember what? I have a telepathic relationship with my keyboard,
    specifically the F1 key......really I don't remember hitting it for at least
    6 months, and yet the Help is always there... :)

    I started playing with the VBA stuff about a year ago. And that's pretty
    much all I still do, play....

    Glad I could help,
    Jeff
     
    Jeff Mishler, Jan 31, 2004
    #5
  6. John Coon

    John Coon Guest

    hope I can progress as you have.
    Thanks
    John coon
     
    John Coon, Feb 1, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.