Jump to content

Convert polylines to 3dpolylines


symoin

Recommended Posts

Hai all there,

 

I have a drawing with lots of points at different elevation (z) and the polylines are drawn as that they joins the points with osnap node. now I need to change those polylines to 3d polylines.

 

Is there any lisp or VBA programme to do this.

 

Help is always appericiated.

Link to comment
Share on other sites

Try something like this:

 

[color=#990099];;-------------=={ LWPolylines to 3D Polylines }==------------;;[/color]
[color=#990099];;                                                            ;;[/color]
[color=#990099];;  Converts a selection of LWPolylines to 3D Polylines.      ;;[/color]
[color=#990099];;------------------------------------------------------------;;[/color]
[color=#990099];;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;[/color]
[color=#990099];;------------------------------------------------------------;;[/color]

[color=RED]([/color][color=BLUE]defun[/color] c:LW3D [color=RED]([/color] [color=BLUE]/[/color] ss i elist z [color=RED])[/color] [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color]
 [color=#990099];; © Lee Mac 2011[/color]

 [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]setq[/color] ss [color=RED]([/color][color=BLUE]ssget[/color] [color=#a52a2a]"_:L"[/color] [color=DARKRED]'[/color][color=RED](([/color][color=#009900]0[/color] [color=DARKRED].[/color] [color=#a52a2a]"LWPOLYLINE"[/color][color=RED]))))[/color]
   
   [color=RED]([/color][color=BLUE]repeat[/color] [color=RED]([/color][color=BLUE]setq[/color] i [color=RED]([/color][color=BLUE]sslength[/color] ss[color=RED]))[/color]
     [color=RED]([/color][color=BLUE]entmakex[/color]
       [color=RED]([/color][color=BLUE]append[/color] [color=DARKRED]'[/color][color=RED](([/color][color=#009900]0[/color] [color=DARKRED].[/color] [color=#a52a2a]"POLYLINE"[/color][color=RED])[/color] [color=RED]([/color][color=#009900]10[/color] [color=#009999]0.[/color] [color=#009999]0.[/color] [color=#009999]0.[/color][color=RED]))[/color]
         [color=RED]([/color][color=BLUE]vl-remove-if[/color]
           [color=RED]([/color][color=BLUE]function[/color]
             [color=RED]([/color][color=BLUE]lambda[/color] [color=RED]([/color] pair [color=RED])[/color] [color=RED]([/color][color=BLUE]member[/color] [color=RED]([/color][color=BLUE]car[/color] pair[color=RED])[/color] [color=DARKRED]'[/color][color=RED]([/color][color=#009900]0[/color] [color=#009900]10[/color] [color=#009900]38[/color] [color=#009900]40[/color] [color=#009900]41[/color] [color=#009900]42[/color] [color=#009900]43[/color] [color=#009900]90[/color] [color=#009900]91[/color] [color=#009900]100[/color][color=RED])))[/color]
           [color=RED])[/color]
           [color=RED]([/color][color=BLUE]setq[/color] elist [color=RED]([/color][color=BLUE]entget[/color] [color=RED]([/color][color=BLUE]setq[/color] e [color=RED]([/color][color=BLUE]ssname[/color] ss [color=RED]([/color][color=BLUE]setq[/color] i [color=RED]([/color][color=BLUE]1-[/color] i[color=RED]))))))[/color]
         [color=RED])[/color]     
       [color=RED])[/color]
     [color=RED])[/color]
     [color=RED]([/color][color=BLUE]setq[/color] z [color=RED]([/color][color=BLUE]list[/color] [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]38[/color] elist[color=RED]))))[/color]
     
     [color=RED]([/color][color=BLUE]while[/color] [color=RED]([/color][color=BLUE]setq[/color] elist [color=RED]([/color][color=BLUE]member[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]10[/color] elist[color=RED])[/color] elist[color=RED]))[/color]
       [color=RED]([/color][color=BLUE]entmakex[/color]
         [color=RED]([/color][color=BLUE]list[/color]
           [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]0[/color] [color=#a52a2a]"VERTEX"[/color][color=RED])[/color]
           [color=RED]([/color][color=BLUE]append[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]10[/color] elist[color=RED])[/color] z[color=RED])[/color]
           [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]40[/color] elist[color=RED])[/color]
           [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]41[/color] elist[color=RED])[/color]
           [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]42[/color] elist[color=RED])[/color]
         [color=RED])[/color]
       [color=RED])[/color]
       [color=RED]([/color][color=BLUE]setq[/color] elist [color=RED]([/color][color=BLUE]cdr[/color] elist[color=RED]))[/color]
     [color=RED])[/color]
     [color=RED]([/color][color=BLUE]entmakex[/color] [color=DARKRED]'[/color][color=RED](([/color][color=#009900]0[/color] [color=DARKRED].[/color] [color=#a52a2a]"SEQEND"[/color][color=RED])))[/color] [color=RED]([/color][color=BLUE]entdel[/color] e[color=RED])[/color]
   [color=RED])[/color]
 [color=RED])[/color]

 [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color]
[color=RED])[/color]

Link to comment
Share on other sites

Are you saying that the existing polylines have varying Z values already? Or are they simply 2D with the correct XY values? As far as I know LWPOLYLINE cannot have varying Z values. The other option would be if the existing lwpolylines have their UCS rotating -David

Link to comment
Share on other sites

As far as I know LWPOLYLINE cannot have varying Z values.

 

That's what I thought - so I went the route of assuming correct XY-Values and using the Elevation [DXF38] for the Z...

:unsure:

Link to comment
Share on other sites

That's what I thought - so I went the route of assuming correct XY-Values and using the Elevation [DXF38] for the Z...

:unsure:

 

I assumed the OP was saying each point varied in the Z axis .... ????

 

Oh well -David

Link to comment
Share on other sites

That's what I thought - so I went the route of assuming correct XY-Values and using the Elevation [DXF38] for the Z...

:unsure:

 

Could you just clarify for a duffer at lisp, that you are retrieving the z value from the point that has the same x, y value as the vertex.

 

As I understand the original post, polylines have been drawn by snapping to 3D points. The polyline would have the z value of the first node snapped to.

Link to comment
Share on other sites

As I understand it, the OP is using LWPolylines which must lie in a single plane at some elevation. The vertex coordinates for the LWPolyline are expressed as 2D OCS points for this elevation. The elevation is stored elsewhere [DXF 38].

 

My code uses the LWPolyline elevation for the Z-Value of every coordinate in the 3D Polyline - hence the 3D Polyline is identical to the LWPolyline. If this is not what was required I think the OP needs to explain further.

 

I'm not too good at explaining what I mean, but I hope this clarifies things!

Link to comment
Share on other sites

I thought that the OP had by mistake drawn an ordinary LWpolyline snapping to 'Points' that were previously in the drawing. He probably should have used the 3D polyline to draw them in the first place, and is after a magic wand to turn his LWPolylines into 3D polylines without having to draw them again.

 

I was wondering how the z values were retrieved in your lisp and attached themselves to the correct vertices to make the required 3D polyline, because obviously the z values of the existing LWPolyline are not as required.

 

Perhaps we are confusing ourselves, and need the OP to clarify matters :?

Link to comment
Share on other sites

I was wondering how the z values were retrieved in your lisp and attached themselves to the correct vertices to make the required 3D polyline, because obviously the z values of the existing LWPolyline are not as required.

 

Mine does nothing more than convert the LWPolyline to a 3DPolyline, the vertices remain in exactly the same positions...

 

Perhaps we are confusing ourselves, and need the OP to clarify matters :?

 

Ditto.

Link to comment
Share on other sites

  • 2 weeks later...

Sorry for the delay,

 

Hai all,

 

I will explain the situation in detail.

 

We are using liscad for processing the survey data and the output was taken in 2d (all points with X&Y but no Z) and normal polylines. then the drawing was edited as per the hand sketches provided by the survey crew.

 

Then we were asked to submit the drawing in 3d (3d points and polylines in 3dpolylines), so another output was taken in 3d (all points with X,Y & Z) and polylines in 3dpolylines.

 

In The final drawing the 2dpoints were erased and 3d points were inserted.

 

Now there is a situation where we have to replace the existing polylines with 3dpolylines which should have the exact elevation at the vertex as of the point.

 

This is a road drawing for a stretch of more than 10kms.

Hope this is a clear picture of the situation.

Link to comment
Share on other sites

Now I am even more confused. You say that you brought in 3d polylines with another output of the survey data. So which 3d polylines are to be made :?

 

I suppose this is a case of someone thinking that you can change a 2d survey to a 3d survey at the touch of a button. (I suppose someone clever will provide that magic button)

 

Next time, do all the processing in 3d FIRST. It is simple to change 3d to 2d, but not the other way round.

Link to comment
Share on other sites

I believe this is what the OP is looking for, but bear in mind that this is a quick and dirty way to do it. There are no error traps other than checking to see if the number of vertices of the polyline equals the number of points.

 

 
(defun c:pl->3dpl ( / pl-ss pnt-ss n pl-obj coords vertN p-list p i pnt pp el 3dpl-obj *MS*)
 (princ "\nSelect 2D Polyline:")
 (setq pl-ss (ssget ":s" '((0 . "LWPOLYLINE"))))
 (princ "\nSelect Points:")
 (setq pnt-ss (ssget '((0 . "AECC_POINT"))))
 (setq pl-obj (vlax-ename->vla-object (ssname pl-ss 0)))
 (setq coords (vlax-get pl-obj 'Coordinates))
 (setq vertN ( / (length coords) 2))
 (if (not (= vertN (sslength pnt-ss)))
   (progn
     (alert "Number Vertices of Polyline Does Not Equal Number of Pnts \n\nExiting...")
     (exit)
     )
   )
 (setq n 0)
  (repeat VertN
   (setq p (list (nth n coords) (nth (1+ n) coords)))
   (setq i 0)
   (repeat VertN
     (setq pnt (vlax-ename->vla-object (ssname pnt-ss i)))
     (setq pp (list (vlax-get pnt 'Easting)(vlax-get pnt 'Northing)))
     (if (equal p pp)
(progn
  (setq el (vlax-get pnt 'Elevation))
  (setq p-list (append p-list (list (nth 0 p)(nth 1 p) el)))
  ) 
)
     (setq i (1+ i))
     )
   (setq n (+ 2 n))
   )
 (setq *MS* (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))))
 (setq 3dpl-obj (vla-add3dpoly *MS* (pl->var p-list)))
 (vlax-put-property 3dpl-obj 'Color acred)
 )

;Given Pointlist returns pointlist in variant form
(defun PL->VAR ( pl / pl ub sa var)
 (setq ub (- (length pl) 1))
 (setq sa (vlax-make-safearray vlax-vbdouble (cons 0 ub)))
 (setq var (vlax-make-variant (setq sa (vlax-safearray-fill sa pl))))
 )

Edited by Hippe013
Link to comment
Share on other sites

Here, I modified Lee's submission to look at each LWPolyline vertex for a point and take the elevation from that, if not, it takes the elevation of the selected LWPolyline (at that vertex).

 

;;-------------=={ LWPolylines to 3D Polylines }==------------;;
;;                                                            ;;
;;  Converts a selection of LWPolylines to 3D Polylines.      ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;  Edited: Alan J. Thompson, 02.08.11                        ;;
;;------------------------------------------------------------;;

(defun c:LWpt3D (/ ss i elist z pt)
 (vl-load-com)
 ;; © Lee Mac 2011
 ;; Edited by: Alan J. Thompson, 02.08.11

 (if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE"))))

   (repeat (setq i (sslength ss))
     (entmakex
       (append '((0 . "POLYLINE") (10 0. 0. 0.) (70 . )
               ;; AJT edit
               (vl-remove-if
                 (function
                   ;; AJT edit
                   (lambda (pair) (member (car pair) '(0 10 38 40 41 42 43 70 90 91 100)))
                 )
                 (setq elist (entget (setq e (ssname ss (setq i (1- i))))))
               )
       )
     )
     (setq z (list (cdr (assoc 38 elist))))

     (while (setq elist (member (assoc 10 elist) elist))
       (entmakex
         (list
           (cons 0 "VERTEX")
           ;; AJT edit BEGIN
           (if (setq pt (ssget "_C"
                               (trans (cdar elist) 0 1)
                               (trans (cdar elist) 0 1)
                               '((0 . "POINT"))
                        )
               )
             (assoc 10 (entget (ssname pt 0)))
             (append (assoc 10 elist) z)
           )
           (cons 70 32)
           ;; AJT edit END
           (assoc 40 elist)
           (assoc 41 elist)
           (assoc 42 elist)
         )
       )
       (setq elist (cdr elist))
     )
     (entmakex '((0 . "SEQEND")))
     (entdel e)
   )
 )

 (princ)
)

Link to comment
Share on other sites

Now I am even more confused. You say that you brought in 3d polylines with another output of the survey data. So which 3d polylines are to be made :?

 

I suppose this is a case of someone thinking that you can change a 2d survey to a 3d survey at the touch of a button. (I suppose someone clever will provide that magic button)

 

Next time, do all the processing in 3d FIRST. It is simple to change 3d to 2d, but not the other way round.

 

Mr. Eldon,

 

I have to remove the polylines and put 3dpolylines, in this case the editing what I have done is gone, so I was thinking a way or a code that would convert the existing polylines to 3dpolylines with the elevation of the point present at each vertex.

Link to comment
Share on other sites

I was only confused because in your original post, you did not explain exactly was going on. Perhaps if you had done so, the thread would be sorted with two posts.

 

Someone has waved a magic wand, so I hope it does what you want it to.

 

But a bit of pre-planning and proper costing to produce the survey would pay dividends.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...