EvilSi Posted April 27, 2009 Share Posted April 27, 2009 Hello there, I want to convert a load of polylines into 3D polylines, in vanilla autocad. I have the 2d polylines drawn with xyz co-ordinates and I want to import them into Infoworks to define river cross-sections. However, infoworks doesn't recognise these objects - it only recognises bona-fide 3dpolylines. Surprisingly, I haven't managed to find a lisp routine that converts polylines (with 3d values) into actual 3dpolylines. Any help? Quote Link to comment Share on other sites More sharing options...
NBC Posted April 27, 2009 Share Posted April 27, 2009 In AutoCAD polylines can only ever be 2d, in that the endpoints of each portion of the polyline will always share the exact same z co-ordinate as each other. So even if you tried to somehow convert a 2d polyline to a 3d polyline, the mere fact that polylines share z values would still mean it is a 2d polyline. Having said that, different polylines can have different z values. In the same way that contours on a map all show, in effect, 2d polylines all at different z values. Quote Link to comment Share on other sites More sharing options...
EvilSi Posted April 27, 2009 Author Share Posted April 27, 2009 These polylines were originally drawn in 2d, however, I have 3d rotated them so that they represent the true shape of the cross-section, in the right place in space. When you list this polyline, it just says it is a polyline, although each vertex has a different z value. I need to convert them into offical 3dpolylines, without just tracing over each one with a new 3dpoly. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 27, 2009 Share Posted April 27, 2009 Could you post an example please? I may be able to write a LISP that will trace over the 2D polylines with a 3D poly, which may work for you? Quote Link to comment Share on other sites More sharing options...
EvilSi Posted April 27, 2009 Author Share Posted April 27, 2009 Aha - good idea! I attach one of the sections, in its position after I have 3drotated it. The red line is a polyline and this is the one I need to be converted to an actual 3dpolyline. Thanks for your help! 2dpl demo.dwg Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 27, 2009 Share Posted April 27, 2009 I've got this, it should incorporate the 3D rotation, but I don't think it does for some reason (defun c:cPoly (/ lwPoly vLst eLst) (vl-load-com) (if (and (setq lwPoly (car (entsel "\nSelect LWPolyline: "))) (eq "LWPOLYLINE" (cdr (assoc 0 (entget lwPoly))))) (progn (setq vLst (mapcar '(lambda (x) (append x '(0.0))) (mapcar 'cdr (vl-remove-if-not '(lambda (x) (eq 10 (car x))) (setq eLst (entget lwPoly)))))) (entmake (list '(0 . "POLYLINE") (cons 8 (cdr (assoc 8 eLst))) '(66 . 1) '(100 . "AcDb3dPolyline") '(70 . (cons 210 (cdr (assoc 210 eLst))))) (while vLst (entmake (list (cons 0 "VERTEX") '(100 . "AcDb3dPolylineVertex") '(70 . 32) (cons 10 (car vLst)))) (setq vLst (cdr vLst))) (entmake '((0 . "SEQEND"))) ;(entdel lwPoly)) ; Remove to Keep Original ) (princ "\n<!> No LWPolyline Selected <!>")) (princ)) Quote Link to comment Share on other sites More sharing options...
EvilSi Posted April 27, 2009 Author Share Posted April 27, 2009 ooh - nice try! That does work for converting plines that are on the xy plane, but not on the ones I've already 3Drotated. I should have asked the question before I wenthrough and rotated all these polyline sections - that would have been perfect! Thanks again for your help here! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 27, 2009 Share Posted April 27, 2009 I'm not sure why it doesn't put the new 3dpolylines in the right plane though, as I use the extrusion vector (code 210) from the original LW polyline to create the new 3dpolyline - yet when I check the extrusion vector in the new 3dPolyline, it is back to the XY plane. Quote Link to comment Share on other sites More sharing options...
scj Posted April 27, 2009 Share Posted April 27, 2009 Try out PEDIT3D.lsp from http://www.black-cad.de It should do the job. Good luck! Jochen Quote Link to comment Share on other sites More sharing options...
EvilSi Posted April 27, 2009 Author Share Posted April 27, 2009 Wow - impressive stuff! That worked perfectly, thank you. Quote Link to comment Share on other sites More sharing options...
SEANT Posted April 27, 2009 Share Posted April 27, 2009 It looks like I may be a bit late; I imagine the PEDIT3D.lsp will give some pointers as to how AutoCAD treats LWPoly coords aligned to UCS’s other than WCS. I put together this VBA routine (my understanding of lisp is a bit lacking) to accommodate the “other-world-ly” orientations. Option Explicit Sub lw23d() Dim intCode(0) As Integer Dim varData(0) As Variant Dim dblNorm() As Double Dim dblElev As Double Dim entLW As AcadLWPolyline Dim ent3d As Acad3DPolyline Dim blnClosed As Boolean Dim varCoords As Variant Dim i As Long Dim intbound As Long Dim varTemp As Variant Dim dblTemp(2) As Double Dim dbl3DCoords() As Double intCode(0) = 0: varData(0) = "LWPOLYLINE" If SoSSS(intCode, varData) > 0 Then For Each entLW In ThisDrawing.SelectionSets.Item("TempSSet") dblNorm = entLW.Normal dblElev = entLW.Elevation blnClosed = entLW.Closed intbound = ((UBound(entLW.Coordinates) + 1) / 2) - 1 ReDim dbl3DCoords(((intbound + 1) * 3) - 1) For i = 0 To intbound varTemp = entLW.Coordinate(i) dblTemp(0) = varTemp(0) dblTemp(1) = varTemp(1) dblTemp(2) = dblElev varTemp = ThisDrawing.Utility.TranslateCoordinates(dblTemp, acOCS, acWorld, 0, dblNorm) dbl3DCoords(i * 3) = varTemp(0) dbl3DCoords(i * 3 + 1) = varTemp(1) dbl3DCoords(i * 3 + 2) = varTemp(2) Next Set ent3d = ThisDrawing.ModelSpace.Add3DPoly(dbl3DCoords) ent3d.Closed = blnClosed Next End If End Sub Sub SSClear() Dim SSS As AcadSelectionSets On Error Resume Next Set SSS = ThisDrawing.SelectionSets If SSS.Count > 0 Then SSS.Item("TempSSet").Delete End If End Sub Function SoSSS(Optional grpCode As Variant, Optional dataVal As Variant) As Integer Dim TempObjSS As AcadSelectionSet SSClear Set TempObjSS = ThisDrawing.SelectionSets.Add("TempSSet") 'pick selection set If IsMissing(grpCode) Then TempObjSS.SelectOnScreen Else TempObjSS.SelectOnScreen grpCode, dataVal End If SoSSS = TempObjSS.Count End Function Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.