Flattening 3D splines

Discussion in 'AutoCAD' started by KeithXP, Dec 8, 2004.

  1. KeithXP

    KeithXP Guest

    Can anyone point me toward to routine that will successfully flatten 3D
    Splines.

    We sometimes get surveyors drawings with contours drawn this way, and
    neither FLATTEN nor another utility I have tried FLATTEN.LSP will work.

    thanks

    Keith
     
    KeithXP, Dec 8, 2004
    #1
  2. KeithXP

    mmm Guest

    I'm not sure why, it wouldn't be hard to generate a 2d spline
    I mean wouldn't you just step through all the vertices and trans the global
    to the current ucs, set the z to 0, and trans back to global.

    --
    Princess Jamie,

    Life shrinks or expands in proportion to one's courage.
    - Anais Nin

    | Can anyone point me toward to routine that will successfully flatten 3D
    | Splines.
    |
    | We sometimes get surveyors drawings with contours drawn this way, and
    | neither FLATTEN nor another utility I have tried FLATTEN.LSP will work.
    |
    | thanks
    |
    | Keith
    |
    |
    |
    |
     
    mmm, Dec 8, 2004
    #2
  3. KeithXP

    ADK Guest

    According to the follow website, they have a lisp routine that would help
    you ...there is a contact email on the page.
    http://ourworld.compuserve.com/homepages/johndavis/autocad.htm

    LEDIT.lsp

    Allows the following operations to be performed on sets of polylines:
    reverse direction; create a single polyline from two or more polylines (the
    endpoints of the polylines need not be touching); incline a 2d polyline
    using an elevation for the start of the line and a fixed gradient or
    endpoint elevation; flatten a 3d polyline to a 2d polyline.

    HTH
     
    ADK, Dec 8, 2004
    #3
  4. KeithXP

    Joe Burke Guest

    Keith,

    Assuming you mean flatten the control points of a spline, something like this might
    do the trick. Barely tested, and not exactly elegant.

    Joe Burke

    (defun c:FlattenSpline ( / ent vobj ctrlpts pt reslst )
    (setq ent (car (entsel "\nSelect spline: ")))
    (setq vobj (vlax-ename->vla-object ent))
    (setq ctrlpts (vlax-get vobj 'ControlPoints))
    ;(print ctrlpts)
    (repeat (/ (length ctrlpts) 3)
    (setq pt (list (car ctrlpts) (cadr ctrlpts) 0.0))
    (setq reslst (cons pt reslst))
    (setq ctrlpts (cdddr ctrlpts))
    )
    (setq reslst (apply 'append reslst))
    ;(print reslst)
    (vlax-put vobj 'ControlPoints reslst)
    (princ)
    )
     
    Joe Burke, Dec 8, 2004
    #4
  5. KeithXP

    Randy Howell Guest

    Flatten usually works. You may need to explode the spline once. There is an old command; CHANGE, Properties, Elev - set to 0.
     
    Randy Howell, Dec 8, 2004
    #5
  6. KeithXP

    KeithXP Guest

    Joe -

    Many thanks - it may not be 'elegant', but it works and gives enough
    information for an inexperienced lisper such as myself to modify it to do
    the FitPoints as well and loop it for a selection set. That's all I needed.

    Thanks very much.

    Keith
     
    KeithXP, Dec 8, 2004
    #6
  7. Hi Keith,

    Just for curiosity, why would you want to do this dumbing down of the data
    in the drawing?

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au
     
    Laurie Comerford, Dec 8, 2004
    #7
  8. KeithXP

    KeithXP Guest

    Laurie

    We would keep a copy of the 3D original. We are not using the 3D data for
    the particular tasks in hand and users find that they are unwittingly
    producing distorted 2D drawings by snapping to 3D points. (In turn getting
    all sorts of problems ranging from inability to fillet and trim lines which
    appear to be in the same plane but aren't becuase they have snapped to a 3D
    point, to inaccurate measures and dimensions etc).

    It has always amazed me that with Autocad you have to buy a 3rd party add on
    (as far as I know) such as Flatland, to force new geometry to 2D. Staff who
    have used Microstation tell me this part of the basic functionality of that
    program.

    Keith
     
    KeithXP, Dec 9, 2004
    #8
  9. KeithXP

    Joe Burke Guest

    Keith,

    You're welcome. Glad I could help.

    Forgive me if I'm stating the obvious. A word of caution if you use the code in a
    loop to process multiple splines. The reslst var may need to be reset (setq reslst
    nil) on each pass to avoid adding to an existing list.

    Joe Burke
     
    Joe Burke, Dec 9, 2004
    #9
  10. Hi Keith,

    Thanks. I never use splines, so had no idea what awkward creatures they
    are. It provided an interesting challenge.

    Here is some VBA code which will flatten all splines to zero. As always
    watch for word wrap.

    You can change the layers selected by replacing the "*" with something like:
    "Layer1,Layer2,MyLayer*"

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

    Sub FlattenSpline()
    Dim oSpline As AcadSpline
    Dim i As Long
    Dim ssObjects As AcadSelectionSet
    Dim vPt As Variant
    If SelectObjectsOnLayer(ssObjects, "SPLINE", "*") > 0 Then
    For Each oSpline In ssObjects
    With oSpline
    For i = 0 To .NumberOfFitPoints - 1
    vPt = .GetFitPoint(i)
    vPt(2) = 0
    .SetFitPoint i, vPt
    Next i
    .Update
    For i = 0 To .NumberOfControlPoints - 1
    vPt = .GetControlPoint(i)
    vPt(2) = 0
    .SetControlPoint i, vPt
    Next i
    End With
    Next
    End If

    End Sub

    ''''''''''''''''''''''''''''' '''''''''''''''''''
    Public Function SelectObjectsOnLayer(ssObs As AcadSelectionSet, spObjectType
    As String, spLayer As String) As Long
    On Error Resume Next
    Dim FilterType(0 To 1) As Integer
    Dim FilterData(0 To 1) As Variant
    Dim sNumber As String
    FilterType(0) = 0: FilterData(0) = spObjectType
    FilterType(1) = 8: FilterData(1) = spLayer
    ' The line below will create an error if the SSET doesn't exist
    ' or delete it if it does exist.
    ' The On Error will allow the program to continue and create the set
    ThisDrawing.SelectionSets.Item("SSET").Delete
    Set ssObs = ThisDrawing.SelectionSets.Add("SSET")
    ssObs.Select acSelectionSetAll, , , FilterType, FilterData
    SelectObjectsOnLayer = ssObs.Count
    Exit Function

    SOLErrorHandler:
    Err.Clear
    SelectObjectsOnLayer = 0
    End Function ' SelectObjectsOnLayer()
     
    Laurie Comerford, Dec 9, 2004
    #10
  11. KeithXP

    Joe Burke Guest

    Keith,

    A bit of trivia I noticed while playing with this. If a spline object containing
    control points at Z values other than zero is copied, the control points are
    automatically flattened. Of course, the same is not true for fit points.

    So to flatten control points given multiple splines, I think you could just copy the
    splines in-place, and delete the originals.

    Joe Burke
     
    Joe Burke, Dec 9, 2004
    #11
  12. I'm pretty sure that Fit points are computed, and the control
    points are the only thing you need to change.
     
    Tony Tanzillo, Dec 9, 2004
    #12
  13. Hi Tony,

    That would make sense as the first trials of the code didn't work and I had
    to swap the order of the two loops with which I processed the two groups of
    data.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au
     
    Laurie Comerford, Dec 10, 2004
    #13
  14. KeithXP

    KeithXP Guest

    Guys -

    thanks very much! I managed to modify the code kindly provided by Joe
    Burke, so that a selection set was processed. The routine processed the
    control points and then the fit points for each entity. Strangely, it would
    always flatten a single spline, but would seldom process a full selection
    set - maybe that was do with the order of processing control & fit points.

    Your routine looks rather more robust with the luxury of error handling (a
    bit beyond me to write!).

    Contributors to this NG have helped me so much over my decade of Autocad
    use. Thanks to everyone!

    Keith
     
    KeithXP, Dec 10, 2004
    #14
  15. KeithXP

    Joe Burke Guest

    Keith,

    I can't know without seeing your code. But I suspect the problem you mentioned, "it
    would always flatten a single spline..." might be caused by not paying attention to
    my message regarding resetting the reslst var to nil inside a loop.

    That would produce the effect you mentioned. The first spline would be processed as
    expected. The second spline and those following would fail because the number of
    points in reslst would accumulate. Thereby no longer corresponding to the number of
    points contained in a spline being processed, within a loop.

    Joe Burke
     
    Joe Burke, Dec 10, 2004
    #15
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.