Help with AddLightWeightPolyline

Discussion in 'AutoCAD' started by mgray, Jul 7, 2004.

  1. mgray

    mgray Guest

    I am trying to take an array of coordinates from a polyline add a value to each one and use the new array to draw a new polyline with AddLightWeightPolyline. I keep getting the following error:

    "Too few elements in safearray or total number of elements is not a multiple of three"

    I dont know what a safearray is and my new array is of a length that is a multiple of 3.

    Also why is it a multiple of 3 if the coordinates of LWPolyline only returns the x and y values but no z value.

    Any help and snipits would be great
     
    mgray, Jul 7, 2004
    #1
  2. mgray

    Jürg Menzi Guest

    mgray
    If you wanna add a new vertex to the polyline, I would suggest to use
    AddVertex method.

    Cheers
     
    Jürg Menzi, Jul 7, 2004
    #2
  3. mgray

    MP Guest

    perhaps posting the code would help finding the error

    each one and use the new array to draw a new polyline with
    AddLightWeightPolyline. I keep getting the following error:
    returns the x and y values but no z value.
     
    MP, Jul 7, 2004
    #3
  4. mgray

    mgray Guest

    Im trying to move all the points on the pline to new locations. I am not trying to add a vertex. See below. Thanks

    Sub mover()

    Dim plineObj As Variant
    Dim points() As Double

    ft = AreaObjsFilter("FilterType")
    fd = AreaObjsFilter("FilterData")

    Set ss = PowerSet("tempSS")
    ss.SelectOnScreen ft, fd

    For Each plineObj In ss
    ' Return all the coordinates of the polyline
    Dim retCoord As Variant
    retCoord = plineObj.Coordinates
    Dim y As Long
    y = 1

    Dim x As Variant
    For Each x In retCoord

    Debug.Print x
    ReDim points(y)
    points(y - 1) = x + 1.1
    y = y + 1
    Next

    ReDim points(y - 1)
    Debug.Print "Length " & UBound(points)

    ThisDrawing.ModelSpace.AddLightWeightPolyline (points)
    ThisDrawing.Regen True

    Next
    End Sub
     
    mgray, Jul 7, 2004
    #4
  5. Quick fix:
    retCoord = plineObj.Coordinates
    ReDim points(0 To UBound(retCoord)) 're-dim one time, to match the
    returned coordinates
    'ReDim points(y - 1) 'comment out this line

    Other ideas, ramblings, etc:
    -- When you re-dimmed points(y-1), you needed to use "ReDim Preserve"
    otherwise points() would be filled with zeroes
    -- I always like to specify both bounds when dimming so that my code does
    not run differently depending on "Option Base" setting
    -- If you are going to move all the vertices by the same amount for your
    final code, you could (I think) instead use .Copy and .Move to make a second
    polyline.

    Good luck,
    James
     
    James Belshan, Jul 7, 2004
    #5
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.